Files
valheim/Assets/_Valheim/Scripts/UI/BossUI.cs
2025-07-04 14:16:14 +08:00

85 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
}