diff --git a/DefaultEvents/Assets/DefaultEvents.unity b/DefaultEvents/Assets/DefaultEvents.unity index ba37ad9..47e7c63 100644 Binary files a/DefaultEvents/Assets/DefaultEvents.unity and b/DefaultEvents/Assets/DefaultEvents.unity differ diff --git a/DefaultEvents/Assets/InputExample.cs b/DefaultEvents/Assets/InputExample.cs index 9c9f706..0bf25d8 100644 --- a/DefaultEvents/Assets/InputExample.cs +++ b/DefaultEvents/Assets/InputExample.cs @@ -9,25 +9,20 @@ public class InputExample : MonoBehaviour [SerializeField] private InputField inputField = null; - [SerializeField] - private Button submitButton = null; - [SerializeField] private Text textDisplay = null; - UnityAction inputAction = null; // The InputField.onSubmit event sends one string argument that the action needs to accept - UnityAction buttonAction = null; - // Use this for initialization void Start() { - // Add a listener to be executed when a submit key is pressed - Enter by default - inputAction = (value) => OnInputSubmitted(value); // value represents the argument that will be passed from InputField.OnSubmit - inputField.onSubmit.AddListener(inputAction); - - // Add functionality to submit the InputField using a button - buttonAction = () => OnInputSubmitted(inputField.value); // capture the value of the InputField when the button is pressed - submitButton.onClick.AddListener(buttonAction); + // Add a Submit Event object with a listener. + /* Note: onEndEdit is called both when Submit key is pressed and when you click away from the field. + * If you want to build a larger form or not submit right away for any other reason, don't use this. + * Instead create a button that calls a function, which then reads the value of inputField.text + */ + InputField.SubmitEvent submitEvent = new InputField.SubmitEvent(); + submitEvent.AddListener(OnInputSubmitted); + inputField.onEndEdit = submitEvent; } private void OnInputSubmitted(string value) diff --git a/README.md b/README.md index fe647ba..14cefc9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ UnityGUIExamples ================ +Update 28 Nov 2014 + +Updated the Default Events example for InputFields to Unity version 4.6.0f3 + (3 Sep 2014) Scripting examples for the new Unity GUI. @@ -13,7 +17,7 @@ All examples are in C#. Default Events ================ -(31 Aug 2014) +(28 Nov 2014) Shows how to subscribe to default events of: