56 lines
1.5 KiB
C#
56 lines
1.5 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;
|
|
InteractionCanvas.BalloonUi.ShowUi();
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
if (_isInteracting) return;
|
|
|
|
StartCoroutine(nameof(OpenRewardBoxCoroutine));
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
|
|
}
|
|
|
|
private IEnumerator OpenRewardBoxCoroutine()
|
|
{
|
|
_isInteracting = true;
|
|
_animationController.SetAnimationParameter("isOpened", true);
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |