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"); var c = hud.Add3DUI(FUI_HeadTitleInfo.UIPackageName, FUI_HeadTitleInfo.UIResName, Camera.main, sortingOrder); this.PreQue.Enqueue(c); } GComponent gComponent = this.PreQue.Dequeue(); FUI_HeadTitleInfo fui = FUI_HeadTitleInfo.GetFormPool(FUIComponent.Instance, gComponent); fui.Name = fui.Id.ToString(); unit.AddComponent(fui); var unitView = unit.GetComponent(); var 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); var hudCharacter = unit.AddComponent(); hudCharacter.SetUnitType(unit); } public void Remove(Unit unit) { var fui = unit.GetComponent(); if (fui == null) { Log.Error($"fui == null"); return; } this.PreQue.Enqueue(fui.self); var go = fui.self.container.cachedTransform.parent.parent; go.SetParent(UnityRoot.Instance.ObjPoolParent); go.gameObject.SetActive(false); unit.RemoveComponent(fui); unit.RemoveComponent(); } } }