zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/HotfixView/Entity/HudComponent.cs

76 lines
2.5 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
{
public class HudComponentAwakeSystem : AwakeSystem<HudComponent>
{
public override void Awake(HudComponent self)
{
HudComponent.Instance = self;
}
}
public class HudComponent : Entity
{
public static HudComponent Instance { get; set; }
/// <summary>
/// 运行中的组件
/// </summary>
private Queue<GComponent> PreQue = new Queue<GComponent>();
private readonly int sortingOrder = 100;
public void Init(Unit unit)
{
2021-06-29 11:28:15 +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);
// }
// GComponent gComponent = this.PreQue.Dequeue();
GameObject hud = new GameObject("Hud");
GComponent gComponent = hud.Add3DUI(FUI_HeadTitleInfo.UIPackageName, FUI_HeadTitleInfo.UIResName, Camera.main, sortingOrder);
2021-04-08 20:09:59 +08:00
FUI_HeadTitleInfo fui = FUI_HeadTitleInfo.GetFormPool(FUIComponent.Instance, gComponent);
fui.Name = fui.Id.ToString();
unit.AddComponent(fui);
2021-04-11 19:50:39 +08:00
UnitView unitView = unit.GetComponent<UnitView>();
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);
2021-04-11 19:50:39 +08:00
HudCharacter hudCharacter = unit.AddComponent<HudCharacter>();
2021-04-08 20:09:59 +08:00
hudCharacter.SetUnitType(unit);
}
public void Remove(Unit unit)
{
2021-04-11 19:50:39 +08:00
FUI_HeadTitleInfo fui = unit.GetComponent<FUI_HeadTitleInfo>();
2021-04-08 20:09:59 +08:00
if (fui == null)
{
Log.Error($"fui == null");
return;
}
2021-06-29 11:28:15 +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(fui);
unit.RemoveComponent<HudCharacter>();
}
}
}