Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit f26371f

Browse files
committed
Go back to previous panel transform saving, no need to change
1 parent a673c39 commit f26371f

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/UI/Panels/UIPanel.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ internal static string RectAnchorsToString(this RectTransform rect)
339339
if (!rect)
340340
throw new ArgumentNullException("rect");
341341

342-
return string.Format(CultureInfo.CurrentCulture, "{0} {1} {2} {3}", new object[]
342+
return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", new object[]
343343
{
344344
rect.anchorMin.x,
345345
rect.anchorMin.y,
@@ -353,16 +353,20 @@ internal static void SetAnchorsFromString(this RectTransform panel, string strin
353353
if (string.IsNullOrEmpty(stringAnchors))
354354
throw new ArgumentNullException("stringAnchors");
355355

356-
var split = stringAnchors.Split(' ');
356+
if (stringAnchors.Contains(" "))
357+
// outdated save data, not worth recovering just reset it.
358+
throw new Exception("invalid save data, resetting.");
359+
360+
var split = stringAnchors.Split(',');
357361

358362
if (split.Length != 4)
359363
throw new Exception($"stringAnchors split is unexpected length: {split.Length}");
360364

361365
Vector4 anchors;
362-
anchors.x = float.Parse(split[0], CultureInfo.CurrentCulture);
363-
anchors.y = float.Parse(split[1], CultureInfo.CurrentCulture);
364-
anchors.z = float.Parse(split[2], CultureInfo.CurrentCulture);
365-
anchors.w = float.Parse(split[3], CultureInfo.CurrentCulture);
366+
anchors.x = float.Parse(split[0], CultureInfo.InvariantCulture);
367+
anchors.y = float.Parse(split[1], CultureInfo.InvariantCulture);
368+
anchors.z = float.Parse(split[2], CultureInfo.InvariantCulture);
369+
anchors.w = float.Parse(split[3], CultureInfo.InvariantCulture);
366370

367371
panel.anchorMin = new Vector2(anchors.x, anchors.y);
368372
panel.anchorMax = new Vector2(anchors.z, anchors.w);
@@ -373,22 +377,29 @@ internal static string RectPositionToString(this RectTransform rect)
373377
if (!rect)
374378
throw new ArgumentNullException("rect");
375379

376-
return string.Format(CultureInfo.CurrentCulture, "{0} {1}", new object[]
380+
return string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[]
377381
{
378382
rect.localPosition.x, rect.localPosition.y
379383
});
380384
}
381385

382386
internal static void SetPositionFromString(this RectTransform rect, string stringPosition)
383387
{
384-
var split = stringPosition.Split(' ');
388+
if (string.IsNullOrEmpty(stringPosition))
389+
throw new ArgumentNullException(stringPosition);
390+
391+
if (stringPosition.Contains(" "))
392+
// outdated save data, not worth recovering just reset it.
393+
throw new Exception("invalid save data, resetting.");
394+
395+
var split = stringPosition.Split(',');
385396

386397
if (split.Length != 2)
387398
throw new Exception($"stringPosition split is unexpected length: {split.Length}");
388399

389400
Vector3 vector = rect.localPosition;
390-
vector.x = float.Parse(split[0], CultureInfo.CurrentCulture);
391-
vector.y = float.Parse(split[1], CultureInfo.CurrentCulture);
401+
vector.x = float.Parse(split[0], CultureInfo.InvariantCulture);
402+
vector.y = float.Parse(split[1], CultureInfo.InvariantCulture);
392403
rect.localPosition = vector;
393404
}
394405
}

0 commit comments

Comments
 (0)