CapersProject/Assets/02.Scripts/Prop/Tycoon/RewardBox.cs
2024-11-11 21:23:27 +09:00

65 lines
1.8 KiB
C#

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);
}
}
}