90 lines
2.3 KiB
C#
90 lines
2.3 KiB
C#
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using XRLib;
|
|
using XRLib.UI;
|
|
using XED.UI;
|
|
using XED.Attributes;
|
|
using TMPro;
|
|
|
|
namespace XED.UI
|
|
{
|
|
public class Panel_PropertyViewer : PanelBase
|
|
{
|
|
Button Button_Close;
|
|
TextMeshProUGUI Text_ObjectName;
|
|
VerticalLayoutGroup Content;
|
|
|
|
UI_PropertyViewerInfo infoPrefab;
|
|
TwinObject selectedObject;
|
|
|
|
Dictionary<UI_PropertyViewerInfo, FieldInfo> infos = new();
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
Button_Close.onClick.AddListener(Deactivate);
|
|
|
|
infoPrefab = Resources.Load<UI_PropertyViewerInfo>("Prefabs/UI/PRF_PropertyViewerInfo");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UpdateData();
|
|
}
|
|
|
|
public void Activate(RaycastHit hit, Component component)
|
|
{
|
|
selectedObject = hit.collider.GetComponent<TwinObject>();
|
|
|
|
if (selectedObject == null)
|
|
return;
|
|
|
|
Text_ObjectName.text = selectedObject.gameObject.name + " (" + selectedObject.GetType().Name + ")";
|
|
|
|
CreateInfos();
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public void Deactivate()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
void CreateInfos()
|
|
{
|
|
var type = selectedObject.GetType();
|
|
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
|
|
|
|
foreach (UI_PropertyViewerInfo info in infos.Keys)
|
|
{
|
|
Destroy(info.gameObject);
|
|
}
|
|
infos.Clear();
|
|
|
|
foreach (FieldInfo field in fields)
|
|
{
|
|
PropertyVisibleAttribute attr = field.GetCustomAttribute<PropertyVisibleAttribute>();
|
|
|
|
if (attr == null || !attr.IsVisible)
|
|
continue;
|
|
|
|
var info = Instantiate(infoPrefab, Content.transform);
|
|
infos.Add(info,field);
|
|
info.Activate(field, selectedObject);
|
|
}
|
|
}
|
|
|
|
void UpdateData()
|
|
{
|
|
foreach (UI_PropertyViewerInfo info in infos.Keys)
|
|
{
|
|
info.Activate(infos[info], selectedObject);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|