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

71 lines
2.2 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
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");
2021-04-11 19:50:39 +08:00
GComponent c = hud.Add3DUI(FUI_TaskTipUI.UIPackageName, FUI_TaskTipUI.UIResName, Camera.main, sortingOrder);
2021-04-08 20:09:59 +08:00
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);
2021-04-11 19:50:39 +08:00
Transform go = fui.self.container.cachedTransform.parent;
UnitView unitView = unit.GetComponent<UnitView>();
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);
return fui;
}
public void Remove(Unit unit)
{
2021-04-11 19:50:39 +08:00
FUI_TaskTipUI fui = unit.GetComponent<FUI_TaskTipUI>();
2021-04-08 20:09:59 +08:00
if (fui == null)
{
Log.Error($"fui == null");
return;
}
fui.m_taskState.selectedIndex = (int)TaskState.TaskNoneState;
this.PreQue.Enqueue(fui.self);
2021-04-11 19:50:39 +08:00
Transform go = fui.self.container.cachedTransform.parent;
2021-04-08 20:09:59 +08:00
go.SetParent(UnityRoot.Instance.ObjPoolParent);
go.gameObject.SetActive(false);
unit.RemoveComponent(fui);
}
}
}