From 752c9b73e3820448824dca8168e7ed619c8b6621 Mon Sep 17 00:00:00 2001 From: TRAfoer Date: Sat, 8 Feb 2025 01:21:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=91=B8=E7=B4=A2DynamicExpresso?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 写了点东西 问题是如果你乱敲会爆各种奇怪的玩意 try catch找不过来的那种 --- Assets/Scripts/Base/Manager/EditorManager.cs | 12 +-- Assets/Scripts/Console/EditorConsole.cs | 87 ++++++++++++++------ 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/Assets/Scripts/Base/Manager/EditorManager.cs b/Assets/Scripts/Base/Manager/EditorManager.cs index 33a56337..2ac930af 100644 --- a/Assets/Scripts/Base/Manager/EditorManager.cs +++ b/Assets/Scripts/Base/Manager/EditorManager.cs @@ -29,13 +29,15 @@ namespace Ichni private void Start() { + + //currentJudgeType = NoteBase.NoteJudgeType.Perfect; var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List(), null); - // var dis0 = Displacement.GenerateElement("Displacement-0", f0, - // new FlexibleFloat(), - // new FlexibleFloat(new List(){new (0,2,0,2, AnimationCurveType.Linear)}), - // new FlexibleFloat()); + var dis0 = Displacement.GenerateElement("Displacement-0",Guid.NewGuid(), new List(),f0, + new FlexibleFloat(), + new FlexibleFloat(new List(){new (0,2,0,10, AnimationCurveType.Linear)}), + new FlexibleFloat()); var t0 = Track.GenerateElement("Track", Guid.NewGuid(), new List(), f0, Vector3.left * 5f); t0.trackPathSubmodule = new TrackPathSubmodule(t0, Track.TrackSpaceType.Linear, Track.TrackSamplingType.TimeDistributed, false); @@ -53,7 +55,7 @@ namespace Ichni var n0 = Tap.GenerateElement("Note-0", Guid.NewGuid(), new List(), 1f, t0); var n0v = BasicNoteVisual.GenerateElement("Note-0-V", Guid.NewGuid(), new List(), "basic", "BasicNoteTap3D", Vector3.zero, Vector3.zero, Vector3.one, n0); - + elementList.ForEach(e => { e.AfterInitialize(); diff --git a/Assets/Scripts/Console/EditorConsole.cs b/Assets/Scripts/Console/EditorConsole.cs index db3ff158..682a8333 100644 --- a/Assets/Scripts/Console/EditorConsole.cs +++ b/Assets/Scripts/Console/EditorConsole.cs @@ -4,9 +4,13 @@ using System.Collections.Generic; using UnityEngine; using DynamicExpresso; using UnityEngine.UI; +using UnityEngine.Events; using Dreamteck; using System.Text.RegularExpressions; -//目前为止我还不知道我在做什么,但是等我搞懂DynamicExpresso可能就会好一点 ——神币 +using DynamicExpresso.Exceptions; +using UnityEngine.UIElements; +using System.Linq; +//又在写大粪 ——神币 namespace Ichni.Editor { public partial class EditorConsole : MonoBehaviour @@ -14,31 +18,40 @@ namespace Ichni.Editor public Interpreter functionInterpreter; public InputField InputCommand; + private Dictionary historyCommand=new Dictionary(); + private int historycount=0; public GameObject ConsoleUI; - public void GetCommand()//当提交命令时 - { - string[] Command =InputCommand.text.Split(" "); - - switch(Command[0]){ - case "help": - print("帮助菜单"); - break; - case "batgenerate": - - // - GameObject Prefab=new(); - // - BatchGenerate(Prefab,Command[2],int.Parse(Command[3]),Command[4]); - break; - default: - print("No command match!"); - break; - } + + + public void GetChange(string change){ + //print(change[InputCommand.caretPosition-1]); + + } + public void GetCommand(string Command)//当提交命令时 + { + + if(InputCommand.text=="")return; + try{functionInterpreter.Eval(Command); + }catch(UnknownIdentifierException){Debug.LogWarning("指令未找到!");} + if(historyCommand.ContainsKey(historycount))historyCommand[historycount]=Command; + else historyCommand.Add(historycount,Command); + historycount++; InputCommand.text=""; + } + private void Update(){ + if(InputCommand.isFocused){ + if(Input.GetKeyDown(KeyCode.DownArrow)&&historyCommand.Count-1>historycount){ + historycount++; + InputCommand.text=historyCommand[historycount]; + }else if(Input.GetKeyDown(KeyCode.UpArrow)&&historycount!=0){ + historycount--; + InputCommand.text=historyCommand[historycount]; + } + } + } - private void Start() @@ -48,22 +61,46 @@ namespace Ichni.Editor SetUpFunctions(); //Test - functionInterpreter.Eval("Log(\"Hello World!\")"); + functionInterpreter.Eval("print(\"Hello World!\")"); + functionInterpreter.Eval("log(\"Hello World but debug!\")"); } } public partial class EditorConsole { - + private delegate int math(int A); + private delegate void Batch(GameObject[] objet,string prop,int loop,string expression); + private Batch _batch; + private math _math; private void SetUpFunctions() { functionInterpreter = new Interpreter(); - functionInterpreter.SetFunction("Log", (System.Action)Debug.Log); + functionInterpreter.SetFunction("print", (Action)print); + functionInterpreter.SetFunction("log", (Action)Debug.Log); + _batch=BatchGenerate; + functionInterpreter.SetFunction("BatchGenerate",_batch); + + _math=swap; + functionInterpreter.SetFunction("swap",_math); + _math=zheng; + functionInterpreter.SetFunction("nswap",_math); } - private void BatchGenerate(GameObject objet,string prop,int loop,string expression){// + private int zheng(int A){ + print(A); + return A;} + private int swap(int A){ + print(-A); + return -A;} + private void BatchGenerate(GameObject[] objet,string prop,int loop,string expression){// //TODO: 预制件,属性,循环数,表达式 print("在做了"); + + } + private void BatchSet(GameObject[] objet,string prop,int loop,string expression){// + //TODO: 预制件,属性,循环数,表达式 + print("在做了"); + } } } \ No newline at end of file