185 lines
5.5 KiB
C#
185 lines
5.5 KiB
C#
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<FUI_HeadTitleInfo>();
|
|
}
|
|
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<NumericComponent>().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;
|
|
fui.m_progress.value = Hp;
|
|
fui.m_progress.max = MaxHp;
|
|
fui.m_progress.titleType = titleType;
|
|
}
|
|
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<NumericComponent>();
|
|
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<Unit>().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(Unit 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;
|
|
fui.m_progress.max = MaxHp;
|
|
fui.m_progress.value = Hp;
|
|
|
|
}
|
|
public void ChangeHp(int changeHPValue)
|
|
{
|
|
Hp += changeHPValue;
|
|
if (Hp > MaxHp)
|
|
Hp = MaxHp;
|
|
if (Hp < 0)
|
|
Hp = 0;
|
|
if (!isVisible) return;
|
|
fui.m_progress.value = Hp;
|
|
|
|
}
|
|
|
|
public void ShowHpBar(Unit unit)
|
|
{
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
|
fui.m_progress.visible = isVisible = true;
|
|
RefreshHp(num);
|
|
}
|
|
public void HideHpBar()
|
|
{
|
|
fui.m_progress.visible = isVisible = false;
|
|
}
|
|
}
|
|
}
|