using ET; using ET; using FairyGUI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace ET { public class HudComponentAwakeSystem: AwakeSystem { public override void Awake(HudComponent self) { HudComponent.Instance = self; } } public class HudComponent: Entity { public static HudComponent Instance { get; set; } /// /// 运行中的组件 /// private Queue PreQue = new Queue(); private readonly int sortingOrder = 100; public void Init(Unit unit) { if (PreQue.Count == 0) { GameObject hud = new GameObject("Hud"); GComponent c = hud.Add3DUI(FUI_HeadTitleInfo.UIPackageName, FUI_HeadTitleInfo.UIResName, Camera.main, sortingOrder); this.PreQue.Enqueue(c); } HudCharacter hudCharacter = unit.AddComponent(); GComponent gComponent = this.PreQue.Dequeue(); UnitView unitView = unit.GetComponent(); FUI_HeadTitleInfo fui = FUI_HeadTitleInfo.GetFormPool(FUIComponent.Instance, gComponent); fui.Name = fui.Id.ToString(); hudCharacter.fui = fui; Transform go = fui.self.container.cachedTransform.parent.parent; go.SetParent(unitView.transform); go.position = unitView.HeadPoint.position; go.localScale = Vector3.one / 100; go.gameObject.SetActive(true); FairyGUI.Stage.inst.SortWorldSpacePanelsByZOrder(sortingOrder); hudCharacter.SetUnitType(unit); } public void Remove(Unit unit) { FUI_HeadTitleInfo fui = unit.GetComponent().fui; if (fui == null) { Log.Error($"fui == null"); return; } this.PreQue.Enqueue(fui.self); Transform go = fui.self.container.cachedTransform.parent.parent; go.SetParent(UnityRoot.Instance.ObjPoolParent); go.gameObject.SetActive(false); unit.RemoveComponent(); } } }