• Hi Guest!

    We are extremely excited to announce the release of our first Beta for VaM2, the next generation of Virt-A-Mate which is currently in development.
    To participate in the Beta, a subscription to the Entertainer or Creator Tier is required. Once subscribed, download instructions can be found here.

    Click here for information and guides regarding the VaM2 beta. Join our Discord server for more announcements and community discussion about VaM2.

Question Focus or Change event for InputField

henshin

Member
Joined
Dec 29, 2023
Messages
155
Reactions
22
I'm using Utils.SetupInputXButton from MacGruber_Utils and I need a way to detect when the input text changed (or better when focus is on and off)

Also is there any documentation to understand better all these UI elements?
 
I've found this solution but not sure if it's the recommended way (creating a new class to get focus events?)

Code:
UIDynamicInputXButton testBtn = Utils.SetupInputXButton(this, new JSONStorableString("Info", "test buttonX"), () => { SuperController.LogMessage("BUTTONX TEST"); }, false);
InputFieldFocusEvents fd = testBtn.input.gameObject.AddComponent<InputFieldFocusEvents>();
fd.mainInstance = this;

public class InputFieldFocusEvents : MonoBehaviour, ISelectHandler, IDeselectHandler
    {
        public MVRScript mainInstance;
        public void OnSelect(BaseEventData eventData)
        {
            InputField input = GetComponent<InputField>();
            string currentText = input != null ? input.text : "";
            SuperController.LogMessage(currentText);
        }
        public void OnDeselect(BaseEventData eventData)
        {
            InputField input = GetComponent<InputField>();
            string currentText = input != null ? input.text : "";
            SuperController.LogMessage(currentText);
        }
    }
 
Upvote 0
Back
Top Bottom