149 lines
4.5 KiB
C#
149 lines
4.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DynamicExpresso;
|
|
using UnityEngine.UI;
|
|
|
|
using Dreamteck;
|
|
using System.Text.RegularExpressions;
|
|
using DynamicExpresso.Exceptions;
|
|
using UnityEngine.UIElements;
|
|
using System.Linq;
|
|
using Unity.VisualScripting;
|
|
using Ichni.RhythmGame;
|
|
using Sirenix.Utilities;
|
|
using UnityEngine.InputSystem;
|
|
using TMPro;
|
|
|
|
//又在写大粪 ——神币
|
|
namespace Ichni.Editor
|
|
{
|
|
public partial class EditorConsole : MonoBehaviour
|
|
{
|
|
|
|
public Interpreter functionInterpreter;
|
|
public TMP_InputField InputCommand;
|
|
private Dictionary<int,string> historyCommand=new Dictionary<int,string>();
|
|
private int historycount=0;
|
|
public GameObject ConsoleUI;
|
|
|
|
public Hierarchy hierarchy;
|
|
public Inspector inspector;
|
|
bool isHide=true;
|
|
|
|
public void GetChange(string change){
|
|
|
|
}
|
|
public void GetCommand(string Command)//当提交命令时
|
|
{
|
|
|
|
if(InputCommand.text=="")return;
|
|
if(historyCommand.ContainsKey(historycount))historyCommand[historycount]=Command;
|
|
else historyCommand.Add(historycount,Command);
|
|
historycount++;
|
|
InputCommand.text="";
|
|
try{functionInterpreter.Eval(Command);
|
|
}catch(Exception e){Debug.LogWarning("WTF Command! "+e);}
|
|
}
|
|
private void Update(){
|
|
if(Keyboard.current.backquoteKey.wasPressedThisFrame){
|
|
ConsoleUI.SetActive(isHide);
|
|
|
|
isHide=!isHide;
|
|
}
|
|
if(InputCommand.isFocused){
|
|
if(Keyboard.current.downArrowKey.wasPressedThisFrame){
|
|
if(historyCommand.Count-1>historycount){
|
|
historycount++;
|
|
InputCommand.text=historyCommand[historycount];}
|
|
else {
|
|
InputCommand.text="";
|
|
historycount=historyCommand.Count;
|
|
}
|
|
|
|
}
|
|
if(Keyboard.current.upArrowKey.wasPressedThisFrame && historycount!=0){
|
|
historycount--;
|
|
InputCommand.text=historyCommand[historycount];
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void Start()
|
|
{
|
|
|
|
|
|
SetUpFunctions();
|
|
|
|
//Test
|
|
// functionInterpreter.Eval("print(\"Hello World!\")");
|
|
// functionInterpreter.Eval("log(\"Hello World but debug!\")");
|
|
}
|
|
}
|
|
|
|
public partial class EditorConsole
|
|
{
|
|
|
|
|
|
|
|
|
|
private void SetUpFunctions()
|
|
{
|
|
functionInterpreter = new Interpreter();
|
|
functionInterpreter.SetFunction("test",(Action)Test);
|
|
functionInterpreter.SetFunction("lgp", (Action<string,int>)LGenPathNodes);
|
|
functionInterpreter.SetFunction("print", (Action<object>)print);
|
|
functionInterpreter.SetFunction("log", (Action<object>)Debug.Log);
|
|
|
|
|
|
|
|
}
|
|
|
|
private void Test()
|
|
{
|
|
//放入测试代码
|
|
var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List<string>(), true, null);
|
|
}
|
|
private GameElement Find(object name){
|
|
string text=name.ToString();
|
|
GameElement[] allObjects = Resources.FindObjectsOfTypeAll(typeof(GameElement)) as GameElement[];
|
|
List<int> objs = new List< int > ();
|
|
List<GameElement> obji = new List< GameElement > ();
|
|
foreach (GameElement obj in allObjects){
|
|
if (obj.elementName == text) {
|
|
objs.Add(obj.GetInstanceID());
|
|
obji.Add(obj);
|
|
print(objs[objs.Count()-1]);
|
|
}
|
|
}
|
|
//TODO duotrack选择菜单
|
|
|
|
if(obji.IsNullOrEmpty()){
|
|
Debug.LogWarning("no find");
|
|
return null;}
|
|
return obji[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LGenPathNodes(string name,int loop){
|
|
|
|
Track track= (Track)Find(name);
|
|
|
|
for(int i=0;i<loop;i++){
|
|
|
|
var p=PathNode.GenerateElement("PathNodes", Guid.NewGuid(), new List<string>(), true,track);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
} |