diff --git a/src_plugin/UI/InteractiveValues/InteractiveColor.cs b/src_plugin/UI/InteractiveValues/InteractiveColor.cs index 88a6475..b1b92fb 100644 --- a/src_plugin/UI/InteractiveValues/InteractiveColor.cs +++ b/src_plugin/UI/InteractiveValues/InteractiveColor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using UnityEngine; @@ -32,20 +33,20 @@ private void RefreshColorUI() { if (this.Value is Color32 c32) { - inputs[0].text = c32.r.ToString(); - inputs[1].text = c32.g.ToString(); - inputs[2].text = c32.b.ToString(); - inputs[3].text = c32.a.ToString(); + inputs[0].text = c32.r.ToString(CultureInfo.InvariantCulture); + inputs[1].text = c32.g.ToString(CultureInfo.InvariantCulture); + inputs[2].text = c32.b.ToString(CultureInfo.InvariantCulture); + inputs[3].text = c32.a.ToString(CultureInfo.InvariantCulture); if (colorImage) colorImage.color = c32; } else if (this.Value is Color color) { - inputs[0].text = color.r.ToString(); - inputs[1].text = color.g.ToString(); - inputs[2].text = color.b.ToString(); - inputs[3].text = color.a.ToString(); + inputs[0].text = color.r.ToString(CultureInfo.InvariantCulture); + inputs[1].text = color.g.ToString(CultureInfo.InvariantCulture); + inputs[2].text = color.b.ToString(CultureInfo.InvariantCulture); + inputs[3].text = color.a.ToString(CultureInfo.InvariantCulture); if (colorImage) colorImage.color = color; @@ -110,13 +111,13 @@ internal void AddEditorRow(int index, GameObject groupObj) { if (Value is Color) { - float val = float.Parse(value); + float val = float.Parse(value, CultureInfo.InvariantCulture); SetValueToColor(val); sliders[index].value = val; } else { - byte val = byte.Parse(value); + byte val = byte.Parse(value, CultureInfo.InvariantCulture); SetValueToColor32(val); sliders[index].value = val; } @@ -150,9 +151,9 @@ internal void AddEditorRow(int index, GameObject groupObj) } else { - inputField.Text = value.ToString(); + inputField.Text = value.ToString(CultureInfo.InvariantCulture); SetValueToColor(value); - inputs[index].text = value.ToString(); + inputs[index].text = value.ToString(CultureInfo.InvariantCulture); } } catch (Exception ex) diff --git a/src_plugin/UI/InteractiveValues/InteractiveFloatStruct.cs b/src_plugin/UI/InteractiveValues/InteractiveFloatStruct.cs index f16849d..7e457b8 100644 --- a/src_plugin/UI/InteractiveValues/InteractiveFloatStruct.cs +++ b/src_plugin/UI/InteractiveValues/InteractiveFloatStruct.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using UnityEngine; @@ -48,7 +49,7 @@ public void RefreshUI(InputField[] inputs, object instance) { FieldInfo field = fields[i]; float val = (float)field.GetValue(instance); - inputs[i].text = val.ToString(); + inputs[i].text = val.ToString(CultureInfo.InvariantCulture); } } catch (Exception ex) @@ -167,7 +168,7 @@ internal void AddEditorRow(int index, GameObject groupObj) { try { - float f = float.Parse(val); + float f = float.Parse(val, CultureInfo.InvariantCulture); Value = structInfo.SetValue(ref this.Value, index, f); Owner.SetValueFromIValue(); } diff --git a/src_plugin/UI/InteractiveValues/InteractiveNumber.cs b/src_plugin/UI/InteractiveValues/InteractiveNumber.cs index 8458774..742ace0 100644 --- a/src_plugin/UI/InteractiveValues/InteractiveNumber.cs +++ b/src_plugin/UI/InteractiveValues/InteractiveNumber.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Reflection; @@ -19,8 +20,11 @@ public class InteractiveNumber : InteractiveValue internal InputFieldRef valueInput; private Slider slider; - public MethodInfo ParseMethod => parseMethod ??= Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }); - private MethodInfo parseMethod; + public MethodInfo ParseMethod => parseMethod ??= Value.GetType().GetMethod("Parse", new Type[] { typeof(string), typeof(CultureInfo) }); + private MethodInfo parseMethod; + + public MethodInfo ToStringMethod => toStringMethod ??= Value.GetType().GetMethod("ToString", new Type[] { typeof(IFormatProvider) }); + private MethodInfo toStringMethod; public InteractiveNumber(object value, Type valueType) : base(value, valueType) { } @@ -29,20 +33,20 @@ public override bool SupportsType(Type type) public override void RefreshUIForValue() { - valueInput.Text = Value.ToString(); + valueInput.Text = (string)ToStringMethod.Invoke(Value, new object[] { CultureInfo.InvariantCulture }); if (!valueInput.Component.gameObject.activeSelf) valueInput.Component.gameObject.SetActive(true); if (slider) - slider.value = (float)Convert.ChangeType(Value, typeof(float)); + slider.value = (float)Convert.ChangeType(Value, typeof(float), CultureInfo.InvariantCulture); } internal void SetValueFromInput() { try { - Value = ParseMethod.Invoke(null, new object[] { valueInput.Text }); + Value = ParseMethod.Invoke(null, new object[] { valueInput.Text, CultureInfo.InvariantCulture }); if (Owner.RefConfig.Description?.AcceptableValues is AcceptableValueBase acceptable && !acceptable.IsValid(Value)) @@ -84,30 +88,33 @@ public override void ConstructUI(GameObject parent) Type gtype = typeof(AcceptableValueRange<>).MakeGenericType(range.ValueType); object minValue = AccessTools.Property(gtype, "MinValue").GetValue(range, null); object maxValue = AccessTools.Property(gtype, "MaxValue").GetValue(range, null); + string minValueStr = (string)ToStringMethod.Invoke(minValue, new object[] { CultureInfo.InvariantCulture }); + string maxValueStr = (string)ToStringMethod.Invoke(maxValue, new object[] { CultureInfo.InvariantCulture }); + - Owner.mainLabel.text += $" [{minValue.ToString()} - {maxValue.ToString()}]"; + Owner.mainLabel.text += $" [{minValueStr} - {maxValueStr}]"; GameObject sliderObj = UIFactory.CreateSlider(mainContent, "ValueSlider", out slider); UIFactory.SetLayoutElement(sliderObj, minWidth: 250, minHeight: 25); - slider.minValue = (float)Convert.ChangeType(minValue, typeof(float)); - slider.maxValue = (float)Convert.ChangeType(maxValue, typeof(float)); + slider.minValue = (float)Convert.ChangeType(minValue, typeof(float), CultureInfo.InvariantCulture); + slider.maxValue = (float)Convert.ChangeType(maxValue, typeof(float), CultureInfo.InvariantCulture); - slider.value = (float)Convert.ChangeType(Value, typeof(float)); + slider.value = (float)Convert.ChangeType(Value, typeof(float), CultureInfo.InvariantCulture); slider.onValueChanged.AddListener((float val) => { - Value = Convert.ChangeType(val, FallbackType); + Value = Convert.ChangeType(val, FallbackType, CultureInfo.InvariantCulture); Owner.SetValueFromIValue(); valueInput.Text = Value.ToString(); }); - //m_valueInput.onValueChanged.AddListener((string val) => - //{ - // SetValueFromInput - // //slider.value = (float)Convert.ChangeType(Value, typeof(float)); - //}); - } - } + //m_valueInput.onValueChanged.AddListener((string val) => + //{ + // SetValueFromInput + // //slider.value = (float)Convert.ChangeType(Value, typeof(float), CultureInfo.InvariantCulture); + //}); + } + } } }