CTT/Unity/Assets/HotfixView/Entity/HudComponent.cs

73 lines
2.3 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using ET;
using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ET
{
2021-09-04 14:55:51 +08:00
public class HudComponentAwakeSystem: AwakeSystem<HudComponent>
2021-04-08 20:09:59 +08:00
{
public override void Awake(HudComponent self)
{
HudComponent.Instance = self;
}
}
2021-09-04 14:55:51 +08:00
public class HudComponent: Entity
2021-04-08 20:09:59 +08:00
{
public static HudComponent Instance { get; set; }
/// <summary>
/// 运行中的组件
/// </summary>
private Queue<GComponent> PreQue = new Queue<GComponent>();
private readonly int sortingOrder = 100;
2021-09-04 14:55:51 +08:00
2021-04-08 20:09:59 +08:00
public void Init(Unit unit)
{
2021-09-04 14:55:51 +08:00
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<HudCharacter>();
GComponent gComponent = this.PreQue.Dequeue();
UnitView unitView = unit.GetComponent<UnitView>();
2021-04-08 20:09:59 +08:00
FUI_HeadTitleInfo fui = FUI_HeadTitleInfo.GetFormPool(FUIComponent.Instance, gComponent);
fui.Name = fui.Id.ToString();
2021-09-04 14:55:51 +08:00
hudCharacter.fui = fui;
2021-04-11 19:50:39 +08:00
Transform go = fui.self.container.cachedTransform.parent.parent;
2021-04-08 20:09:59 +08:00
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);
}
2021-09-04 14:55:51 +08:00
2021-04-08 20:09:59 +08:00
public void Remove(Unit unit)
{
2021-09-04 14:55:51 +08:00
FUI_HeadTitleInfo fui = unit.GetComponent<HudCharacter>().fui;
2021-04-08 20:09:59 +08:00
if (fui == null)
{
Log.Error($"fui == null");
return;
}
2021-09-04 14:55:51 +08:00
this.PreQue.Enqueue(fui.self);
Transform go = fui.self.container.cachedTransform.parent.parent;
go.SetParent(UnityRoot.Instance.ObjPoolParent);
go.gameObject.SetActive(false);
2021-04-08 20:09:59 +08:00
unit.RemoveComponent<HudCharacter>();
}
}
2021-09-04 14:55:51 +08:00
}