using System; using UnityEngine; public class LevelRewardSection : MonoBehaviour { public bool IsWorking { get; private set; } public bool HasReward => _progression.HasReward; private LevelRewardProgression _progression; private LevelRewardFiller _filler; private ItemRewardWindow _rewardWindow; private void Awake() { _filler = transform.FindRecursive("IconsFillBar").GetComponent(); } public void Init(string alias) { _progression = new LevelRewardProgression(alias); if (HasReward) _filler.SetItem(_progression.RewardItem, _progression.Progress); } public void ChangeProgress(bool canCompletedProgress) { SetIsWorking(true); _progression.ChangeProgress(canCompletedProgress); _filler.OnCompletedFilling += OnFillerFinishedFilling; _filler.FillTo(_progression.Progress); } private void OnFillerFinishedFilling() { _filler.OnCompletedFilling -= OnFillerFinishedFilling; if (_progression.ProgressIsFull) { _rewardWindow = UI.GetOrCreateWindow(); _rewardWindow.SetItem(_progression.RewardItem); _rewardWindow.SetCallback(OnRewardWindowResult); _rewardWindow.Show(); } else SetIsWorking(false); } private void SetIsWorking(bool isWorking) { IsWorking = isWorking; } public void Show() { gameObject.SetActive(true); } public void Hide() { gameObject.SetActive(false); } private void OnRewardWindowResult(RewardStatus result) { switch (result) { case RewardStatus.PlayerRefused: OnPlayerSkipReward(); break; case RewardStatus.PlayerNeedsReward: OnPlayerNeedReward(); break; default: throw new ArgumentOutOfRangeException(nameof(result), result, null); } _rewardWindow.Close(); SetIsWorking(false); } private void OnPlayerSkipReward() { Hide(); } private void OnPlayerNeedReward() { ApplyRewardItem(); // поменять вид } private void ApplyRewardItem() { _progression.ApplyItemToInventory(); _progression.TryRandomizeNewItem(0); } }