Files
ichni_Creator_Studio/Assets/Scripts/Console/EditorConsole.cs
TRAfoer 1b3c3556a1 优化hierarchy
即时生成和删除tab(不会做动态刷新
基本上hierarchy的性能就到这了,之后还是做点辅助工具防止1000+的栏展开吧
(重要)bug测试不完全,需要再加改进
2025-02-12 01:57:18 +08:00

147 lines
4.8 KiB
C#

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;
//又在写大粪 ——神币
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){
}
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(InputCommand.isFocused){
if(Input.GetKeyDown(KeyCode.DownArrow)){
if(historyCommand.Count-1>historycount){
historycount++;
InputCommand.text=historyCommand[historycount];}
else {
InputCommand.text="";
historycount=historyCommand.Count;
}
}
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 void Batch(string name,string prop,int loop,string expression);
private Batch _batch;
private void SetUpFunctions()
{
functionInterpreter = new Interpreter();
functionInterpreter.SetFunction("test",(Action)Test);
functionInterpreter.SetFunction("loopg", (Action<string,int>)LoopGenerate);
functionInterpreter.SetFunction("print", (Action<object>)print);
functionInterpreter.SetFunction("log", (Action<object>)Debug.Log);
_batch=BatchGenerate;
functionInterpreter.SetFunction("BatchGenerate",_batch);
}
private void Test()
{
//放入测试代码
var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List<string>(), true, null);
}
private GameElement Find(object name){
string text=name.ToString();
GameElement[] allObjects = Resources.FindObjectsOfTypeAll(typeof(GameElement)) as GameElement[];
List<int> objs = new List< int > ();
List<GameElement> 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 BatchGenerate(string name,string prop,int loop,string expression){//
GameElement[] allObjects = Resources.FindObjectsOfTypeAll(typeof(GameElement)) as GameElement[];
List<int> objs=new();
foreach (GameElement obj in allObjects){
if(obj.elementName==name)objs.Add(obj.GetInstanceID());
}
print(objs);
//TODO: 预制件,属性,循环数,表达式
print("在做了");
}
private void LoopGenerate(string name,int time){
Track track= (Track)Find(name);
for(int i=0;i<time;i++){
PathNode.GenerateElement("PathNodes", Guid.NewGuid(), new List<string>(), true,track);
}
}
}
}