diff --git a/Runtime/Extension/SizeConverter.cs b/Runtime/Extension/SizeConverter.cs new file mode 100644 index 0000000..2384e4d --- /dev/null +++ b/Runtime/Extension/SizeConverter.cs @@ -0,0 +1,52 @@ +using UnityEngine; + +namespace Better.Extensions.Runtime +{ + public static class SizeConverter + { + private const float ConvertRation = 1024f; + + public enum SizeUnits : long + { + Byte = 0, + Kb = 1, + Mb = 2, + Gb = 3, + Tb = 4, + Pb = 5, + Eb = 6, + Zb = 7, + Yb = 8 + } + + public static double ToSize(this ulong value, SizeUnits unit) + { + return (value / Mathf.Pow(1024, (long)unit)); + } + + public static double ToSize(this long value, SizeUnits unit) + { + return (value / Mathf.Pow(1024, (long)unit)); + } + + public static double ToSize(this double value, SizeUnits unit) + { + return (value / Mathf.Pow(1024, (long)unit)); + } + + public static double ToMegabytes(this ulong bytes) + { + return bytes.ToSize(SizeUnits.Mb); + } + + public static double ToMegabytes(this double bytes) + { + return bytes.ToSize(SizeUnits.Mb); + } + + public static double ToMegabytes(this long bytes) + { + return bytes.ToSize(SizeUnits.Mb); + } + } +} \ No newline at end of file diff --git a/Runtime/Extension/SizeConverter.cs.meta b/Runtime/Extension/SizeConverter.cs.meta new file mode 100644 index 0000000..9e9383c --- /dev/null +++ b/Runtime/Extension/SizeConverter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a46526559c2e4c81a8571e350acd4179 +timeCreated: 1675466791 \ No newline at end of file