mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 06:08:16 +08:00
Use CurrentCulture, and use whitespace instead of comma as separator
This commit is contained in:
parent
b7e275f02c
commit
dabf92a1a5
@ -13,7 +13,7 @@ namespace UnityExplorer
|
||||
/// </summary>
|
||||
public static bool ContainsIgnoreCase(this string _this, string s)
|
||||
{
|
||||
return ParseUtility.en_US.CompareInfo.IndexOf(_this, s, CompareOptions.IgnoreCase) >= 0;
|
||||
return CultureInfo.CurrentCulture.CompareInfo.IndexOf(_this, s, CompareOptions.IgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -10,8 +10,6 @@ namespace UnityExplorer
|
||||
{
|
||||
public static class ParseUtility
|
||||
{
|
||||
public static CultureInfo en_US = new CultureInfo("en-US");
|
||||
|
||||
private static readonly HashSet<Type> nonPrimitiveTypes = new HashSet<Type>
|
||||
{
|
||||
typeof(string),
|
||||
@ -19,20 +17,18 @@ namespace UnityExplorer
|
||||
typeof(DateTime),
|
||||
};
|
||||
|
||||
public const string NUMBER_FORMAT = "0.####";
|
||||
// Helper for formatting float/double/decimal numbers to maximum of 4 decimal points.
|
||||
// And also for formatting a sequence of those numbers, ie a Vector3, Color etc
|
||||
|
||||
public static readonly string NumberFormatString = $"0{CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator}####";
|
||||
private static readonly Dictionary<int, string> numSequenceStrings = new Dictionary<int, string>();
|
||||
|
||||
// Helper for formatting float/double/decimal numbers to maximum of 4 decimal points.
|
||||
public static string FormatDecimalSequence(params object[] numbers)
|
||||
{
|
||||
if (numbers.Length <= 0)
|
||||
return null;
|
||||
|
||||
int count = numbers.Length;
|
||||
var formatString = GetSequenceFormatString(count);
|
||||
|
||||
return string.Format(en_US, formatString, numbers);
|
||||
return string.Format(CultureInfo.CurrentCulture, GetSequenceFormatString(numbers.Length), numbers);
|
||||
}
|
||||
|
||||
public static string GetSequenceFormatString(int count)
|
||||
@ -46,19 +42,19 @@ namespace UnityExplorer
|
||||
string[] strings = new string[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
strings[i] = $"{{{i}:{NUMBER_FORMAT}}}";
|
||||
strings[i] = $"{{{i}:{NumberFormatString}}}";
|
||||
|
||||
string s = string.Join(", ", strings);
|
||||
|
||||
numSequenceStrings.Add(count, s);
|
||||
return s;
|
||||
string ret = string.Join(" ", strings);
|
||||
numSequenceStrings.Add(count, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Main parsing API
|
||||
|
||||
public static bool CanParse(Type type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(type.FullName))
|
||||
return false;
|
||||
return type.IsPrimitive || type.IsEnum || nonPrimitiveTypes.Contains(type) || customTypes.ContainsKey(type.FullName);
|
||||
return !string.IsNullOrEmpty(type?.FullName)
|
||||
&& (type.IsPrimitive || type.IsEnum || nonPrimitiveTypes.Contains(type) || customTypes.ContainsKey(type.FullName));
|
||||
}
|
||||
|
||||
public static bool TryParse(string input, Type type, out object obj, out Exception parseException)
|
||||
@ -143,7 +139,7 @@ namespace UnityExplorer
|
||||
else if (formattedTypes.Contains(type))
|
||||
{
|
||||
return ReflectionUtility.GetMethodInfo(type, "ToString", new Type[] { typeof(string), typeof(IFormatProvider) })
|
||||
.Invoke(obj, new object[] { NUMBER_FORMAT, en_US })
|
||||
.Invoke(obj, new object[] { NumberFormatString, CultureInfo.CurrentCulture })
|
||||
as string;
|
||||
}
|
||||
else
|
||||
@ -166,9 +162,7 @@ namespace UnityExplorer
|
||||
try
|
||||
{
|
||||
if (type.IsEnum)
|
||||
{
|
||||
typeInputExamples.Add(type.AssemblyQualifiedName, Enum.GetNames(type).First());
|
||||
}
|
||||
else
|
||||
{
|
||||
var instance = Activator.CreateInstance(type);
|
||||
@ -222,10 +216,10 @@ namespace UnityExplorer
|
||||
{
|
||||
Vector2 vector = default;
|
||||
|
||||
var split = input.Split(',');
|
||||
var split = input.Split(' ');
|
||||
|
||||
vector.x = float.Parse(split[0].Trim(), en_US);
|
||||
vector.y = float.Parse(split[1].Trim(), en_US);
|
||||
vector.x = float.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.y = float.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
|
||||
return vector;
|
||||
}
|
||||
@ -244,11 +238,11 @@ namespace UnityExplorer
|
||||
{
|
||||
Vector3 vector = default;
|
||||
|
||||
var split = input.Split(',');
|
||||
var split = input.Split(' ');
|
||||
|
||||
vector.x = float.Parse(split[0].Trim(), en_US);
|
||||
vector.y = float.Parse(split[1].Trim(), en_US);
|
||||
vector.z = float.Parse(split[2].Trim(), en_US);
|
||||
vector.x = float.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.y = float.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.z = float.Parse(split[2].Trim(), CultureInfo.CurrentCulture);
|
||||
|
||||
return vector;
|
||||
}
|
||||
@ -267,12 +261,12 @@ namespace UnityExplorer
|
||||
{
|
||||
Vector4 vector = default;
|
||||
|
||||
var split = input.Split(',');
|
||||
var split = input.Split(' ');
|
||||
|
||||
vector.x = float.Parse(split[0].Trim(), en_US);
|
||||
vector.y = float.Parse(split[1].Trim(), en_US);
|
||||
vector.z = float.Parse(split[2].Trim(), en_US);
|
||||
vector.w = float.Parse(split[3].Trim(), en_US);
|
||||
vector.x = float.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.y = float.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.z = float.Parse(split[2].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.w = float.Parse(split[3].Trim(), CultureInfo.CurrentCulture);
|
||||
|
||||
return vector;
|
||||
}
|
||||
@ -291,22 +285,22 @@ namespace UnityExplorer
|
||||
{
|
||||
Vector3 vector = default;
|
||||
|
||||
var split = input.Split(',');
|
||||
var split = input.Split(' ');
|
||||
|
||||
if (split.Length == 4)
|
||||
{
|
||||
Quaternion quat = default;
|
||||
quat.x = float.Parse(split[0].Trim(), en_US);
|
||||
quat.y = float.Parse(split[1].Trim(), en_US);
|
||||
quat.z = float.Parse(split[2].Trim(), en_US);
|
||||
quat.w = float.Parse(split[3].Trim(), en_US);
|
||||
quat.x = float.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
quat.y = float.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
quat.z = float.Parse(split[2].Trim(), CultureInfo.CurrentCulture);
|
||||
quat.w = float.Parse(split[3].Trim(), CultureInfo.CurrentCulture);
|
||||
return quat;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector.x = float.Parse(split[0].Trim(), en_US);
|
||||
vector.y = float.Parse(split[1].Trim(), en_US);
|
||||
vector.z = float.Parse(split[2].Trim(), en_US);
|
||||
vector.x = float.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.y = float.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
vector.z = float.Parse(split[2].Trim(), CultureInfo.CurrentCulture);
|
||||
return Quaternion.Euler(vector);
|
||||
}
|
||||
}
|
||||
@ -327,12 +321,12 @@ namespace UnityExplorer
|
||||
{
|
||||
Rect rect = default;
|
||||
|
||||
var split = input.Split(',');
|
||||
var split = input.Split(' ');
|
||||
|
||||
rect.x = float.Parse(split[0].Trim(), en_US);
|
||||
rect.y = float.Parse(split[1].Trim(), en_US);
|
||||
rect.width = float.Parse(split[2].Trim(), en_US);
|
||||
rect.height = float.Parse(split[3].Trim(), en_US);
|
||||
rect.x = float.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
rect.y = float.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
rect.width = float.Parse(split[2].Trim(), CultureInfo.CurrentCulture);
|
||||
rect.height = float.Parse(split[3].Trim(), CultureInfo.CurrentCulture);
|
||||
|
||||
return rect;
|
||||
}
|
||||
@ -351,13 +345,13 @@ namespace UnityExplorer
|
||||
{
|
||||
Color color = default;
|
||||
|
||||
var split = input.Split(',');
|
||||
var split = input.Split(' ');
|
||||
|
||||
color.r = float.Parse(split[0].Trim(), en_US);
|
||||
color.g = float.Parse(split[1].Trim(), en_US);
|
||||
color.b = float.Parse(split[2].Trim(), en_US);
|
||||
color.r = float.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
color.g = float.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
color.b = float.Parse(split[2].Trim(), CultureInfo.CurrentCulture);
|
||||
if (split.Length > 3)
|
||||
color.a = float.Parse(split[3].Trim(), en_US);
|
||||
color.a = float.Parse(split[3].Trim(), CultureInfo.CurrentCulture);
|
||||
else
|
||||
color.a = 1;
|
||||
|
||||
@ -378,13 +372,13 @@ namespace UnityExplorer
|
||||
{
|
||||
Color32 color = default;
|
||||
|
||||
var split = input.Split(',');
|
||||
var split = input.Split(' ');
|
||||
|
||||
color.r = byte.Parse(split[0].Trim(), en_US);
|
||||
color.g = byte.Parse(split[1].Trim(), en_US);
|
||||
color.b = byte.Parse(split[2].Trim(), en_US);
|
||||
color.r = byte.Parse(split[0].Trim(), CultureInfo.CurrentCulture);
|
||||
color.g = byte.Parse(split[1].Trim(), CultureInfo.CurrentCulture);
|
||||
color.b = byte.Parse(split[2].Trim(), CultureInfo.CurrentCulture);
|
||||
if (split.Length > 3)
|
||||
color.a = byte.Parse(split[3].Trim(), en_US);
|
||||
color.a = byte.Parse(split[3].Trim(), CultureInfo.CurrentCulture);
|
||||
else
|
||||
color.a = 255;
|
||||
|
||||
@ -397,7 +391,7 @@ namespace UnityExplorer
|
||||
return null;
|
||||
|
||||
// ints, this is fine
|
||||
return $"{color.r}, {color.g}, {color.b}, {color.a}";
|
||||
return $"{color.r} {color.g} {color.b} {color.a}";
|
||||
}
|
||||
|
||||
// Layermask (Int32)
|
||||
|
@ -209,6 +209,10 @@ namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
ExplorerCore.LogWarning("Invalid or corrupt panel save data! Restoring to default.");
|
||||
SetTransformDefaults();
|
||||
UIManager.Initializing = false;
|
||||
DoSaveToConfigElement();
|
||||
ConfigManager.InternalHandler.SaveConfig();
|
||||
UIManager.Initializing = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,7 +339,7 @@ namespace UnityExplorer.UI.Panels
|
||||
if (!rect)
|
||||
throw new ArgumentNullException("rect");
|
||||
|
||||
return string.Format(ParseUtility.en_US, "{0},{1},{2},{3}", new object[]
|
||||
return string.Format(CultureInfo.CurrentCulture, "{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
rect.anchorMin.x,
|
||||
rect.anchorMin.y,
|
||||
@ -349,16 +353,16 @@ namespace UnityExplorer.UI.Panels
|
||||
if (string.IsNullOrEmpty(stringAnchors))
|
||||
throw new ArgumentNullException("stringAnchors");
|
||||
|
||||
var split = stringAnchors.Split(',');
|
||||
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], ParseUtility.en_US);
|
||||
anchors.y = float.Parse(split[1], ParseUtility.en_US);
|
||||
anchors.z = float.Parse(split[2], ParseUtility.en_US);
|
||||
anchors.w = float.Parse(split[3], ParseUtility.en_US);
|
||||
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);
|
||||
|
||||
panel.anchorMin = new Vector2(anchors.x, anchors.y);
|
||||
panel.anchorMax = new Vector2(anchors.z, anchors.w);
|
||||
@ -369,7 +373,7 @@ namespace UnityExplorer.UI.Panels
|
||||
if (!rect)
|
||||
throw new ArgumentNullException("rect");
|
||||
|
||||
return string.Format(ParseUtility.en_US, "{0},{1}", new object[]
|
||||
return string.Format(CultureInfo.CurrentCulture, "{0} {1}", new object[]
|
||||
{
|
||||
rect.localPosition.x, rect.localPosition.y
|
||||
});
|
||||
@ -377,14 +381,14 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
internal static void SetPositionFromString(this RectTransform rect, string stringPosition)
|
||||
{
|
||||
var split = stringPosition.Split(',');
|
||||
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], ParseUtility.en_US);
|
||||
vector.y = float.Parse(split[1], ParseUtility.en_US);
|
||||
vector.x = float.Parse(split[0], CultureInfo.CurrentCulture);
|
||||
vector.y = float.Parse(split[1], CultureInfo.CurrentCulture);
|
||||
rect.localPosition = vector;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace UnityExplorer.UI
|
||||
Bottom
|
||||
}
|
||||
|
||||
public static bool Initializing { get; private set; } = true;
|
||||
public static bool Initializing { get; internal set; } = true;
|
||||
|
||||
private static readonly Dictionary<Panels, UIPanel> UIPanels = new Dictionary<Panels, UIPanel>();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user