using System; using System.Collections.Generic; using Code.Infrastructure.Camera; using Code.Infrastructure.UI; using Code.OfficeGame.BattleMode.Actions; using Code.OfficeGame.BattleMode.Health.UI; using Code.OfficeGame.BattleMode.Timeline; using Cysharp.Threading.Tasks; using R3; using Reflex.Attributes; using UnityEngine; namespace Code.OfficeGame.BattleMode.Health { public class HealthPanelsHolder : IDisposable { public List PanelList { get; private set; } = new(); private readonly List<(EntityHealthPanel Panel, EntityId EntityId)> _bindings = new(); [Inject] private void Construct(CameraStateMachine cameraStateMachine) { foreach (var panel in PanelList) panel.Construct(cameraStateMachine); } public async UniTask SpawnHealthBars(IUIFactory factory, List entities) { PanelList = new List(); _bindings.Clear(); foreach (var entity in entities) { var healthBarTarget = entity.GetComponentInChildren(); if (!healthBarTarget) continue; var panel = (EntityHealthPanel)await factory.LoadPanel(UIPanelType.EntityHealthBar, false); panel.SetTarget(healthBarTarget.transform); PanelList.Add(panel); _bindings.Add((panel, entity.GetEntityId())); } } public IDisposable BindToTimeline(BattleTimeline timeline) { var bag = new DisposableBag(); foreach (var (panel, entityId) in _bindings) { panel.BindToTimeline(timeline, entityId).AddTo(ref bag); } return bag; } public void Dispose() { foreach (var panel in PanelList) panel.Dispose(); PanelList.Clear(); _bindings.Clear(); } } }