From e042713cf5fc2ef021bb2806a9544685bcbc07b0 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. --- .../Plugins/CandyCoded.Forms/Scripts/Form.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Assets/Plugins/CandyCoded.Forms/Scripts/Form.cs b/Assets/Plugins/CandyCoded.Forms/Scripts/Form.cs index 6a6353e..b583eb3 100644 --- a/Assets/Plugins/CandyCoded.Forms/Scripts/Form.cs +++ b/Assets/Plugins/CandyCoded.Forms/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();