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 Canvas[] scaleParts; public Interpreter functionInterpreter; public TMP_InputField InputCommand; private Dictionary historyCommand=new Dictionary(); 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(Keyboard.current.leftCtrlKey.isPressed&&Keyboard.current.upArrowKey.wasPressedThisFrame){ foreach(Canvas i in scaleParts){ var canvasScaler = i.GetComponent(); canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x + 100, canvasScaler.referenceResolution.y); } }else if(Keyboard.current.leftCtrlKey.isPressed&&Keyboard.current.downArrowKey.wasPressedThisFrame){ foreach(Canvas i in scaleParts){ var canvasScaler = i.GetComponent(); canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x - 100, canvasScaler.referenceResolution.y); } } 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)LGenPathNodes); functionInterpreter.SetFunction("print", (Action)print); functionInterpreter.SetFunction("log", (Action)Debug.Log); } private void Test() { //放入测试代码 var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List(), true, null); } private GameElement Find(object name){ string text=name.ToString(); GameElement[] allObjects = Resources.FindObjectsOfTypeAll(typeof(GameElement)) as GameElement[]; List objs = new List< int > (); List 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(), true,track); } } } }