using Cal.DataTable; using ET; using ET.EventType; using FairyGUI; using System; using System.Collections.Generic; using UnityEngine; namespace ET { public class HudCharacter : Entity { private float MaxHp; private float Hp; private bool isVisible; private FUI_HeadTitleInfo _fui; private FUI_HeadTitleInfo fui { get { if (!_fui) { _fui = Parent.GetComponent(); } return _fui; } } public void Init(SetHudCharacter unitCharacter, ProgressTitleType progressTitleType) { try { Init(unitCharacter.unit, unitCharacter.hp, unitCharacter.maxHp, unitCharacter.level, unitCharacter.name, unitCharacter.jobType, progressTitleType); } catch (Exception e) { Log.Error(e); } } private void Init(Unit unit, int hp, int maxHp, int level, string _name, JobType jobType, ProgressTitleType titleType = ProgressTitleType.ValueAndMax) { try { Hp = hp; MaxHp = maxHp; UpdateJobSign(unit, jobType); SetTitle(unit.GetComponent().GetAsInt(NumericType.Title)); fui.m_label.m_txtName.text = _name; fui.m_label.m_txtLevel.text = $"{CharacterHelper.GetLevelString(unit, level)}"; Center(); if (maxHp == 0) return; this.fui.m_pbHp.SetMaxShield(Hp,0,MaxHp); } catch (Exception e) { Log.Error(e); } } private void Center() { fui.m_label.self.LRCenter(); } private void UpdateJobSign(Unit unit, JobType jobType) { int job = (int)jobType; fui.m_job.selectedIndex = job; NumericComponent num = unit.GetComponent(); if (num) { job += num.GetAsInt(NumericType.Transmigration) * 4; } fui.m_label.m_job.selectedIndex = job; } internal void SetTitle(int title) { if (title == 0) { fui.m_txtTitle.text = null; return; } TitleConfig titleConfig = TitleConfigCategory.Instance.Get(title); fui.m_txtTitle.text = titleConfig.Title; } public void SetUnitType(Unit unit) { UnitType unitType = unit.UnitType; if (unitType == UnitType.None) { unitType = GetParent().UnitType; } Color color = Color.green; switch (unitType) { case UnitType.Player: color = ColorHelper.GetColorByStr("#068eec"); HideHpBar(); break; case UnitType.TeamMember: color = Color.blue; HideHpBar(); break; case UnitType.Monster: case UnitType.Enermy: color = Color.red; ShowHpBar(unit); break; case UnitType.MapMonster: color = Color.red; HideHpBar(); break; case UnitType.OtherPlayer: color = ColorHelper.GetColorByStr("#07ce01"); HideHpBar(); break; case UnitType.None: break; case UnitType.NPC: break; case UnitType.TransPoint: HideHpBar(); break; case UnitType.SceneUnit: HideHpBar(); break; case UnitType.Pet: HideHpBar(); break; default: break; } fui.m_label.m_imgLevelBG.color = color; fui.m_label.m_txtName.color = color; } public void ChangeToLevel(Entity unit) { fui.m_label.m_txtLevel.text = $"{CharacterHelper.GetLevelString(unit)}"; } public void RefreshHp(NumericComponent num) { float hp = num.Get(NumericType.Hp); float maxHp = num.Get(NumericType.MaxHp); if (Hp > MaxHp) Hp = MaxHp; if (Hp < 0) Hp = 0; Hp = hp; MaxHp = maxHp; if (!isVisible) return; if (maxHp <= 0) return; this.fui.m_pbHp.SetHpAndShield(Hp,0,this.MaxHp); } public void ShowHpBar(Unit unit) { NumericComponent num = unit.GetComponent(); fui.m_pbHp.self.visible = isVisible = true; RefreshHp(num); } public void HideHpBar() { fui.m_pbHp.self.visible = isVisible = false; } } }