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 const float originScale = 0.8f; /// /// 运行中的组件 /// 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(); //thisTranform.localScale.x * unitView.transform.localScale.x = originScale*0.01 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); float scale =originScale*0.01f/ unitView.transform.localScale.x; go.localScale = new Vector3(scale,scale,1); go.position = unitView.HeadPoint.position; 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(); } } }