Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #29 from uurha/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
uurha committed Feb 3, 2023
1 parent 0b53a3d commit f59a9c9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Runtime/Extension/SizeConverter.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Extension/SizeConverter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f59a9c9

Please sign in to comment.