85 lines
2.1 KiB
C#
85 lines
2.1 KiB
C#
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using DG.Tweening;
|
||
using DragonLi.Core;
|
||
using Common;
|
||
using BehaviorDesigner.Runtime;
|
||
using Mirror;
|
||
|
||
namespace Valheim
|
||
{
|
||
public class BossUI : NetworkBehaviour
|
||
{
|
||
public GameObject found;
|
||
public TextMeshProUGUI[] lvIcon;
|
||
public Image[] lvIconBg;
|
||
|
||
public Image blood1;
|
||
|
||
public Image blood2;
|
||
|
||
public State uiState;
|
||
|
||
public FishGiant boss;
|
||
public BehaviorTree behaviorTree;
|
||
|
||
public void Start()
|
||
{
|
||
if (isServer)
|
||
{
|
||
// behaviorTree.RegisterEvent("FoundEnemy", FoundEnemyRpc);
|
||
// behaviorTree.RegisterEvent("Back", BackRpc);
|
||
behaviorTree.RegisterEvent("Ghost", GhostRpc);
|
||
}
|
||
uiState.StateChange(2);
|
||
}
|
||
|
||
public void Update()
|
||
{
|
||
if (isClient)
|
||
{
|
||
if (boss.bossState == BossState.Idle)
|
||
{
|
||
uiState.StateChange(1);
|
||
}
|
||
|
||
// 亮出完整ui时,更新等级和血量
|
||
if (uiState.nowState == 1)
|
||
{
|
||
LvChange(boss.lvl);
|
||
HpChange(boss.health, boss.OriginHealth);
|
||
}
|
||
// 不完整ui,更新等级
|
||
else if (uiState.nowState == 2)
|
||
{
|
||
LvChange(boss.lvl);
|
||
}
|
||
}
|
||
}
|
||
|
||
[ClientRpc]
|
||
public void GhostRpc()
|
||
{
|
||
// 隐藏ui
|
||
uiState.StateChange(0);
|
||
}
|
||
|
||
public void LvChange(int lv)
|
||
{
|
||
for (int i = 0; i < lvIconBg.Length; i++)
|
||
{
|
||
lvIconBg[i].sprite = Resources.Load<Sprite>($"BloodIcon/Enemy/lvl{lv}");
|
||
lvIcon[i].text = $"<sprite={lv}>";
|
||
}
|
||
}
|
||
|
||
public void HpChange(float currentBlood, float totalBlood)
|
||
{
|
||
float value = currentBlood / totalBlood;
|
||
DOTween.To(() => blood2.fillAmount, x => blood2.fillAmount = x, value, 0.5f);
|
||
blood1.fillAmount = value;
|
||
}
|
||
}
|
||
}
|