This commit is contained in:
SoulliesOfficial
2025-07-15 05:00:31 -04:00
parent d2e981b826
commit 4708da8318
12 changed files with 1613 additions and 107 deletions

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace Ichni.Editor
{
public class DynamicUIVector2InputField : DynamicUIElement, IHaveAutoUpdate
{
public TMP_InputField inputFieldX;
public TMP_InputField inputFieldY;
public bool isAutoUpdate { get; set; }
public bool isReceiving { get; set; }
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
{
base.Initialize(baseElement, title, parameterName);
if (parameterName != string.Empty)
{
ApplyContent();
inputFieldX.onEndEdit.AddListener(_ => ApplyParameters());
inputFieldY.onEndEdit.AddListener(_ => ApplyParameters());
}
}
private void Update()
{
(this as IHaveAutoUpdate).UpdateContent();
// 检测鼠标是否在 inputFieldX、inputFieldY 或 inputFieldZ 上
var selectedGameObject = EventSystem.current.currentSelectedGameObject;
bool[] isMouseOverText = new[]
{
selectedGameObject==inputFieldX.gameObject,
selectedGameObject==inputFieldY.gameObject,
};
if (Mouse.current.scroll.ReadValue().y != 0) // 检测鼠标滚轮
{
float scrollDelta = Mouse.current.scroll.ReadValue().y > 0 ? 0.1f : -0.1f; // 根据滚轮方向设置增量
if (isMouseOverText[0]) // 鼠标在 inputFieldX 上
{
float currentValue = float.Parse(inputFieldX.text);
inputFieldX.text = (currentValue + scrollDelta).ToString();
ApplyParameters();
}
else if (isMouseOverText[1]) // 鼠标在 inputFieldY 上
{
float currentValue = float.Parse(inputFieldY.text);
inputFieldY.text = (currentValue + scrollDelta).ToString();
ApplyParameters();
}
}
}
public void SetDefaultValue(Vector2 value)
{
inputFieldX.text = value.x.ToString();
inputFieldY.text = value.y.ToString();
}
public Vector2 GetValue()
{
return new Vector2(float.Parse(inputFieldX.text), float.Parse(inputFieldY.text));
}
public void SetAutoUpdate(bool enable)
{
isAutoUpdate = enable;
isReceiving = true;
inputFieldX.onSelect.AddListener(_ => isReceiving = false);
inputFieldY.onSelect.AddListener(_ => isReceiving = false);
inputFieldX.onDeselect.AddListener(_ => isReceiving = true);
inputFieldY.onDeselect.AddListener(_ => isReceiving = true);
}
public void ApplyContent()
{
Vector2 pos = (Vector2)connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement); //获取对应变量的值
inputFieldX.text = pos.x.ToString();
inputFieldY.text = pos.y.ToString();
}
private void ApplyParameters()
{
Vector2 newValue = new Vector2(float.Parse(inputFieldX.text), float.Parse(inputFieldY.text));
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, newValue);
connectedBaseElement.Refresh();
}
public override DynamicUIElement AddListenerFunction(UnityAction action)
{
inputFieldX.onEndEdit.AddListener(_ => action());
inputFieldY.onEndEdit.AddListener(_ => action());
return this;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0fa96ed23c470e439b349bc8e29ae6d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -8,8 +8,6 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.Serialization;
using UnityEngine.UIElements.Experimental;
namespace Ichni.Editor
{

View File

@@ -130,6 +130,18 @@ namespace Ichni.Editor
subcontainer.dynamicUIElements.Add(vector3InputField);
return vector3InputField;
}
public DynamicUIVector2InputField GenerateVector2InputField(IBaseElement baseElement,
DynamicUISubcontainer subcontainer, string title, string parameterName, bool isAutoUpdate = false)
{
DynamicUIVector2InputField vector2InputField =
Object.Instantiate(EditorManager.instance.basePrefabs.vector2InputField, subcontainer.rect)
.GetComponent<DynamicUIVector2InputField>();
vector2InputField.Initialize(baseElement, title, parameterName);
vector2InputField.SetAutoUpdate(isAutoUpdate);
subcontainer.dynamicUIElements.Add(vector2InputField);
return vector2InputField;
}
public DynamicUIBaseColorPicker GenerateBaseColorPicker(IBaseElement baseElement, DynamicUISubcontainer subcontainer,
string title, string parameterName)