Skip to content

Commit

Permalink
Added InvariantCulture to float.Parse so that it always parses the co…
Browse files Browse the repository at this point in the history
…rrect "invariant" number format that unity usually spits out
  • Loading branch information
zsoi committed Mar 8, 2022
1 parent 6b12117 commit 20a8475
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Editor/BuildLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// https://github.com/pschraut/UnityAddressablesBuildLayoutExplorer
//
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;

namespace Oddworm.EditorFramework
Expand Down Expand Up @@ -589,25 +590,25 @@ long ParseSize(string size)
if (size.EndsWith("GB", System.StringComparison.OrdinalIgnoreCase))
{
var s = size.Substring(0, size.Length - 2);
return (long)(float.Parse(s) * 1024 * 1024 * 1024);
return (long)(float.Parse(s, CultureInfo.InvariantCulture) * 1024 * 1024 * 1024);
}

if (size.EndsWith("MB", System.StringComparison.OrdinalIgnoreCase))
{
var s = size.Substring(0, size.Length - 2);
return (long)(float.Parse(s) * 1024 * 1024);
return (long)(float.Parse(s, CultureInfo.InvariantCulture) * 1024 * 1024);
}

if (size.EndsWith("KB", System.StringComparison.OrdinalIgnoreCase))
{
var s = size.Substring(0, size.Length - 2);
return (long)(float.Parse(s) * 1024);
return (long)(float.Parse(s, CultureInfo.InvariantCulture) * 1024);
}

if (size.EndsWith("B", System.StringComparison.OrdinalIgnoreCase))
{
var s = size.Substring(0, size.Length - 1);
return long.Parse(s);
return long.Parse(s, CultureInfo.InvariantCulture);
}

return -1;
Expand Down

0 comments on commit 20a8475

Please sign in to comment.