csharp 使用箭头键调试导航功能
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 使用箭头键调试导航功能相关的知识,希望对你有一定的参考价值。
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));
}
}
}
}
}
以上是关于csharp 使用箭头键调试导航功能的主要内容,如果未能解决你的问题,请参考以下文章