From f26371f95fc2a1ac9ac042808496179c3dc56226 Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Wed, 28 Jul 2021 18:27:10 +1000 Subject: [PATCH] Go back to previous panel transform saving, no need to change --- src/UI/Panels/UIPanel.cs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/UI/Panels/UIPanel.cs b/src/UI/Panels/UIPanel.cs index 0e98f37..8bce555 100644 --- a/src/UI/Panels/UIPanel.cs +++ b/src/UI/Panels/UIPanel.cs @@ -339,7 +339,7 @@ namespace UnityExplorer.UI.Panels if (!rect) throw new ArgumentNullException("rect"); - return string.Format(CultureInfo.CurrentCulture, "{0} {1} {2} {3}", new object[] + return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", new object[] { rect.anchorMin.x, rect.anchorMin.y, @@ -353,16 +353,20 @@ namespace UnityExplorer.UI.Panels if (string.IsNullOrEmpty(stringAnchors)) throw new ArgumentNullException("stringAnchors"); - var split = stringAnchors.Split(' '); + if (stringAnchors.Contains(" ")) + // outdated save data, not worth recovering just reset it. + throw new Exception("invalid save data, resetting."); + + var split = stringAnchors.Split(','); if (split.Length != 4) throw new Exception($"stringAnchors split is unexpected length: {split.Length}"); Vector4 anchors; - anchors.x = float.Parse(split[0], CultureInfo.CurrentCulture); - anchors.y = float.Parse(split[1], CultureInfo.CurrentCulture); - anchors.z = float.Parse(split[2], CultureInfo.CurrentCulture); - anchors.w = float.Parse(split[3], CultureInfo.CurrentCulture); + anchors.x = float.Parse(split[0], CultureInfo.InvariantCulture); + anchors.y = float.Parse(split[1], CultureInfo.InvariantCulture); + anchors.z = float.Parse(split[2], CultureInfo.InvariantCulture); + anchors.w = float.Parse(split[3], CultureInfo.InvariantCulture); panel.anchorMin = new Vector2(anchors.x, anchors.y); panel.anchorMax = new Vector2(anchors.z, anchors.w); @@ -373,7 +377,7 @@ namespace UnityExplorer.UI.Panels if (!rect) throw new ArgumentNullException("rect"); - return string.Format(CultureInfo.CurrentCulture, "{0} {1}", new object[] + return string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { rect.localPosition.x, rect.localPosition.y }); @@ -381,14 +385,21 @@ namespace UnityExplorer.UI.Panels internal static void SetPositionFromString(this RectTransform rect, string stringPosition) { - var split = stringPosition.Split(' '); + if (string.IsNullOrEmpty(stringPosition)) + throw new ArgumentNullException(stringPosition); + + if (stringPosition.Contains(" ")) + // outdated save data, not worth recovering just reset it. + throw new Exception("invalid save data, resetting."); + + var split = stringPosition.Split(','); if (split.Length != 2) throw new Exception($"stringPosition split is unexpected length: {split.Length}"); Vector3 vector = rect.localPosition; - vector.x = float.Parse(split[0], CultureInfo.CurrentCulture); - vector.y = float.Parse(split[1], CultureInfo.CurrentCulture); + vector.x = float.Parse(split[0], CultureInfo.InvariantCulture); + vector.y = float.Parse(split[1], CultureInfo.InvariantCulture); rect.localPosition = vector; } }