Skip to content

Commit 4350e26

Browse files
committed
fixed return functionality
1 parent 56a3aa1 commit 4350e26

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

Assets/UXF/Scripts/UI/InputFieldKeyboardReturnEvent.cs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@
66

77
namespace UXF
88
{
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;
1515

16-
public UnityEvent onReturn;
16+
public UnityEvent onReturn;
1717

18-
void Start()
19-
{
20-
inputField = GetComponent<InputField>();
21-
}
18+
void Start()
19+
{
20+
inputField = GetComponent<InputField>();
21+
}
2222

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+
}
2935
}

0 commit comments

Comments
 (0)