using System.Collections.Generic; using Framework; using Framework.Wrapper; using Gameplay.Character; using Gameplay.Level; using Gameplay.Unit; using PhxhSDK; using TMPro; using UnityEngine; using Utils; public class UIDebugShowIDController : UIWindow { public class UIInfos : UIGameObjectWrapper { public TextMeshProUGUI Text_ID; public TextMeshProUGUI Text_State; public UIInfos(GameObject go) : base(go, true) { Text_ID = GetItem("Text_ID"); Text_State = GetItem("Text_State"); } } private Dictionary _idInfos = new Dictionary(16); private Stack _infoPool = new Stack(16); private GameObject _template; private HashSet _tempRemoveSet = new HashSet(16); public override void OnInit() { _template = FindObj("TemplateRoot"); _template.SetActive(false); } private void Update() { var characterManager = GameUnitManager.instance.characterManager; if (characterManager == null) { HideWindow(); return; } // ------------------- _tempRemoveSet.Clear(); foreach (var info in _idInfos) { if (characterManager.Get(info.Key) == null) { _tempRemoveSet.Add(info.Key); } } foreach (var id in _tempRemoveSet) { RecycleInfoGo(_idInfos[id]); _idInfos.Remove(id); } //------------------- characterManager.ForEach(delegate(Character character) { var id = character.GetID(); if (!_idInfos.ContainsKey(id)) { _idInfos.Add(id, CreateInfo(id)); } var infos = _idInfos[id]; var pos = PhxhSDK.Utils.WorldPos2ScreenPos(character.transData.pos, CameraManager.Instance.MainCamera); pos = PhxhSDK.Utils.ScreenPos2WorldPos(pos, CameraManager.Instance.UICamera); pos = new Vector3(pos.x, pos.y, 0); infos.SetPosition(pos); infos.Text_State.text = $"{character?.downFSM?.currentState?.GetType().Name}" + $", {character?.upFSM?.currentState?.GetType().Name}" + $", {character?.fullFSM?.currentState?.GetType().Name}"; }); } private void RecycleInfoGo(UIInfos info) { if (info != null) { info.IsActive = false; } _infoPool.Push(info); } private UIInfos CreateInfo(uint id) { if (!_infoPool.TryPop(out var infos)) { infos = new UIInfos(GameObject.Instantiate(_template, _template.transform.parent)); } infos.IsActive = true; infos.Text_ID.text = $"ID:{id:000000}"; infos.Text_State.text = $"State:{EDownState.None}"; return infos; } }