mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 00:57:14 +08:00
52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using Base;
|
||
|
|
using Entity;
|
||
|
|
using Managers;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace UI
|
||
|
|
{
|
||
|
|
public class BaseBuildingHPBarUI:MonoBehaviour,ITickUI
|
||
|
|
{
|
||
|
|
public BarUI baseBuildingHPBar;
|
||
|
|
private List<Building> playerBuildings = new();
|
||
|
|
|
||
|
|
public void Init()
|
||
|
|
{
|
||
|
|
var entities= EntityManager.Instance.FindEntitiesByFaction(Program.Instance.FocusedDimensionId,
|
||
|
|
AffiliationManager.Instance.PlayerAffiliation);
|
||
|
|
if (entities is not { Length: > 0 }) return;
|
||
|
|
foreach (var entity in entities)
|
||
|
|
{
|
||
|
|
if(entity.entity is Building playerBuilding)
|
||
|
|
{
|
||
|
|
playerBuildings.Add(playerBuilding);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnEnable()
|
||
|
|
{
|
||
|
|
Clock.AddTickUI(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnDisable()
|
||
|
|
{
|
||
|
|
Clock.RemoveTickUI(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void TickUI()
|
||
|
|
{
|
||
|
|
if (!playerBuildings.Any()) return;
|
||
|
|
float tHp=0;
|
||
|
|
float nHp=0;
|
||
|
|
foreach (var playerBuilding in playerBuildings)
|
||
|
|
{
|
||
|
|
tHp=playerBuilding.BaseAttributes.health;
|
||
|
|
nHp=playerBuilding.AttributesNow.health;
|
||
|
|
}
|
||
|
|
baseBuildingHPBar.Progress = nHp / tHp;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|