Instantly share code, notes, and snippets.
Created
July 24, 2019 01:24
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save jadepark-dev/094eed8be753c73ea18c8dece238c8bf to your computer and use it in GitHub Desktop.
This file contains 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; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
using UnityEngine.EventSystems; | |
public class DebugNavigationManager : MonoBehaviour | |
{ | |
public AppManager _Appmanager; | |
EventSystem system; | |
public GameObject settingsPanel; | |
public GameObject TrackingManager; | |
public GameObject SettingManager; | |
public GameObject initSelection; | |
public bool inSettingMode = false; | |
public bool findFirstSelectable = false; | |
void Start() | |
{ | |
system = EventSystem.current; | |
} | |
void Update() | |
{ if(_Appmanager.isDebugging){ | |
ShortcutsForSetting(); | |
TabNavigation(); | |
} | |
} | |
public void ToggleSettingsPanel() | |
{ | |
if (settingsPanel.activeSelf) | |
{ | |
settingsPanel.SetActive(false); | |
inSettingMode = false; | |
} | |
else | |
{ | |
settingsPanel.SetActive(true); | |
inSettingMode = true; | |
} | |
} | |
public void ShortcutsForSetting() | |
{ | |
// Ctrl + T to show setting panel. | |
if (Input.GetKeyDown(KeyCode.T)) | |
{ | |
if (Input.GetKey(KeyCode.LeftControl)) | |
{ | |
ToggleSettingsPanel(); | |
if(inSettingMode){ | |
InputField inputfield = initSelection.GetComponent<InputField>(); | |
if (inputfield != null)inputfield.OnPointerClick(new PointerEventData(system)); | |
system.SetSelectedGameObject(initSelection.gameObject, new BaseEventData(system)); | |
} | |
} | |
} | |
if (inSettingMode) | |
{ | |
// Ctrl + Y to Init Camera Calibration. | |
if (Input.GetKeyDown(KeyCode.Y)) | |
{ | |
if (Input.GetKey(KeyCode.LeftControl)) | |
{ | |
TrackingManager.GetComponent<CamCalibration>().CamCaliInit(); | |
} | |
} | |
// Ctrl + S to Save Settings. | |
// Ctrl + Shift + S to Save Settings into Default Settings File. | |
if (Input.GetKeyDown(KeyCode.S)) | |
{ | |
if (Input.GetKey(KeyCode.LeftControl)) | |
{ | |
SettingManager.GetComponent<SettingManager>().SaveSettings(0); | |
if (Input.GetKey(KeyCode.LeftShift)) | |
{ | |
SettingManager.GetComponent<SettingManager>().SaveSettings(1); | |
} | |
} | |
} | |
// Ctrl + L to Load Settings. | |
// Ctrl + Shift + L to Load Settings from Default Settings File. | |
if (Input.GetKeyDown(KeyCode.L)) | |
{ | |
if (Input.GetKey(KeyCode.LeftControl)) | |
{ | |
SettingManager.GetComponent<SettingManager>().LoadSettings(0); | |
if (Input.GetKey(KeyCode.LeftShift)) | |
{ | |
SettingManager.GetComponent<SettingManager>().LoadSettings(1); | |
} | |
} | |
} | |
} | |
} | |
private void TabNavigation() | |
{ | |
if (inSettingMode) | |
{ | |
if (Input.GetKeyDown(KeyCode.Tab)) | |
{ | |
if (Input.GetKey(KeyCode.LeftShift)) | |
{ | |
Selectable prev = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnLeft(); | |
if (prev != null) | |
{ | |
InputField inputfield = prev.GetComponent<InputField>(); | |
if (inputfield != null) | |
inputfield.OnPointerClick(new PointerEventData(system)); | |
system.SetSelectedGameObject(prev.gameObject, new BaseEventData(system)); | |
} | |
} | |
else | |
{ | |
Selectable next = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnRight(); | |
if (next != null) | |
{ | |
InputField inputfield = next.GetComponent<InputField>(); | |
if (inputfield != null) inputfield.OnPointerClick(new PointerEventData(system)); | |
system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); | |
} | |
} | |
} | |
if (Input.GetKeyDown(KeyCode.UpArrow)) | |
{ | |
Selectable up = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnUp(); | |
if (up != null) | |
{ | |
InputField inputfield = up.GetComponent<InputField>(); | |
if (inputfield != null) inputfield.OnPointerClick(new PointerEventData(system)); | |
system.SetSelectedGameObject(up.gameObject, new BaseEventData(system)); | |
} | |
} | |
if (Input.GetKeyDown(KeyCode.DownArrow)) | |
{ | |
Selectable down = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnDown(); | |
if (down != null) | |
{ | |
InputField inputfield = down.GetComponent<InputField>(); | |
if (inputfield != null) inputfield.OnPointerClick(new PointerEventData(system)); | |
system.SetSelectedGameObject(down.gameObject, new BaseEventData(system)); | |
} | |
} | |
if (Input.GetKeyDown(KeyCode.LeftArrow)) | |
{ | |
Selectable left = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnLeft(); | |
if (left != null) | |
{ | |
InputField inputfield = left.GetComponent<InputField>(); | |
if (inputfield != null) inputfield.OnPointerClick(new PointerEventData(system)); | |
system.SetSelectedGameObject(left.gameObject, new BaseEventData(system)); | |
} | |
} | |
if (Input.GetKeyDown(KeyCode.RightArrow)) | |
{ | |
Selectable right = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnRight(); | |
if (right != null) | |
{ | |
InputField inputfield = right.GetComponent<InputField>(); | |
if (inputfield != null) inputfield.OnPointerClick(new PointerEventData(system)); | |
system.SetSelectedGameObject(right.gameObject, new BaseEventData(system)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment