UniversalViewer/Assets/Scripts/KeyboardShortcuts.cs

101 lines
2.6 KiB
C#
Raw Normal View History

2024-04-21 22:38:26 +08:00
using CommandUndoRedo;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
public class KeyboardShortcuts : MonoBehaviour
{
public static KeyboardShortcuts Instance;
EventSystem eventSystem;
public bool KeyboardLocked = false;
public List<char> KeyStrokes = new List<char>();
private void Awake()
{
if (Instance != null)
{
Destroy(Instance);
}
Instance = this;
eventSystem = EventSystem.current;
}
public void Undo()
{
UndoRedoManager.Undo();
}
public void Redo()
{
UndoRedoManager.Redo();
}
private void Update()
{
if (eventSystem.currentSelectedGameObject != null) return;
KatboiSequence();
if (Input.anyKeyDown && !string.IsNullOrEmpty(Input.inputString))
{
switch (Input.inputString.ToUpper()[0])
{
case 'H':
//Settings.Instance.showHints = !Settings.Instance.showHints;
//ModelViewerInterface.GetInstance().TooltipLabels[0].transform.parent.gameObject.SetActive(Settings.Instance.showHints);
//Settings.Save();
break;
case 'X':
Screenshot.Instance.TakeScreenshot();
break;
}
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
TimelineController.ChangeCurrentFrame(1, true);
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
TimelineController.ChangeCurrentFrame(-1, true);
}
else if (Input.GetKeyDown(KeyCode.Space))
{
TimelineController.Instance.Play = !TimelineController.Instance.Play;
}
}
private void KatboiSequence()
{
List<string> sequences = new List<string>()
{
"KATBOI01"
};
if (Input.anyKeyDown && !string.IsNullOrEmpty(Input.inputString))
{
if (KeyStrokes.Count >= 10)
{
KeyStrokes = KeyStrokes.Skip(KeyStrokes.Count - 10).ToList();
}
KeyStrokes.Add(Input.inputString.ToUpper()[0]);
}
var curString = new string(KeyStrokes.ToArray());
string passcode = sequences.FirstOrDefault(s => curString.Contains(s));
if (!string.IsNullOrEmpty(passcode))
{
switch (passcode)
{
case "KATBOI01":
//secret here
break;
default: break;
}
KeyStrokes.Clear();
}
}
}