精调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 = "";
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dreamteck.Splines.Primitives;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
@@ -32,5 +35,63 @@ namespace Ichni.Editor
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Canvas[] scaleParts;
|
||||
|
||||
public GameObject HierarchyTopMark, InspectorTopMark, HierarchyBottomMark, InspectorBottomMark;
|
||||
|
||||
public GameObject HierarchyTopLocatedPoint, HierarchyBottomLocatedPoint,
|
||||
InspectorTopLocatedPoint, InspectorBottomLocatedPoint;
|
||||
public void Start()
|
||||
{
|
||||
UpdateUIScale();
|
||||
}
|
||||
public void UpdateUIScale()
|
||||
{
|
||||
Canvas.ForceUpdateCanvases();
|
||||
|
||||
|
||||
HierarchyTopLocatedPoint.transform.position = HierarchyTopMark.transform.position;
|
||||
HierarchyBottomLocatedPoint.transform.position = HierarchyBottomMark.transform.position;
|
||||
InspectorTopLocatedPoint.transform.position = InspectorTopMark.transform.position;
|
||||
InspectorBottomLocatedPoint.transform.position = InspectorBottomMark.transform.position;
|
||||
|
||||
hierarchy.GetComponent<RectTransform>().sizeDelta = new Vector2(hierarchy.GetComponent<RectTransform>().sizeDelta.x,
|
||||
HierarchyTopLocatedPoint.transform.localPosition.y - HierarchyBottomLocatedPoint.transform.localPosition.y);
|
||||
hierarchy.transform.localPosition = new Vector3(hierarchy.transform.localPosition.x, HierarchyTopLocatedPoint.transform.localPosition.y - (hierarchy.GetComponent<RectTransform>().sizeDelta.y / 2f), 0);
|
||||
hierarchy.addFolderButton.transform.position = new Vector3(hierarchy.addFolderButton.transform.position.x, HierarchyBottomLocatedPoint.transform.position.y, 0);
|
||||
|
||||
|
||||
|
||||
inspector.GetComponent<RectTransform>().sizeDelta = new Vector2(inspector.GetComponent<RectTransform>().sizeDelta.x,
|
||||
InspectorTopLocatedPoint.transform.localPosition.y - InspectorBottomLocatedPoint.transform.localPosition.y);
|
||||
inspector.transform.localPosition = new Vector3(inspector.transform.localPosition.x, (InspectorTopLocatedPoint.transform.localPosition.y - (inspector.GetComponent<RectTransform>().sizeDelta.y / 2f)) / inspector.GetComponent<RectTransform>().localScale.y, 0);
|
||||
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
UpdateUIScale();
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
UpdateUIScale();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,9 @@ public class DoubleCheckButton : MonoBehaviour, IPointerExitHandler
|
||||
private bool isConfirmState = false;
|
||||
public UnityAction onConfirm;
|
||||
|
||||
public Color ComfirmColor;
|
||||
public Color DefaultColor;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
button = GetComponent<Button>();
|
||||
@@ -21,7 +24,7 @@ public class DoubleCheckButton : MonoBehaviour, IPointerExitHandler
|
||||
{
|
||||
// 第一次点击,进入确认状态(变红)
|
||||
isConfirmState = true;
|
||||
button.image.color = Color.red;
|
||||
button.image.color = ComfirmColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -45,7 +48,7 @@ public class DoubleCheckButton : MonoBehaviour, IPointerExitHandler
|
||||
private void ResetButtonState()
|
||||
{
|
||||
isConfirmState = false;
|
||||
button.image.color = Color.white;
|
||||
button.image.color = DefaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user