摸索DynamicExpresso
写了点东西 问题是如果你乱敲会爆各种奇怪的玩意 try catch找不过来的那种
This commit is contained in:
@@ -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("在做了");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user