This commit is contained in:
2025-02-22 00:05:36 +08:00
parent dfa136eb3a
commit f3b7befda4
2 changed files with 26654 additions and 87 deletions

View File

@@ -15,6 +15,7 @@ using Ichni.RhythmGame;
using Sirenix.Utilities; using Sirenix.Utilities;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using TMPro; using TMPro;
using MoreMountains.Tools;
//又在写大粪 ——神币 //又在写大粪 ——神币
namespace Ichni.Editor namespace Ichni.Editor
@@ -24,143 +25,192 @@ namespace Ichni.Editor
public Canvas[] scaleParts; public Canvas[] scaleParts;
public Interpreter functionInterpreter; public Interpreter functionInterpreter;
public TMP_InputField InputCommand; public TMP_InputField InputCommand;
private Dictionary<int,string> historyCommand=new Dictionary<int,string>(); private Dictionary<int, string> historyCommand = new Dictionary<int, string>();
private int historycount=0; private int historycount = 0;
public GameObject ConsoleUI; public GameObject ConsoleUI;
public Hierarchy hierarchy; bool isHide = true;
public Inspector inspector;
bool isHide=true; public void GetChange(string change)
{
public void GetChange(string change){
} }
public void GetCommand(string Command)//当提交命令时 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
try{functionInterpreter.Eval(Command); {
}catch(Exception e){Debug.LogWarning("WTF Command! "+e);} functionInterpreter.Eval(Command);
}
catch (Exception e)
{
Debug.LogWarning("WTF Command! " + e);
LogWindow.Log("Unknow Command!", Color.red);
}
} }
private void Update(){ private void Update()
{
UIscale(); UIscale();
if(InputCommand.isFocused)InputDect(); if (InputCommand.isFocused) InputDect();
} }
private void UIscale(){ private void UIscale()
if(Keyboard.current.backquoteKey.wasPressedThisFrame){ {
if (Keyboard.current.backquoteKey.wasPressedThisFrame)
{
ConsoleUI.SetActive(isHide); ConsoleUI.SetActive(isHide);
isHide=!isHide; isHide = !isHide;
if (isHide) StartCoroutine(WindowAnim.ShowPanel(InputCommand.gameObject));
} }
if(Keyboard.current.leftCtrlKey.isPressed&&Keyboard.current.upArrowKey.wasPressedThisFrame){ if (Keyboard.current.leftCtrlKey.isPressed && Keyboard.current.upArrowKey.wasPressedThisFrame)
foreach(Canvas i in scaleParts){ {
var canvasScaler = i.GetComponent<CanvasScaler>(); foreach (Canvas i in scaleParts)
{
var canvasScaler = i.GetComponent<CanvasScaler>();
canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x + 100, canvasScaler.referenceResolution.y); canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x + 100, canvasScaler.referenceResolution.y);
} }
}else }
if(Keyboard.current.leftCtrlKey.isPressed&&Keyboard.current.downArrowKey.wasPressedThisFrame){ else
foreach(Canvas i in scaleParts){ if (Keyboard.current.leftCtrlKey.isPressed && Keyboard.current.downArrowKey.wasPressedThisFrame)
{
foreach (Canvas i in scaleParts)
{
var canvasScaler = i.GetComponent<CanvasScaler>(); var canvasScaler = i.GetComponent<CanvasScaler>();
canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x - 100, canvasScaler.referenceResolution.y); canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x - 100, canvasScaler.referenceResolution.y);
} }
} }
} }
private void InputDect(){
if(Keyboard.current.downArrowKey.wasPressedThisFrame){
if(historyCommand.Count-1>historycount){
historycount++;
InputCommand.text=historyCommand[historycount];}
else {
InputCommand.text="";
historycount=historyCommand.Count;
}
//这是史,不要看
private void InputDect()
{
if (Keyboard.current.downArrowKey.wasPressedThisFrame)
{
if (historyCommand.Count - 1 > historycount)
{
historycount++;
InputCommand.text = historyCommand[historycount];
} }
if(Keyboard.current.upArrowKey.wasPressedThisFrame && historycount!=0){ else
historycount--; {
InputCommand.text=historyCommand[historycount]; InputCommand.text = "";
historycount = historyCommand.Count;
} }
}
if (Keyboard.current.upArrowKey.wasPressedThisFrame && historycount != 0)
{
historycount--;
InputCommand.text = historyCommand[historycount];
}
if (Keyboard.current.enterKey.wasPressedThisFrame)
{
string[] strings = InputCommand.text.Split(' ');
string ExpoCommand = "";
foreach (string i in strings)
{
if (!i.IsNullOrWhitespace())
{
if (ExpoCommand.IsNullOrWhitespace()) ExpoCommand = i + "(";
else ExpoCommand += i + ",";
}
}
ExpoCommand = ExpoCommand.RemoveExtraSpaces().Substring(0, ExpoCommand.Length - 1);
if (!ExpoCommand.Contains('(')) ExpoCommand += "(";
ExpoCommand += ")";
print(ExpoCommand);
GetCommand(ExpoCommand);
if (historyCommand.ContainsKey(historycount)) historyCommand[historycount] = InputCommand.text;
else historyCommand.Add(historycount, InputCommand.text);
historycount++;
InputCommand.text = "";
}
} }
private void Start() private void Start()
{ {
inspector = EditorManager.instance.uiManager.inspector;
hierarchy = EditorManager.instance.uiManager.hierarchy;
logWindow = EditorManager.instance.uiManager.mainPage.logWindow;
SetUpFunctions(); SetUpFunctions();
//Test //Test
// functionInterpreter.Eval("print(\"Hello World!\")"); // functionInterpreter.Eval("print(\"Hello World!\")");
// functionInterpreter.Eval("log(\"Hello World but debug!\")"); // functionInterpreter.Eval("log(\"Hello World but debug!\")");
} }
} }
public partial class EditorConsole public partial class EditorConsole
{ {
public Inspector inspector;
public Hierarchy hierarchy;
public LogWindow logWindow;
private void SetUpFunctions() private void SetUpFunctions()
{ {
functionInterpreter = new Interpreter(); functionInterpreter = new Interpreter();
functionInterpreter.SetFunction("test",(Action)Test); functionInterpreter.SetFunction("test", (Action)Test);
functionInterpreter.SetFunction("lgp", (Action<string,int>)LGenPathNodes);
functionInterpreter.SetFunction("Kill", (Action)Kill);
functionInterpreter.SetFunction("lgp", (Action<int, float, float, float, float, float, float>)LGenPathNodes);
functionInterpreter.SetFunction("print", (Action<object>)print); functionInterpreter.SetFunction("print", (Action<object>)print);
functionInterpreter.SetFunction("log", (Action<object>)Debug.Log); functionInterpreter.SetFunction("log", (Action<object>)Debug.Log);
} }
private void Kill()
{
if (inspector.connectedGameElement == null)
{
LogWindow.Log("Please select a GameElement first!");
return;
}
for (int i = inspector.connectedGameElement.childElementList.Count - 1; i <= 0; i--)
{
inspector.connectedGameElement.childElementList[i].Delete();
}
}
private void Test() private void Test()
{ {
//放入测试代码
var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List<string>(), true, null); 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 LGenPathNodes(string name,int loop){
Track track= (Track)Find(name);
for(int i=0;i<loop;i++){
var p=PathNode.GenerateElement("PathNodes", Guid.NewGuid(), new List<string>(), true,track);
}
private void LGenPathNodes(int loop, float xs, float xe, float ys, float ye, float zs, float ze)
{
if (inspector.connectedGameElement == null || inspector.connectedGameElement.GetType() != typeof(Track))
{
LogWindow.Log("Please select a Track first!");
return;
}
Track track = (Track)inspector.connectedGameElement;
for (int i = 0; i < loop; i++)
{
float x = xs + (xe - xs) / loop * i;
float y = ys + (ye - ys) / loop * i;
float z = zs + (ze - zs) / loop * i;
PathNode j = PathNode.GenerateElement("PathNode" + i.ToString(), Guid.NewGuid(), new List<string>(), true, track);
j.transformSubmodule.originalPosition = new Vector3(x, y, z);
}
} }
} }

26517
Document/console概要.rtf Normal file

File diff suppressed because it is too large Load Diff