using System; using System.Collections; using UnityEngine; namespace BlueWater.Tycoons { [Serializable] public class RewardBox : InteractionFurniture { [SerializeField] private AnimationController _animationController; private RewardBoxType _rewardBoxType; private bool _isInteracting; public void Initialize(RewardBoxType rewardBoxType) { _rewardBoxType = rewardBoxType; } public override void Interaction() { if (_isInteracting) return; StartCoroutine(nameof(OpenRewardBoxCoroutine)); } public override void CancelInteraction() { } private IEnumerator OpenRewardBoxCoroutine() { _isInteracting = true; _animationController.SetAnimationParameter("isOpened", true); var animationStarted = false; yield return StartCoroutine(_animationController.WaitForAnimationToRun("Open", success => animationStarted = success)); if (!animationStarted) { Destroy(gameObject); yield break; } yield return new WaitUntil(() => _animationController.GetCurrentAnimationNormalizedTime() >= 1f); switch (_rewardBoxType) { case RewardBoxType.Normal: EventManager.InvokeOpenedNormalRewardBox(); break; case RewardBoxType.Rare: EventManager.InvokeOpenedRareRewardBox(); break; default: throw new ArgumentOutOfRangeException(); } Destroy(gameObject); } } }