Created
March 1, 2018 15:38
-
-
Save bitinn/e22176b5aeec5ae12a78f388b4ee2b9e to your computer and use it in GitHub Desktop.
Fake OnSubmit for Input Field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using UnityEngine.EventSystems; | |
namespace BeginHQ.Utility { | |
/* | |
redirect submit event to parent | |
*/ | |
public class UISubmitInput : MonoBehaviour { | |
private void Awake () { | |
var input = gameObject.GetComponent<InputField>(); | |
input.onEndEdit.AddListener((s) => { | |
HandleSubmit(input); | |
}); | |
} | |
private void HandleSubmit (InputField input) { | |
var ev = new BaseEventData(EventSystem.current); | |
ExecuteEvents.ExecuteHierarchy(transform.parent.gameObject, ev, ExecuteEvents.submitHandler); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment