Files
Studio/Assets/Canvas_Commander.cs
2025-02-19 17:43:14 +09:00

58 lines
1.2 KiB
C#

using TMPro;
using UnityEngine;
namespace XED
{
public class Canvas_Commander : MonoBehaviour
{
public string[] commands =
{
"HELP",
"WAIT",
"CREATE",
"COUNT",
};
public TMP_InputField input;
private void Awake()
{
input = GetComponentInChildren<TMP_InputField>();
}
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;
}
}
}