Files
Studio/Assets/Scripts/XED/UI/Elements/UI_PropertyViewerInfo.cs
2025-02-24 09:26:27 +09:00

58 lines
1.3 KiB
C#

using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using XRLib.UI;
namespace XED.UI
{
public class UI_PropertyViewerInfo : UIBase
{
RectTransform rect;
TextMeshProUGUI Text_Name;
TextMeshProUGUI Text_Value;
float originHeight;
public FieldInfo fieldInfo;
public override void AfterAwake()
{
rect = GetComponent<RectTransform>();
originHeight = rect.sizeDelta.y;
}
public void Activate(FieldInfo info, TwinObject selectedTwinObject)
{
object value = info.GetValue(selectedTwinObject);
Text_Name.text = ToUpperFirstLetter(info.Name);
Text_Value.text = value.ToString();
SetSize();
fieldInfo = info;
}
void SetSize()
{
float height = originHeight;
float textHeight = Text_Value.preferredHeight;
if (textHeight > height)
{
height = textHeight;
}
rect.sizeDelta = new Vector2(rect.sizeDelta.x, height);
}
string ToUpperFirstLetter(string input)
{
if (string.IsNullOrEmpty(input))
return input;
return char.ToUpper(input[0]) + input.Substring(1);
}
}
}