95 lines
2.4 KiB
C#
95 lines
2.4 KiB
C#
using Studio.Dynamic.TwinObject;
|
|
using Studio.Dynamic.M;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using XRLib.UI;
|
|
using System.Linq;
|
|
using Studio.Core;
|
|
|
|
namespace Studio.UI
|
|
{
|
|
public class Panel_AGV : PanelBase
|
|
{
|
|
public GameObject itemPrefab;
|
|
public RectTransform Content;
|
|
private Dictionary<string, TMP_Text> textDict = new();
|
|
private bool itemInit;
|
|
private string targetId = string.Empty;
|
|
|
|
private AGV prevAgv;
|
|
public override void AfterAwake()
|
|
{
|
|
itemPrefab = Resources.Load<GameObject>("Prefabs/UI/PRF_EntityItem");
|
|
}
|
|
|
|
internal void OnUpdateData(Dictionary<string, string> entity)
|
|
{
|
|
if (!itemInit)
|
|
{
|
|
InstantiateUI(entity);
|
|
itemInit = true;
|
|
}
|
|
else
|
|
{
|
|
UpdateUI(entity);
|
|
}
|
|
}
|
|
|
|
internal void SetTarget(List<GameObject> selectedObjects)
|
|
{
|
|
if (selectedObjects.Count == 0)
|
|
return;
|
|
|
|
GameObject selectedObject = selectedObjects[0];
|
|
if (prevAgv != null)
|
|
{
|
|
prevAgv.onDataUpdate -= InstantiateUI;
|
|
prevAgv = null;
|
|
}
|
|
|
|
if (selectedObject.TryGetComponent<AGV>(out AGV agv))
|
|
{
|
|
var dic = agv.Info;
|
|
SetActive(true);
|
|
prevAgv = agv;
|
|
OnUpdateData(dic);
|
|
agv.onDataUpdate += OnUpdateData;
|
|
}
|
|
else
|
|
{
|
|
SetActive(false);
|
|
}
|
|
}
|
|
|
|
void InstantiateUI(Dictionary<string, string> entity)
|
|
{
|
|
foreach (var kvp in entity)
|
|
{
|
|
GameObject item = Instantiate(itemPrefab, Content);
|
|
|
|
var texts = item.GetComponentsInChildren<TMP_Text>();
|
|
|
|
TMP_Text keyText = texts[0];
|
|
TMP_Text valueText = texts[1];
|
|
|
|
keyText.text = kvp.Key;
|
|
valueText.text = kvp.Value;
|
|
|
|
textDict[kvp.Key] = valueText;
|
|
}
|
|
}
|
|
|
|
public void UpdateUI(Dictionary<string, string> entity)
|
|
{
|
|
foreach (var kvp in entity)
|
|
{
|
|
if (textDict.TryGetValue(kvp.Key, out var txt))
|
|
{
|
|
txt.text = kvp.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|