Inspector-2
加入Text,以及一些必要注释
This commit is contained in:
@@ -1,15 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public abstract class DynamicUIElement : MonoBehaviour
|
||||
{
|
||||
public GameElement connectedGameElement => EditorManager.instance.uiManager.inspector.connectedGameElement;
|
||||
public bool isAlwaysUpdated;
|
||||
public abstract void Initialize(string parameterName);
|
||||
public TMP_Text title;
|
||||
protected GameElement connectedGameElement => EditorManager.instance.uiManager.inspector.connectedGameElement;
|
||||
|
||||
/// <summary>
|
||||
/// 参数名,通过反射获取饿修改对应变量的值
|
||||
/// </summary>
|
||||
public string parameterName;
|
||||
|
||||
/// <summary>
|
||||
/// 是否始终更新,如果子类可能用到此变量,则在子类中写Update即可
|
||||
/// </summary>
|
||||
public bool isAlwaysUpdated;
|
||||
|
||||
public virtual void Initialize(string title, string parameterName)
|
||||
{
|
||||
this.parameterName = parameterName;
|
||||
this.title.text = title;
|
||||
}
|
||||
|
||||
//public abstract void ApplyParameters();
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,13 @@ namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIInputField : DynamicUIElement
|
||||
{
|
||||
public string parameterName;
|
||||
public TMP_InputField inputField;
|
||||
|
||||
public override void Initialize(string parameterName)
|
||||
public override void Initialize(string title, string parameterName)
|
||||
{
|
||||
this.parameterName = parameterName;
|
||||
inputField.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString();
|
||||
inputField.onEndEdit.AddListener(ApplyParameters);
|
||||
base.Initialize(title, parameterName);
|
||||
inputField.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString(); //获取对应变量的值
|
||||
inputField.onEndEdit.AddListener(ApplyParameters); //输入结束后修改变量
|
||||
}
|
||||
|
||||
private void ApplyParameters(string text)
|
||||
|
||||
27
Assets/Scripts/DynamicUI/DynamicUIElements/DynamicUIText.cs
Normal file
27
Assets/Scripts/DynamicUI/DynamicUIElements/DynamicUIText.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIText : DynamicUIElement
|
||||
{
|
||||
public TMP_Text text;
|
||||
|
||||
public override void Initialize(string title, string parameterName)
|
||||
{
|
||||
base.Initialize(title, parameterName);
|
||||
text.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isAlwaysUpdated)
|
||||
{
|
||||
text.text = connectedGameElement.GetType().GetField(parameterName).GetValue(connectedGameElement).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd156b66e112a4120a775c14113c0738
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user