摸索DynamicExpresso

写了点东西
问题是如果你乱敲会爆各种奇怪的玩意
try catch找不过来的那种
This commit is contained in:
2025-02-08 01:21:40 +08:00
parent 1be8a5a900
commit 752c9b73e3
2 changed files with 69 additions and 30 deletions

View File

@@ -29,13 +29,15 @@ namespace Ichni
private void Start()
{
//currentJudgeType = NoteBase.NoteJudgeType.Perfect;
var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List<string>(), null);
// var dis0 = Displacement.GenerateElement("Displacement-0", f0,
// new FlexibleFloat(),
// new FlexibleFloat(new List<AnimatedFloat>(){new (0,2,0,2, AnimationCurveType.Linear)}),
// new FlexibleFloat());
var dis0 = Displacement.GenerateElement("Displacement-0",Guid.NewGuid(), new List<string>(),f0,
new FlexibleFloat(),
new FlexibleFloat(new List<AnimatedFloat>(){new (0,2,0,10, AnimationCurveType.Linear)}),
new FlexibleFloat());
var t0 = Track.GenerateElement("Track", Guid.NewGuid(), new List<string>(), 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<string>(), 1f, t0);
var n0v = BasicNoteVisual.GenerateElement("Note-0-V", Guid.NewGuid(), new List<string>(), "basic",
"BasicNoteTap3D", Vector3.zero, Vector3.zero, Vector3.one, n0);
elementList.ForEach(e =>
{
e.AfterInitialize();

View File

@@ -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<int,string> historyCommand=new Dictionary<int,string>();
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<object>)Debug.Log);
functionInterpreter.SetFunction("print", (Action<object>)print);
functionInterpreter.SetFunction("log", (Action<object>)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("在做了");
}
}
}