Last active
July 2, 2020 09:41
-
-
Save neogeek/4f253793fa026b829ee378f78c603fd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
using UnityEngine.EventSystems; | |
using UnityEngine.UI; | |
namespace CandyCoded | |
{ | |
public class Form : MonoBehaviour | |
{ | |
public Dictionary<string, string> GetFormValues() | |
{ | |
return gameObject.GetComponentsInChildren<FormField>().Where(field => field.name != "") | |
.ToDictionary(field => field.name, field => field.value); | |
} | |
private EventSystem _eventSystem; | |
private void Awake() | |
{ | |
_eventSystem = EventSystem.current; | |
} | |
private void Update() | |
{ | |
if (!Input.GetKeyDown(KeyCode.Tab)) | |
{ | |
return; | |
} | |
var selectable = _eventSystem.currentSelectedGameObject.GetComponent<Selectable>(); | |
var next = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) | |
? selectable.FindSelectableOnUp() | |
: selectable.FindSelectableOnDown(); | |
_eventSystem.SetSelectedGameObject(next.gameObject, null); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
namespace CandyCoded | |
{ | |
public class FormField : MonoBehaviour | |
{ | |
[SerializeField] | |
private string _name; | |
public new string name => _name; | |
public string value { get; internal set; } | |
public void SetValue(string value) | |
{ | |
this.value = value; | |
} | |
public void SetValue(int value) | |
{ | |
this.value = value.ToString(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.EventSystems; | |
using UnityEngine.UI; | |
namespace CandyCoded | |
{ | |
public class FormLabel : MonoBehaviour, IPointerClickHandler | |
{ | |
[SerializeField] | |
private Selectable _selectable; | |
private EventSystem _eventSystem; | |
private void Awake() | |
{ | |
_eventSystem = EventSystem.current; | |
} | |
public void OnPointerClick(PointerEventData eventData) | |
{ | |
_eventSystem.SetSelectedGameObject(_selectable.gameObject, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment