File tree Expand file tree Collapse file tree 1 file changed +23
-17
lines changed Expand file tree Collapse file tree 1 file changed +23
-17
lines changed Original file line number Diff line number Diff line change 6
6
7
7
namespace UXF
8
8
{
9
- /// <summary>
10
- /// A script that can be added to an object with an input field, when enter is pressed while editing the input field a UnityEvent will be invoked
11
- /// </summary>
12
- public class InputFieldKeyboardReturnEvent : MonoBehaviour
13
- {
14
- private InputField inputField ;
9
+ /// <summary>
10
+ /// A script that can be added to an object with an input field, when enter is pressed while editing the input field a UnityEvent will be invoked
11
+ /// </summary>
12
+ public class InputFieldKeyboardReturnEvent : MonoBehaviour
13
+ {
14
+ private InputField inputField ;
15
15
16
- public UnityEvent onReturn ;
16
+ public UnityEvent onReturn ;
17
17
18
- void Start ( )
19
- {
20
- inputField = GetComponent < InputField > ( ) ;
21
- }
18
+ void Start ( )
19
+ {
20
+ inputField = GetComponent < InputField > ( ) ;
21
+ }
22
22
23
- void OnGUI ( )
24
- {
25
- if ( inputField . isFocused && ! string . IsNullOrEmpty ( inputField . text ) && Input . GetKeyDown ( KeyCode . Return ) )
26
- onReturn . Invoke ( ) ;
27
- }
28
- }
23
+ void OnGUI ( )
24
+ {
25
+ if ( inputField . isFocused &&
26
+ ! string . IsNullOrEmpty ( inputField . text ) &&
27
+ ( Input . GetKeyDown ( KeyCode . Return ) || Input . GetKeyDown ( KeyCode . KeypadEnter ) ) )
28
+ {
29
+ onReturn . Invoke ( ) ;
30
+ inputField . Select ( ) ;
31
+ inputField . ActivateInputField ( ) ;
32
+ }
33
+ }
34
+ }
29
35
}
You can’t perform that action at this time.
0 commit comments