至尊AI之力👊👊👊👊至尊AI之力👊👊👊👊
This commit is contained in:
32711
Assets/FR2_Cache.asset
32711
Assets/FR2_Cache.asset
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,23 +1,16 @@
|
||||
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;
|
||||
using UnityEngine.InputSystem;
|
||||
using TMPro;
|
||||
using MoreMountains.Tools;
|
||||
using System.Reflection;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Sirenix.Utilities;
|
||||
|
||||
//又在写大粪 ——神币
|
||||
namespace Ichni.Editor
|
||||
@@ -29,12 +22,61 @@ namespace Ichni.Editor
|
||||
private Dictionary<int, string> historyCommand = new Dictionary<int, string>();
|
||||
private int historycount = 0;
|
||||
public GameObject ConsoleUI;
|
||||
|
||||
public TMP_Text cueText;
|
||||
bool isHide = true;
|
||||
|
||||
public void GetChange(string change)
|
||||
{
|
||||
// Task t = new Task(() =>
|
||||
// {
|
||||
// 1. 提取命令名
|
||||
string trimmed = change.Trim();
|
||||
if (string.IsNullOrEmpty(trimmed))
|
||||
{
|
||||
cueText.text = "";
|
||||
return;
|
||||
}
|
||||
// 支持 func(...) 或 func abc 123
|
||||
var match = Regex.Match(trimmed, @"^(\w+)");
|
||||
if (!match.Success)
|
||||
{
|
||||
cueText.text = "";
|
||||
return;
|
||||
}
|
||||
string funcName = match.Groups[1].Value;
|
||||
|
||||
// 2. 查找方法
|
||||
List<MethodInfo> methods = typeof(EditorConsoleMethods).GetMethods()
|
||||
.Where(m => m.IsStatic && m.IsPublic && m.ReturnType == typeof(void) && m.Name.Contains(funcName)).ToList();
|
||||
cueText.text = "";
|
||||
foreach (MethodInfo method in methods)
|
||||
{
|
||||
if (method == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string methodName = method.Name;
|
||||
// 3. 获取参数信息
|
||||
var parameters = method.GetParameters();
|
||||
if (parameters.Length == 0)
|
||||
{
|
||||
cueText.text += $"{methodName} " + "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// 4. 生成参数提示
|
||||
string paramHint = string.Join(" ", parameters.Select(p =>
|
||||
p.IsOptional ? $"[{p.ParameterType.Name}:{p.Name}]" : $"{p.ParameterType.Name}:{p.Name}"
|
||||
));
|
||||
cueText.text += $"{methodName} {paramHint}".Trim() + "\n";
|
||||
}
|
||||
if (cueText.text.IsNullOrWhitespace())
|
||||
{
|
||||
cueText.text = "No matching commands found.";
|
||||
}
|
||||
// });
|
||||
|
||||
// t.RunSynchronously();
|
||||
}
|
||||
public void GetCommand(string Command)//当提交命令时
|
||||
{
|
||||
@@ -104,19 +146,8 @@ namespace Ichni.Editor
|
||||
InputCommand.text = "";
|
||||
return;
|
||||
}
|
||||
string ExpoCommand = TransformCommand(input);
|
||||
|
||||
// 处理命令格式
|
||||
// 使用正则表达式将首个单词作为函数名,后续以逗号分隔参数
|
||||
var match = Regex.Match(input.Trim(), @"^(\w+)\s*(.*)$");
|
||||
string ExpoCommand = input;
|
||||
if (match.Success)
|
||||
{
|
||||
string func = match.Groups[1].Value;
|
||||
string args = match.Groups[2].Value.Trim();
|
||||
// 用正则将所有空白分隔的参数替换为逗号
|
||||
args = Regex.Replace(args, @"\s+", ",");
|
||||
ExpoCommand = string.IsNullOrEmpty(args) ? $"{func}()" : $"{func}({args})";
|
||||
}
|
||||
|
||||
print(ExpoCommand);
|
||||
GetCommand(ExpoCommand);
|
||||
@@ -131,7 +162,75 @@ namespace Ichni.Editor
|
||||
InputCommand.text = "";
|
||||
}
|
||||
}
|
||||
private string TransformCommand(string input)
|
||||
{
|
||||
// 处理命令格式,适配 DynamicExpresso
|
||||
string trimmed = input.Trim();
|
||||
|
||||
// 1. 直接支持 func(...) 形式
|
||||
if (Regex.IsMatch(trimmed, @"^\w+\s*\(.*\)$"))
|
||||
return trimmed;
|
||||
|
||||
// 2. 直接支持赋值表达式
|
||||
if (trimmed.Contains("="))
|
||||
return trimmed;
|
||||
|
||||
// 3. 支持 func abc 123 [1,2,3] 形式
|
||||
var match = Regex.Match(trimmed, @"^(\w+)\s*(.*)$");
|
||||
if (match.Success)
|
||||
{
|
||||
string func = match.Groups[1].Value;
|
||||
string args = match.Groups[2].Value.Trim();
|
||||
|
||||
// 匹配参数:中括号、引号、或连续非空白
|
||||
var argMatches = Regex.Matches(args, @"(\[[^\]]+\]|""(?:[^""\\]|\\.)*""|\S+)");
|
||||
var argList = argMatches.Cast<Match>().Select(m => m.Value).ToList();
|
||||
|
||||
List<string> processedArgs = new List<string>();
|
||||
foreach (var arg in argList)
|
||||
{
|
||||
string a = arg.Trim();
|
||||
|
||||
// Vector2/3: [1,2] 或 [1,2,3]
|
||||
if (Regex.IsMatch(a, @"^\[\s*-?\d+(\.\d+)?\s*,\s*-?\d+(\.\d+)?(\s*,\s*-?\d+(\.\d+)?)*\s*\]$"))
|
||||
{
|
||||
// 去除中括号和空格
|
||||
string content = a.Substring(1, a.Length - 2).Trim();
|
||||
var nums = content.Split(',').Select(s => s.Trim()).ToArray();
|
||||
if (nums.Length == 2)
|
||||
processedArgs.Add($"new Vector2({nums[0]},{nums[1]})");
|
||||
else if (nums.Length == 3)
|
||||
processedArgs.Add($"new Vector3({nums[0]},{nums[1]},{nums[2]})");
|
||||
else
|
||||
processedArgs.Add(a); // 不是2或3维,原样返回
|
||||
}
|
||||
// 已有引号的字符串
|
||||
else if (a.StartsWith("\"") && a.EndsWith("\""))
|
||||
{
|
||||
processedArgs.Add(a);
|
||||
}
|
||||
// 数字
|
||||
else if (Regex.IsMatch(a, @"^-?\d+(\.\d+)?$"))
|
||||
{
|
||||
processedArgs.Add(a);
|
||||
}
|
||||
// 变量名(字母开头,允许字母数字下划线)
|
||||
else if (Regex.IsMatch(a, @"^[a-zA-Z_]\w*$"))
|
||||
{
|
||||
processedArgs.Add(a);
|
||||
}
|
||||
// 其它未加引号的参数,自动加引号
|
||||
else
|
||||
{
|
||||
processedArgs.Add($"\"{a}\"");
|
||||
}
|
||||
}
|
||||
|
||||
string joinedArgs = string.Join(",", processedArgs);
|
||||
return string.IsNullOrEmpty(joinedArgs) ? $"{func}()" : $"{func}({joinedArgs})";
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
|
||||
@@ -152,7 +251,9 @@ namespace Ichni.Editor
|
||||
public List<string> commandList = new List<string>();
|
||||
public void SetUpFunctions()
|
||||
{
|
||||
functionInterpreter = new Interpreter();//这是AI给的东西?
|
||||
functionInterpreter = new Interpreter()
|
||||
.Reference(typeof(Vector3))
|
||||
.Reference(typeof(Vector2));//这是AI给的东西?
|
||||
foreach (MethodInfo i in typeof(EditorConsoleMethods).GetMethods().
|
||||
ToList().Where(i => i.IsStatic && i.IsPublic && i.ReturnType == typeof(void)))
|
||||
{
|
||||
@@ -199,17 +300,23 @@ namespace Ichni.Editor
|
||||
public static void test()
|
||||
{
|
||||
|
||||
var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List<string>(), true, null);
|
||||
}
|
||||
public static void test2()
|
||||
{
|
||||
|
||||
public static void tp(float x, float y, float z)
|
||||
}
|
||||
public static void tttttt()
|
||||
{
|
||||
|
||||
}
|
||||
public static void tp(Vector3 pos)
|
||||
{
|
||||
if (EditorManager.instance.cameraManager.isSceneCameraActive)
|
||||
{
|
||||
EditorManager.instance.cameraManager.sceneCamera.sceneCamera.transform.position =
|
||||
new Vector3(x, y, z);
|
||||
EditorManager.instance.cameraManager.sceneCamera.sceneCamera.transform.position = pos;
|
||||
}
|
||||
}
|
||||
// 保留无参tp
|
||||
public static void tp()
|
||||
{
|
||||
if (EditorManager.instance.cameraManager.isSceneCameraActive)
|
||||
@@ -222,7 +329,7 @@ namespace Ichni.Editor
|
||||
|
||||
|
||||
|
||||
public static void lgp(int loop, float xs, float xe, float ys, float ye, float zs, float ze)
|
||||
public static void lgp(int loop, Vector3 start, Vector3 end)
|
||||
{
|
||||
if (inspector.connectedGameElement == null || inspector.connectedGameElement.GetType() != typeof(Track))
|
||||
{
|
||||
@@ -232,13 +339,88 @@ namespace Ichni.Editor
|
||||
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;
|
||||
float t = (float)i / loop;
|
||||
float x = start.x + (end.x - start.x) * t;
|
||||
float y = start.y + (end.y - start.y) * t;
|
||||
float z = start.z + (end.z - start.z) * t;
|
||||
PathNode j = PathNode.GenerateElement("PathNode" + i.ToString(), Guid.NewGuid(), new List<string>(), true, track, true);
|
||||
j.transformSubmodule.originalPosition = new Vector3(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 支持主轴方向的螺旋线式 PathNode
|
||||
public static void spiral(int loop, Vector3 center, float r, float h, int pointsPerTurn, string axis = "y")
|
||||
{
|
||||
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 t = (float)i / loop;
|
||||
float angle = 2 * Mathf.PI * (i % pointsPerTurn) / pointsPerTurn;
|
||||
Vector3 pos = new Vector3(center.x, center.y, center.z);
|
||||
|
||||
switch (axis.ToLower())
|
||||
{
|
||||
case "x":
|
||||
pos.x += h * t;
|
||||
pos.y += r * Mathf.Cos(angle);
|
||||
pos.z += r * Mathf.Sin(angle);
|
||||
break;
|
||||
case "y":
|
||||
pos.x += r * Mathf.Cos(angle);
|
||||
pos.y += h * t;
|
||||
pos.z += r * Mathf.Sin(angle);
|
||||
break;
|
||||
case "z":
|
||||
pos.x += r * Mathf.Cos(angle);
|
||||
pos.y += r * Mathf.Sin(angle);
|
||||
pos.z += h * t;
|
||||
break;
|
||||
default:
|
||||
pos.x += r * Mathf.Cos(angle);
|
||||
pos.y += h * t;
|
||||
pos.z += r * Mathf.Sin(angle);
|
||||
break;
|
||||
}
|
||||
|
||||
PathNode node = PathNode.GenerateElement("SpiralNode" + i.ToString(), Guid.NewGuid(), new List<string>(), true, track, true);
|
||||
node.transformSubmodule.originalPosition = pos;
|
||||
}
|
||||
}
|
||||
|
||||
// 任意方向的螺旋线式 PathNode(中心点和方向均为Vector3)
|
||||
public static void spiral(int loop, Vector3 center, float r, float h, int pointsPerTurn, Vector3 dir)
|
||||
{
|
||||
if (inspector.connectedGameElement == null || inspector.connectedGameElement.GetType() != typeof(Track))
|
||||
{
|
||||
LogWindow.Log("Please select a Track first!");
|
||||
return;
|
||||
}
|
||||
Vector3 direction = dir.normalized;
|
||||
if (direction == Vector3.zero) direction = Vector3.up; // 默认Y轴
|
||||
|
||||
Quaternion rot = Quaternion.FromToRotation(Vector3.up, direction);
|
||||
|
||||
Track track = (Track)inspector.connectedGameElement;
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
float t = (float)i / loop;
|
||||
float angle = 2 * Mathf.PI * (i % pointsPerTurn) / pointsPerTurn;
|
||||
Vector3 localPos = new Vector3(
|
||||
r * Mathf.Cos(angle),
|
||||
h * t,
|
||||
r * Mathf.Sin(angle)
|
||||
);
|
||||
Vector3 pos = center + rot * localPos;
|
||||
|
||||
PathNode node = PathNode.GenerateElement("SpiralNode" + i.ToString(), Guid.NewGuid(), new List<string>(), true, track, true);
|
||||
node.transformSubmodule.originalPosition = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user