Files
Studio/Assets/Scripts/XED/UI/Canvas/Canvas_Commander.cs

115 lines
2.7 KiB
C#
Raw Normal View History

2025-02-19 17:24:26 +09:00
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using WI.UI;
namespace XED
{
public class Canvas_Commander : CanvasBase
{
public string[] commands =
{
"HELP",
"WAIT",
"CREATE",
"COUNT",
};
public TMP_InputField input;
public Button Button_ComponentMode;
public Button Button_NormalMode;
public Button Button_Depth0;
public Button Button_Depth1;
public Button Button_Depth2;
public Button Button_Depth3;
public Button Button_Depth4;
private void Awake()
{
input = GetComponentInChildren<TMP_InputField>();
}
public override void AfterAwake()
{
Button_ComponentMode.onClick.AddListener(OnClickComponentMode);
Button_NormalMode.onClick.AddListener(OnClickNormalMode);
Button_Depth0.onClick.AddListener(OnClickDepth0);
Button_Depth1.onClick.AddListener(OnClickDepth1);
Button_Depth2.onClick.AddListener(OnClickDepth2);
Button_Depth3.onClick.AddListener(OnClickDepth3);
Button_Depth4.onClick.AddListener(OnClickDepth4);
}
private void OnClickDepth4()
{
OnClickComponentMode();
}
private void OnClickDepth3()
{
Camera.main.fieldOfView = 40;
}
private void OnClickDepth2()
{
Camera.main.fieldOfView = 50;
}
private void OnClickDepth1()
{
Camera.main.fieldOfView = 60;
}
private void OnClickDepth0()
{
Camera.main.fieldOfView = 70;
}
private void OnClickNormalMode()
{
Camera.main.orthographic = false;
}
private void OnClickComponentMode()
{
Camera.main.orthographic = true;
}
private void Update()
{
if(input.isFocused && Input.GetKeyDown(KeyCode.Return))
{
Command(input.text);
input.text = "";
}
}
void Command(string args)
{
var commands = args.Split(' ');
for (int i = 0; i < commands.Length; i++)
{
if (!CommandCheck(commands[i]))
{
Debug.Log("Command not found: " + commands[i]);
return;
}
}
}
bool CommandCheck(string command)
{
foreach (var c in commands)
{
if(command == c)
{
return true;
}
}
return false;
}
}
}