mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-19 23:37:13 +08:00
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Base;
|
|
using Entity;
|
|
using Managers;
|
|
using UnityEngine;
|
|
|
|
namespace UI
|
|
{
|
|
public class NanorobotsHPUI:MonoBehaviour,ITickUI
|
|
{
|
|
public BarUI hpBar;
|
|
public List<Entity.Entity> nanorobots;
|
|
public string nanorobotAffiliation;
|
|
|
|
private void Start()
|
|
{
|
|
EntityManager.Instance.OnCreateEntity += OnCreateEntity;
|
|
nanorobotAffiliation = Configs.ConfigManager.Instance.GetValue<string>("NanorobotsAffiliation");
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EntityManager.Instance.OnCreateEntity -= OnCreateEntity;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Clock.AddTickUI(this);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
Clock.RemoveTickUI(this);
|
|
}
|
|
|
|
public void TickUI()
|
|
{
|
|
float totalHP = 0;
|
|
float remainHP = 0;
|
|
foreach (var entity in nanorobots)
|
|
{
|
|
remainHP += entity.AttributesNow.health;
|
|
totalHP += entity.BaseAttributes.health;
|
|
}
|
|
|
|
if (totalHP == 0)
|
|
{
|
|
hpBar.Progress = 1;
|
|
}
|
|
else
|
|
{
|
|
hpBar.Progress = remainHP / totalHP;
|
|
}
|
|
}
|
|
private void OnCreateEntity(Entity.Entity entity)
|
|
{
|
|
if (entity.affiliation == nanorobotAffiliation)
|
|
{
|
|
nanorobots.Add(entity);
|
|
entity.OnEntityDiedEvent += OnDied;
|
|
}
|
|
}
|
|
|
|
private void OnDied(Entity.Entity entity)
|
|
{
|
|
nanorobots.Remove(entity);
|
|
}
|
|
}
|
|
} |