diff --git a/Sane Eric's UI/Scriptable Variables/FloatVariableInput.cs b/Sane Eric's UI/Scriptable Variables/FloatVariableInput.cs index cea8441a5e3bfc9839097aff223aff930c82437a..412ae446ac69097b64d5a9de722d23cd2be49e3d 100644 --- a/Sane Eric's UI/Scriptable Variables/FloatVariableInput.cs +++ b/Sane Eric's UI/Scriptable Variables/FloatVariableInput.cs @@ -17,6 +17,8 @@ namespace Shared.SEUI { // Temporary callback to bridge value changes in the UI and the variable private UnityAction<string> valueConverter; + private bool blockUIChanges = false; + //--------------------------------------------------------------------------- void Start() { // Make sure the input handles the right content type @@ -27,11 +29,20 @@ namespace Shared.SEUI { protected override void AddUIListener(UnityAction<float> callback) { // Define the value converting bridge callback to add to the UI listener valueConverter = delegate(string value) { - if (!String.IsNullOrEmpty(input.text)) { - callback(Convert.ToSingle(value)); + // If the user is trying to make it a negative number or a decimal, + // the string will just be "-" or end in "." at one point, + // so wait until it is a parsable number + if (value != "-" && !value.EndsWith(".")) { + blockUIChanges = false; + if (!String.IsNullOrEmpty(input.text)) { + callback(Convert.ToSingle(value)); + } + else { + callback(0); + } } else { - callback(0.0f); + blockUIChanges = true; } }; @@ -48,12 +59,14 @@ namespace Shared.SEUI { //--------------------------------------------------------------------------- protected override bool DoValuesMatch() { - return !String.IsNullOrEmpty(input.text) && Convert.ToSingle(input.text) == variable.Value; + return !String.IsNullOrEmpty(input.text) && input.text == variable.Value.ToString(); } //--------------------------------------------------------------------------- protected override void UpdateUIValue() { - input.SetTextWithoutNotify(variable.Value.ToString()); + if (!blockUIChanges) { + input.SetTextWithoutNotify(variable.Value.ToString()); + } } //--------------------------------------------------------------------------- diff --git a/Sane Eric's UI/Scriptable Variables/IntVariableInput.cs b/Sane Eric's UI/Scriptable Variables/IntVariableInput.cs index 6ba9330f4e3adff8b5da71d31725766705e4cc7d..fa057f3fb6dc319b1e3e1cf32e6d1f09bf48ce21 100644 --- a/Sane Eric's UI/Scriptable Variables/IntVariableInput.cs +++ b/Sane Eric's UI/Scriptable Variables/IntVariableInput.cs @@ -17,6 +17,8 @@ namespace Shared.SEUI { // Temporary callback to bridge value changes in the UI and the variable private UnityAction<string> valueConverter; + private bool blockUIChanges = false; + //--------------------------------------------------------------------------- void Start() { // Make sure the input handles the right content type @@ -27,11 +29,19 @@ namespace Shared.SEUI { protected override void AddUIListener(UnityAction<int> callback) { // Define the value converting bridge callback to add to the UI listener valueConverter = delegate(string value) { - if (!String.IsNullOrEmpty(input.text)) { - callback(Convert.ToInt32(value)); + // If the user is trying to make it a negative number, the string will just be "-" at one point, + // so wait until it is a parsable number + if (value != "-") { + blockUIChanges = false; + if (!String.IsNullOrEmpty(input.text)) { + callback(Convert.ToInt32(value)); + } + else { + callback(0); + } } else { - callback(0); + blockUIChanges = true; } }; @@ -53,7 +63,9 @@ namespace Shared.SEUI { //--------------------------------------------------------------------------- protected override void UpdateUIValue() { - input.SetTextWithoutNotify(variable.Value.ToString()); + if (!blockUIChanges) { + input.SetTextWithoutNotify(variable.Value.ToString()); + } } //--------------------------------------------------------------------------- diff --git a/package.json b/package.json index f7e79b6f79021f3ebfded984a85eaa024501bf45..bb1cf649087cc2446c7018fd1abeb602b9047b74 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.futuretech.shared", "displayName": "FutureTech Shared", "description": "Contains shared items such as the Scriptable Variables.", - "version": "0.1.27", + "version": "0.1.28", "unity": "2019.3", "license": "MIT", "repository": {