Vector3 inputfield 改进

This commit is contained in:
SoulliesOfficial
2025-02-12 18:46:46 -05:00
parent 3a1ee5f9ef
commit 8d03acc3cb
30 changed files with 1781 additions and 239 deletions

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
namespace Ichni.Editor
{
public class DynamicUIDropdown : DynamicUIElement
{
public TMP_Dropdown dropdown;
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
{
base.Initialize(baseElement, title, parameterName);
dropdown.value = (int)connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement); //获取对应变量的值
dropdown.onValueChanged.AddListener(ApplyParameters);
}
public void SetUpEnum(Type enumType)
{
dropdown.options.Clear();
List<string> enumNameList = System.Enum.GetNames(enumType).ToList();
dropdown.AddOptions(enumNameList);
}
private void ApplyParameters(int value)
{
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, value);
connectedBaseElement.Refresh();
}
}
}

View File

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

View File

@@ -9,7 +9,7 @@ namespace Ichni.Editor
public abstract class DynamicUIElement : MonoBehaviour
{
public TMP_Text title;
protected GameElement connectedGameElement => EditorManager.instance.uiManager.inspector.connectedGameElement;
public IBaseElement connectedBaseElement;
/// <summary>
/// 参数名,通过反射获取饿修改对应变量的值
@@ -21,8 +21,9 @@ namespace Ichni.Editor
/// </summary>
public bool isAlwaysUpdated;
public virtual void Initialize(string title, string parameterName)
public virtual void Initialize(IBaseElement baseElement, string title, string parameterName)
{
this.connectedBaseElement = baseElement;
this.parameterName = parameterName;
this.title.text = title;
}

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
@@ -9,17 +10,18 @@ namespace Ichni.Editor
{
public TMP_InputField inputField;
public override void Initialize(string title, string parameterName)
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
{
base.Initialize(title, parameterName);
inputField.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString(); //获取对应变量的值
base.Initialize(baseElement, title, parameterName);
inputField.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString(); //获取对应变量的值
inputField.onEndEdit.AddListener(ApplyParameters); //输入结束后修改变量
inputField.onEndEdit.AddListener(ApplyParameters);
}
private void ApplyParameters(string text)
{
connectedGameElement.GetType().GetField(parameterName).SetValue(connectedGameElement, text);
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, text);
connectedBaseElement.Refresh();
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
@@ -10,17 +11,17 @@ namespace Ichni.Editor
{
public TMP_Text text;
public override void Initialize(string title, string parameterName)
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
{
base.Initialize(title, parameterName);
text.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString();
base.Initialize(baseElement, title, parameterName);
text.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString();
}
private void Update()
{
if (isAlwaysUpdated)
{
text.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString();
text.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString();
}
}
}

View File

@@ -1,71 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using JetBrains.Annotations;
using TMPro;
using UnityEngine;
using UnityEngine.UIElements.Experimental;
namespace Ichni.Editor{
public class DynamicUIVec3InputField : DynamicUIElement
{
public TMP_InputField inputFieldx;
public TMP_InputField inputFieldy;
public TMP_InputField inputFieldz;
public TransformSubmodule e=null;
public override void Initialize(string title, string parameterName)
{
foreach(var i in connectedGameElement.submoduleList){
if(i.GetType()==typeof(TransformSubmodule)){
e= (TransformSubmodule)i;
break;
}
}
if (e == null)Destroy(gameObject);
base.Initialize(title, parameterName);
Vector3 pos = (Vector3)e.GetType().GetField(parameterName).GetValue(e); //获取对应变量的值
inputFieldx.text =pos.x.ToString();
inputFieldy.text =pos.y.ToString();
inputFieldz.text =pos.z.ToString();
}//我不应该用这种复制大法的(
public void ApplyParametersx(string text)
{
Vector3 newpos=totramsf(text,0);
e.GetType().GetField(parameterName).SetValue(e, newpos);
}
public void ApplyParametersy(string text)
{
Vector3 newpos=totramsf(text,1);
e.GetType().GetField(parameterName).SetValue(e, newpos);
}
public void ApplyParametersz(string text)
{
Vector3 newpos=totramsf(text,2);
e.GetType().GetField(parameterName).SetValue(e, newpos);
}
Vector3 totramsf(string value,int queue){
float avalue;
if(!float.TryParse(value,out avalue)){
avalue=0f;
}
Vector3 a= (Vector3)e.GetType().GetField(parameterName).GetValue(e); //获取对应变量的值
a[queue]=avalue;
return a;
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using JetBrains.Annotations;
using TMPro;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements.Experimental;
namespace Ichni.Editor
{
public class DynamicUIVector3InputField : DynamicUIElement
{
public TMP_InputField inputFieldX;
public TMP_InputField inputFieldY;
public TMP_InputField inputFieldZ;
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
{
base.Initialize(baseElement, title, parameterName);
Vector3 pos = (Vector3)connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement); //获取对应变量的值
inputFieldX.text = pos.x.ToString();
inputFieldY.text = pos.y.ToString();
inputFieldZ.text = pos.z.ToString();
inputFieldX.onEndEdit.AddListener(_ => ApplyParameters());
inputFieldY.onEndEdit.AddListener(_ => ApplyParameters());
inputFieldZ.onEndEdit.AddListener(_ => ApplyParameters());
}
public void ApplyParameters()
{
Vector3 newValue = new Vector3(float.Parse(inputFieldX.text), float.Parse(inputFieldY.text), float.Parse(inputFieldZ.text));
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, newValue);
connectedBaseElement.Refresh();
}
}
}