@@ -339,7 +339,7 @@ internal static string RectAnchorsToString(this RectTransform rect)
339
339
if ( ! rect )
340
340
throw new ArgumentNullException ( "rect" ) ;
341
341
342
- return string . Format ( CultureInfo . CurrentCulture , "{0} {1} {2} {3}" , new object [ ]
342
+ return string . Format ( CultureInfo . InvariantCulture , "{0}, {1}, {2}, {3}" , new object [ ]
343
343
{
344
344
rect . anchorMin . x ,
345
345
rect . anchorMin . y ,
@@ -353,16 +353,20 @@ internal static void SetAnchorsFromString(this RectTransform panel, string strin
353
353
if ( string . IsNullOrEmpty ( stringAnchors ) )
354
354
throw new ArgumentNullException ( "stringAnchors" ) ;
355
355
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 ( ',' ) ;
357
361
358
362
if ( split . Length != 4 )
359
363
throw new Exception ( $ "stringAnchors split is unexpected length: { split . Length } ") ;
360
364
361
365
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 ) ;
366
370
367
371
panel . anchorMin = new Vector2 ( anchors . x , anchors . y ) ;
368
372
panel . anchorMax = new Vector2 ( anchors . z , anchors . w ) ;
@@ -373,22 +377,29 @@ internal static string RectPositionToString(this RectTransform rect)
373
377
if ( ! rect )
374
378
throw new ArgumentNullException ( "rect" ) ;
375
379
376
- return string . Format ( CultureInfo . CurrentCulture , "{0} {1}" , new object [ ]
380
+ return string . Format ( CultureInfo . InvariantCulture , "{0}, {1}" , new object [ ]
377
381
{
378
382
rect . localPosition . x , rect . localPosition . y
379
383
} ) ;
380
384
}
381
385
382
386
internal static void SetPositionFromString ( this RectTransform rect , string stringPosition )
383
387
{
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 ( ',' ) ;
385
396
386
397
if ( split . Length != 2 )
387
398
throw new Exception ( $ "stringPosition split is unexpected length: { split . Length } ") ;
388
399
389
400
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 ) ;
392
403
rect . localPosition = vector ;
393
404
}
394
405
}
0 commit comments