Vec3InputField 2
e 按·(esc下面那个)暂时关闭UI
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame;
|
||||
using JetBrains.Annotations;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements.Experimental;
|
||||
@@ -9,47 +11,58 @@ public class DynamicUIVec3InputField : DynamicUIElement
|
||||
public TMP_InputField inputFieldx;
|
||||
public TMP_InputField inputFieldy;
|
||||
public TMP_InputField inputFieldz;
|
||||
Transform objtransform;
|
||||
|
||||
|
||||
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);
|
||||
objtransform = connectedGameElement.transform;
|
||||
Vector3 pos = (Vector3)objtransform.GetType().GetProperty(parameterName).GetValue(objtransform);
|
||||
|
||||
Vector3 pos = (Vector3)e.GetType().GetField(parameterName).GetValue(e); //获取对应变量的值
|
||||
|
||||
|
||||
inputFieldx.text =pos.x.ToString();
|
||||
inputFieldx.onEndEdit.AddListener(ApplyParametersx);
|
||||
|
||||
inputFieldy.text =pos.y.ToString();
|
||||
inputFieldx.onEndEdit.AddListener(ApplyParametersy);
|
||||
|
||||
inputFieldz.text =pos.z.ToString();
|
||||
inputFieldx.onEndEdit.AddListener(ApplyParametersz);
|
||||
|
||||
}//我不应该用这种复制大法的(
|
||||
|
||||
private void ApplyParametersx(string text)
|
||||
public void ApplyParametersx(string text)
|
||||
{
|
||||
Vector3 newpos=totramsf(float.Parse(text),0);
|
||||
transform.GetType().GetProperty(parameterName).SetValue(objtransform,newpos);
|
||||
|
||||
Vector3 newpos=totramsf(text,0);
|
||||
e.GetType().GetField(parameterName).SetValue(e, newpos);
|
||||
|
||||
}
|
||||
private void ApplyParametersy(string text)
|
||||
public void ApplyParametersy(string text)
|
||||
{
|
||||
Vector3 newpos=totramsf(float.Parse(text),1);
|
||||
transform.GetType().GetProperty(parameterName).SetValue(objtransform,newpos);
|
||||
|
||||
Vector3 newpos=totramsf(text,1);
|
||||
e.GetType().GetField(parameterName).SetValue(e, newpos);
|
||||
}
|
||||
private void ApplyParametersz(string text)
|
||||
public void ApplyParametersz(string text)
|
||||
{
|
||||
Vector3 newpos=totramsf(float.Parse(text),2);
|
||||
transform.GetType().GetProperty(parameterName).SetValue(objtransform,newpos);
|
||||
|
||||
Vector3 newpos=totramsf(text,2);
|
||||
e.GetType().GetField(parameterName).SetValue(e, newpos);
|
||||
}
|
||||
|
||||
Vector3 totramsf(float value,int queue){
|
||||
Vector3 a= (Vector3)transform.GetType().GetProperty(parameterName).GetValue(connectedGameElement.transform);
|
||||
switch(queue){
|
||||
case 0:a.x=value;break;
|
||||
case 1:a.y=value;break;
|
||||
case 2:a.z=value;break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user