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

71 lines
2.2 KiB
C#

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