精调UI(存疑)
This commit is contained in:
@@ -24,7 +24,6 @@ namespace Ichni.Editor
|
||||
{
|
||||
public partial class EditorConsole : MonoBehaviour
|
||||
{
|
||||
public Canvas[] scaleParts;
|
||||
public Interpreter functionInterpreter;
|
||||
public TMP_InputField InputCommand;
|
||||
private Dictionary<int, string> historyCommand = new Dictionary<int, string>();
|
||||
@@ -39,11 +38,6 @@ namespace Ichni.Editor
|
||||
}
|
||||
public void GetCommand(string Command)//当提交命令时
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
functionInterpreter.Eval(Command);
|
||||
@@ -56,11 +50,8 @@ namespace Ichni.Editor
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
|
||||
UIscale();
|
||||
if (InputCommand.isFocused) InputDect();
|
||||
|
||||
|
||||
}
|
||||
private void UIscale()
|
||||
{
|
||||
@@ -72,24 +63,7 @@ namespace Ichni.Editor
|
||||
isHide = !isHide;
|
||||
if (!isHide) StartCoroutine(WindowAnim.ShowPanelOnScale(InputCommand.gameObject));
|
||||
}
|
||||
if (Keyboard.current.leftCtrlKey.isPressed && Keyboard.current.upArrowKey.wasPressedThisFrame)
|
||||
{
|
||||
foreach (Canvas i in scaleParts)
|
||||
{
|
||||
var canvasScaler = i.GetComponent<CanvasScaler>();
|
||||
canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x + 100, canvasScaler.referenceResolution.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (Keyboard.current.leftCtrlKey.isPressed && Keyboard.current.downArrowKey.wasPressedThisFrame)
|
||||
{
|
||||
foreach (Canvas i in scaleParts)
|
||||
{
|
||||
var canvasScaler = i.GetComponent<CanvasScaler>();
|
||||
canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x - 100, canvasScaler.referenceResolution.y);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +71,7 @@ namespace Ichni.Editor
|
||||
//这是史,不要看
|
||||
private void InputDect()
|
||||
{
|
||||
// 向下翻历史命令
|
||||
if (Keyboard.current.downArrowKey.wasPressedThisFrame)
|
||||
{
|
||||
if (historyCommand.Count - 1 > historycount)
|
||||
@@ -109,32 +84,49 @@ namespace Ichni.Editor
|
||||
InputCommand.text = "";
|
||||
historycount = historyCommand.Count;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 向上翻历史命令
|
||||
if (Keyboard.current.upArrowKey.wasPressedThisFrame && historycount != 0)
|
||||
{
|
||||
historycount--;
|
||||
InputCommand.text = historyCommand[historycount];
|
||||
return;
|
||||
}
|
||||
|
||||
// 提交命令
|
||||
if (Keyboard.current.enterKey.wasPressedThisFrame)
|
||||
{
|
||||
string[] strings = InputCommand.text.Split(' ');
|
||||
string ExpoCommand = "";
|
||||
foreach (string i in strings)
|
||||
string input = InputCommand.text;
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
if (!i.IsNullOrWhitespace())
|
||||
{
|
||||
if (ExpoCommand.IsNullOrWhitespace()) ExpoCommand = i + "(";
|
||||
else ExpoCommand += i + ",";
|
||||
}
|
||||
InputCommand.text = "";
|
||||
return;
|
||||
}
|
||||
ExpoCommand = ExpoCommand.RemoveExtraSpaces().Substring(0, ExpoCommand.Length - 1);
|
||||
if (!ExpoCommand.Contains('(')) ExpoCommand += "(";
|
||||
ExpoCommand += ")";
|
||||
|
||||
// 处理命令格式
|
||||
// 使用正则表达式将首个单词作为函数名,后续以逗号分隔参数
|
||||
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);
|
||||
if (historyCommand.ContainsKey(historycount)) historyCommand[historycount] = InputCommand.text;
|
||||
else historyCommand.Add(historycount, InputCommand.text);
|
||||
|
||||
// 记录历史命令
|
||||
if (historyCommand.ContainsKey(historycount))
|
||||
historyCommand[historycount] = input;
|
||||
else
|
||||
historyCommand.Add(historycount, input);
|
||||
|
||||
historycount++;
|
||||
InputCommand.text = "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user