106 lines
3.5 KiB
C#
106 lines
3.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DynamicExpresso;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Events;
|
|
using Dreamteck;
|
|
using System.Text.RegularExpressions;
|
|
using DynamicExpresso.Exceptions;
|
|
using UnityEngine.UIElements;
|
|
using System.Linq;
|
|
//又在写大粪 ——神币
|
|
namespace Ichni.Editor
|
|
{
|
|
public partial class EditorConsole : MonoBehaviour
|
|
{
|
|
|
|
public Interpreter functionInterpreter;
|
|
public InputField InputCommand;
|
|
private Dictionary<int,string> historyCommand=new Dictionary<int,string>();
|
|
private int historycount=0;
|
|
public GameObject ConsoleUI;
|
|
|
|
|
|
|
|
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()
|
|
{
|
|
|
|
|
|
SetUpFunctions();
|
|
|
|
//Test
|
|
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("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 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("在做了");
|
|
|
|
}
|
|
}
|
|
} |