Implement file system resource manager. (Amend)
This commit is contained in:
28
Assets/Cryville/Common/Qualified.cs
Normal file
28
Assets/Cryville/Common/Qualified.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common {
|
||||
public struct Qualified<T> : IFormattable where T : IConvertible {
|
||||
static readonly string _prefixes = "yzafpnμm kMGTPEZY";
|
||||
public T Value { get; set; }
|
||||
public string Unit { get; set; }
|
||||
|
||||
public Qualified(string unit) : this(default(T), unit) { }
|
||||
public Qualified(T value, string unit) {
|
||||
Value = value;
|
||||
Unit = unit;
|
||||
}
|
||||
|
||||
public override string ToString() { return ToString("G3"); }
|
||||
public string ToString(string format) { return ToString(format, null); }
|
||||
public string ToString(string format, IFormatProvider formatProvider) {
|
||||
double value = Value.ToDouble(formatProvider);
|
||||
int expIndex = (int)System.Math.Log10(value) / 3;
|
||||
if (expIndex == 0) {
|
||||
return value.ToString(format, formatProvider) + Unit;
|
||||
}
|
||||
int prefixIndex = System.Math.Clamp(expIndex + 8, 0, _prefixes.Length - 1);
|
||||
value /= System.Math.Pow(1e3, prefixIndex - 8);
|
||||
return value.ToString(format, formatProvider) + _prefixes[prefixIndex] + Unit;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Qualified.cs.meta
Normal file
11
Assets/Cryville/Common/Qualified.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 909a28e78d4239f4c9507c3c9128baf2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user