From 1a22c2fa3f1a98b0a8e2a63ded723df671ee670d Mon Sep 17 00:00:00 2001 From: Scott Doxey Date: Sun, 12 Jul 2020 12:15:22 -0400 Subject: [PATCH] Prevent tabbing or submitting from other forms. --- Scripts/Form.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Scripts/Form.cs b/Scripts/Form.cs index 6a6353e..b583eb3 100644 --- a/Scripts/Form.cs +++ b/Scripts/Form.cs @@ -49,9 +49,19 @@ private void Update() return; } + var selectable = _eventSystem.currentSelectedGameObject.GetComponent(); + + var allSelectable = _eventSystem.currentSelectedGameObject.GetComponentInParent
() + .GetComponentsInChildren(); + + if (!allSelectable.Contains(selectable)) + { + return; + } + if (Input.GetKeyDown(KeyCode.Tab)) { - HandleTabPress(); + HandleTabPress(selectable, allSelectable); } if (Input.GetKeyDown(KeyCode.Return)) @@ -61,14 +71,9 @@ private void Update() } - private void HandleTabPress() + private void HandleTabPress(Selectable selectable, Selectable[] allSelectable) { - var selectable = _eventSystem.currentSelectedGameObject.GetComponent(); - - var allSelectable = _eventSystem.currentSelectedGameObject.GetComponentInParent() - .GetComponentsInChildren(); - var prevSelectable = selectable.FindSelectableOnUp() ?? allSelectable.Last(); var nextSelectable = selectable.FindSelectableOnDown() ?? allSelectable.First();