Skip to content

Commit

Permalink
Prevent tabbing or submitting from other forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
neogeek committed Jul 12, 2020
1 parent 12fc625 commit 1a22c2f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Scripts/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,19 @@ private void Update()
return;
}

var selectable = _eventSystem.currentSelectedGameObject.GetComponent<Selectable>();

var allSelectable = _eventSystem.currentSelectedGameObject.GetComponentInParent<Form>()
.GetComponentsInChildren<Selectable>();

if (!allSelectable.Contains(selectable))
{
return;
}

if (Input.GetKeyDown(KeyCode.Tab))
{
HandleTabPress();
HandleTabPress(selectable, allSelectable);
}

if (Input.GetKeyDown(KeyCode.Return))
Expand All @@ -61,14 +71,9 @@ private void Update()

}

private void HandleTabPress()
private void HandleTabPress(Selectable selectable, Selectable[] allSelectable)
{

var selectable = _eventSystem.currentSelectedGameObject.GetComponent<Selectable>();

var allSelectable = _eventSystem.currentSelectedGameObject.GetComponentInParent<Form>()
.GetComponentsInChildren<Selectable>();

var prevSelectable = selectable.FindSelectableOnUp() ?? allSelectable.Last();
var nextSelectable = selectable.FindSelectableOnDown() ?? allSelectable.First();

Expand Down

0 comments on commit 1a22c2f

Please sign in to comment.