Implement file system resource manager. (Amend)

This commit is contained in:
2023-11-29 22:24:47 +08:00
parent 83ea6f5a0c
commit d74db533dc
2 changed files with 39 additions and 0 deletions

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 909a28e78d4239f4c9507c3c9128baf2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: