Input Enter Submit:

- Option to defocus input on hitting the enter key
- Demo
pull/413/head
LARS-LAPTOP2\larsme 2019-02-22 16:03:59 +01:00
parent ff47f703c0
commit cd0800d701
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);
}
} }
} }
} }