• 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
There is no documentation for VAM because they are Unity components. Everything you will do with them is 100% vanilla Unity C#.

onValueChanged events can be triggered with listeners, you can find examples in VAMStory's code.
The focus implementation of Unity for input fields is shitty at best, I generally tend to use onEndEdit.

The way you did with a new class is ultra standard for Unity. Don't be afraid to use that... it's the way Unity works : )
 
Upvote 0
Back
Top Bottom