From 67f9f744bbd481ac6fccc6de60492a590beb4e16 Mon Sep 17 00:00:00 2001 From: Sinai Date: Mon, 21 Jun 2021 19:26:05 +1000 Subject: [PATCH] Handle Unity 2021+ InputField.onEndEdit change --- src/Core/Utility/UnityHelpers.cs | 13 +++++++++++++ .../GameObjectWidgets/GameObjectControls.cs | 8 ++++---- src/UI/UIManager.cs | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Core/Utility/UnityHelpers.cs b/src/Core/Utility/UnityHelpers.cs index 372e32e..d8e1086 100644 --- a/src/Core/Utility/UnityHelpers.cs +++ b/src/Core/Utility/UnityHelpers.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Reflection; using System.Text; using UnityEngine; using UnityEngine.Events; +using UnityEngine.UI; using Object = UnityEngine.Object; // Project-wide namespace for accessibility @@ -107,5 +109,16 @@ namespace UnityExplorer return color; } + + private static PropertyInfo onEndEdit; + + public static UnityEvent GetOnEndEdit(this InputField _this) + { + if (onEndEdit == null) + onEndEdit = typeof(InputField).GetProperty("onEndEdit") + ?? throw new Exception("Could not get InputField.onEndEdit property!"); + + return onEndEdit.GetValue(_this, null).TryCast>(); + } } } diff --git a/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs b/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs index 7b8ade0..be2d1b2 100644 --- a/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs +++ b/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs @@ -468,7 +468,7 @@ namespace UnityExplorer.UI.Inspectors //UIFactory.SetLayoutElement(pathApplyBtn.Component.gameObject, minHeight: 25, minWidth: 120); //pathApplyBtn.OnClick += () => { OnPathEndEdit(PathInput.Text); }; - PathInput.Component.onEndEdit.AddListener((string val) => { OnPathEndEdit(val); }); + PathInput.Component.GetOnEndEdit().AddListener((string val) => { OnPathEndEdit(val); }); // Title and update row @@ -484,7 +484,7 @@ namespace UnityExplorer.UI.Inspectors NameInput = UIFactory.CreateInputField(titleRow, "NameInput", "untitled"); UIFactory.SetLayoutElement(NameInput.Component.gameObject, minHeight: 30, minWidth: 100, flexibleWidth: 9999); NameInput.Component.textComponent.fontSize = 15; - NameInput.Component.onEndEdit.AddListener((string val) => { OnNameEndEdit(val); }); + NameInput.Component.GetOnEndEdit().AddListener((string val) => { OnNameEndEdit(val); }); // second row (toggles, instanceID, tag, buttons) @@ -521,7 +521,7 @@ namespace UnityExplorer.UI.Inspectors TagInput = UIFactory.CreateInputField(secondRow, "TagInput", "none"); UIFactory.SetLayoutElement(TagInput.Component.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 999); TagInput.Component.textComponent.color = Color.white; - TagInput.Component.onEndEdit.AddListener((string val) => { OnTagEndEdit(val); }); + TagInput.Component.GetOnEndEdit().AddListener((string val) => { OnTagEndEdit(val); }); // Instantiate var instantiateBtn = UIFactory.CreateButton(secondRow, "InstantiateBtn", "Instantiate", new Color(0.2f, 0.2f, 0.2f)); @@ -644,7 +644,7 @@ namespace UnityExplorer.UI.Inspectors var inputField = UIFactory.CreateInputField(rowObj, "InputField", "..."); UIFactory.SetLayoutElement(inputField.Component.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 999); - inputField.Component.onEndEdit.AddListener((string value) => { OnTransformInputEndEdit(type, value); }); + inputField.Component.GetOnEndEdit().AddListener((string value) => { OnTransformInputEndEdit(type, value); }); var control = new TransformControl(type, inputField); diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 4c8b943..2e172b8 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -378,7 +378,7 @@ namespace UnityExplorer.UI timeInput = UIFactory.CreateInputField(navbarPanel, "TimeInput", "timeScale"); UIFactory.SetLayoutElement(timeInput.Component.gameObject, minHeight: 25, minWidth: 40); timeInput.Text = Time.timeScale.ToString("F2"); - timeInput.Component.onEndEdit.AddListener(OnTimeInputEndEdit); + timeInput.Component.GetOnEndEdit().AddListener(OnTimeInputEndEdit); pauseBtn = UIFactory.CreateButton(navbarPanel, "PauseButton", "||", new Color(0.2f, 0.2f, 0.2f)); UIFactory.SetLayoutElement(pauseBtn.Component.gameObject, minHeight: 25, minWidth: 25);