• Hi Guest!

    We have posted a new VaM2 dev log on Patreon, starting a monthly cadence of written progress updates between Beta releases. Highlights include the new Gizmos System, Selection Carousel, and Modes System with Context-Specific Editing. Beta1.2 is 15 of 21 items complete.

    Read the full post on Patreon, or follow progress on the public Trello roadmap.

Question Focus or Change event for InputField

henshin

Active member
Joined
Dec 29, 2023
Messages
202
Reactions
94
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