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

78 lines
2.5 KiB
C#

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; }
private const float originScale = 0.8f;
/// <summary>
/// 运行中的组件
/// </summary>
private Queue<GComponent> PreQue = new Queue<GComponent>();
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<HudCharacter>();
GComponent gComponent = this.PreQue.Dequeue();
UnitView unitView = unit.GetComponent<UnitView>();
//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<HudCharacter>().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<HudCharacter>();
}
}
}