Input Enter Submit:
- Option to defocus input on hitting the enter key - Demopull/413/head
parent
ff47f703c0
commit
cd0800d701
|
@ -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
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 45161b084cced954b88fb3d619bc7f9a
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -13,9 +13,13 @@ namespace UnityEngine.UI.Extensions
|
|||
public class InputFieldEnterSubmit : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class EnterSubmitEvent : UnityEvent<string> { }
|
||||
public class EnterSubmitEvent : UnityEvent<string>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EnterSubmitEvent EnterSubmit;
|
||||
public bool defocusInput = true;
|
||||
private InputField _input;
|
||||
|
||||
void Awake()
|
||||
|
@ -26,8 +30,13 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
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);
|
||||
if (defocusInput)
|
||||
{
|
||||
UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue