prev XRISEditor main
This commit is contained in:
57
Assets/Scripts/XED/UI/UI_PropertyViewerInfo.cs
Normal file
57
Assets/Scripts/XED/UI/UI_PropertyViewerInfo.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Reflection;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using WI.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user