I am looking for an example of how to grab the OnSubmit (and the others) events from InputField. Can’t find any and I don’t seem to be able to wrap my head around it without an example to read.
There is no example of it in the demoproject and I would suggest adding one.
—EDIT—
So I found the solution. Leaving a simple example here so it can help someone else.
using UnityEngine;
using UnityEngine.UI;
public class GConsoleuGUIInput : MonoBehaviour {
void Start() {
GetComponent<InputField> ().onSubmit.AddListener (OnSubmit);
}
void OnSubmit(string line) {
Debug.Log ("OnSubmit("+line+")");
}
}
I take it you have the same problem as I have, which is InputField being defocused when trying to add new line with Enter/Return? Logically pressing Enter while typing text into a multiline InputField should make a newline (Shift-Enter does that, but how many users know that?). I’m aware that EventSystem has Submit-button mapped to Enter/Return, but even when setting that to something else, the problem persists. I have filed a bug report, let’s see how it goes.
Sorry for not helping on your actual problem, I’ve yet to look into that myself…
Ctrl-enter is something that works in steamchat so it isn’t that far of from what users might find by experimenting.
But no. I am trying to trigger some code when you press enter to submit the thing you wrote. For console input to be precise.
So for me to be able to do what I need I need to be able to track any changes in inputvalue(each keypress) and submit. Oh and if the TextField have focus to actually. Will need that to make arrows up/down work I guess.
Problem is I haven’t done anything yet with such an eventsystem so I need to read some example code. I bet it isn’t hard once you know how to do it but I can’t find the info.