添加Vec3InputField和其预制件
代码要改,还没写好,而且我不知道为什么在inputField那里的方法不管用,transform的GetFields()都是空的
This commit is contained in:
@@ -3,13 +3,19 @@ using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIContainer : MonoBehaviour
|
||||
{
|
||||
public TMP_Text title;
|
||||
public GridLayoutGroup gridLayoutGroup;
|
||||
public List<DynamicUIElement> dynamicUIElements = new List<DynamicUIElement>();
|
||||
[FormerlySerializedAs("container")] public RectTransform rect;
|
||||
|
||||
public void setVoH(bool VoH){
|
||||
if(VoH)gridLayoutGroup.cellSize=new Vector2(250,100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace Ichni.Editor
|
||||
{
|
||||
base.Initialize(title, parameterName);
|
||||
inputField.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString(); //获取对应变量的值
|
||||
|
||||
inputField.onEndEdit.AddListener(ApplyParameters); //输入结束后修改变量
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
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;
|
||||
Transform objtransform;
|
||||
|
||||
public override void Initialize(string title, string parameterName)
|
||||
{
|
||||
base.Initialize(title, parameterName);
|
||||
objtransform = connectedGameElement.transform;
|
||||
Vector3 pos = (Vector3)objtransform.GetType().GetProperty(parameterName).GetValue(objtransform);
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
Vector3 newpos=totramsf(float.Parse(text),0);
|
||||
transform.GetType().GetProperty(parameterName).SetValue(objtransform,newpos);
|
||||
|
||||
}
|
||||
private void ApplyParametersy(string text)
|
||||
{
|
||||
Vector3 newpos=totramsf(float.Parse(text),1);
|
||||
transform.GetType().GetProperty(parameterName).SetValue(objtransform,newpos);
|
||||
}
|
||||
private void ApplyParametersz(string text)
|
||||
{
|
||||
Vector3 newpos=totramsf(float.Parse(text),2);
|
||||
transform.GetType().GetProperty(parameterName).SetValue(objtransform,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;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8372da2ad7a105d4aa3904e8b3fdfd71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Ichni.RhythmGame;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -49,6 +50,14 @@ namespace Ichni.Editor
|
||||
container.dynamicUIElements.Add(inputField);
|
||||
return inputField;
|
||||
}
|
||||
public DynamicUIVec3InputField GenerateVec3InputField(DynamicUIContainer container, string title, string parameterName){
|
||||
DynamicUIVec3InputField a=Instantiate(EditorManager.instance.basePrefabs.Vec3inputField,container.rect).GetComponent<DynamicUIVec3InputField>();
|
||||
a.Initialize(title, parameterName);
|
||||
container.dynamicUIElements.Add(a);
|
||||
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
public DynamicUIText GenerateText(DynamicUIContainer container, string title, string parameterName, bool isAlwaysUpdate = false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user