Hello to everyone. I register an event like this: Code (CSharp): textFieldExample.Q(TextField.textInputUssName).RegisterCallback<KeyUpEvent>(e => functionExample("hello")); Now i am trying to remove it but i can't in any way, any suggestions?
You can do it like that: Code (CSharp): private void OnEnable() { root = GetComponent<UIDocument>().rootVisualElement; var tf = root.Q<TextField>("my-textfield"); tf.Q(TextField.textInputUssName).RegisterCallback<KeyUpEvent>(keyUpAction); tf.Q(TextField.textInputUssName).UnregisterCallback<KeyUpEvent>(keyUpAction); } private void keyUpAction(KeyUpEvent evt) { Debug.Log("hello"); }
There are several ways to do that, one is to create a class like so: Code (CSharp): class actionClass { public string Parameter { get; set; } public void keyUpAction(KeyUpEvent evt) { Debug.Log(Parameter); } } then: Code (CSharp): var ac = new actionClass(); ac.Parameter = "hello"; tf.Q(TextField.textInputUssName).RegisterCallback<KeyUpEvent>(ac.keyUpAction); and when you need to change the parameter you simply do: Code (CSharp): ac.Parameter = "world";