Merged in larsme/unity-ui-extensions/inputField_Enter_Submit_defocus_Input_Option (pull request #46)

Defocus Option and Demo for Input Enter Submit Script
pull/413/head
lars me 2019-02-25 15:01:47 +00:00 committed by Simon Jackson
commit d7d293a348
4 changed files with 1226 additions and 2 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9faa2b8f6b738d543a53cea7512c605d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 45161b084cced954b88fb3d619bc7f9a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,9 +13,13 @@ namespace UnityEngine.UI.Extensions
public class InputFieldEnterSubmit : MonoBehaviour public class InputFieldEnterSubmit : MonoBehaviour
{ {
[System.Serializable] [System.Serializable]
public class EnterSubmitEvent : UnityEvent<string> { } public class EnterSubmitEvent : UnityEvent<string>
{
}
public EnterSubmitEvent EnterSubmit; public EnterSubmitEvent EnterSubmit;
public bool defocusInput = true;
private InputField _input; private InputField _input;
void Awake() void Awake()
@ -26,8 +30,13 @@ namespace UnityEngine.UI.Extensions
public void OnEndEdit(string txt) public void OnEndEdit(string txt)
{ {
if (!Input.GetKeyDown(KeyCode.Return) && !Input.GetKeyDown(KeyCode.KeypadEnter)) return; if (!Input.GetKeyDown(KeyCode.Return) && !Input.GetKeyDown(KeyCode.KeypadEnter))
return;
EnterSubmit.Invoke(txt); EnterSubmit.Invoke(txt);
if (defocusInput)
{
UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
}
} }
} }
} }