2024-11-11 09:51:12 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
2024-12-10 06:49:15 +00:00
|
|
|
using BlueWater.Audios;
|
2024-11-21 11:05:59 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
using Sirenix.OdinInspector;
|
2024-11-11 09:51:12 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater.Tycoons
|
|
|
|
{
|
|
|
|
[Serializable]
|
|
|
|
public class RewardBox : InteractionFurniture
|
|
|
|
{
|
2024-12-06 13:20:10 +00:00
|
|
|
[Title("참조")]
|
2024-11-11 09:51:12 +00:00
|
|
|
[SerializeField]
|
|
|
|
private AnimationController _animationController;
|
|
|
|
|
2024-11-21 11:05:59 +00:00
|
|
|
[Title("구매 불가능 연출")]
|
|
|
|
[SerializeField]
|
|
|
|
private float _shakeDuration = 0.3f;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Vector3 _shakePosition = new(0.05f, 0f, 0f);
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private int _vibrato = 30;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Ease _ease = Ease.OutQuad;
|
|
|
|
|
2024-12-10 06:49:15 +00:00
|
|
|
[SerializeField]
|
|
|
|
private string _interactionFailedSfxName = "RewardBoxInteractionFailed";
|
|
|
|
|
2024-11-21 11:05:59 +00:00
|
|
|
private Tween _unavailablePurchaseTween;
|
2024-11-11 09:51:12 +00:00
|
|
|
private RewardBoxType _rewardBoxType;
|
2024-11-12 09:15:42 +00:00
|
|
|
private int _requiredGold;
|
2024-11-11 09:51:12 +00:00
|
|
|
private bool _isInteracting;
|
2024-11-21 11:05:59 +00:00
|
|
|
|
|
|
|
protected override void Start()
|
|
|
|
{
|
|
|
|
base.Start();
|
|
|
|
|
|
|
|
_unavailablePurchaseTween = VisualLook.transform.DOShakePosition(_shakeDuration, _shakePosition, _vibrato).SetEase(_ease).SetAutoKill(false).Pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
_unavailablePurchaseTween.Kill();
|
|
|
|
}
|
|
|
|
|
2024-11-12 09:15:42 +00:00
|
|
|
public void Initialize(LevelData levelData)
|
2024-11-11 09:51:12 +00:00
|
|
|
{
|
2024-11-12 09:15:42 +00:00
|
|
|
_rewardBoxType = levelData.RewardBoxType;
|
2024-11-12 12:07:23 +00:00
|
|
|
_requiredGold = levelData.RewardBoxPrice;
|
2024-11-12 09:15:42 +00:00
|
|
|
InteractionCanvas.UnlockUi.Initialize(DataManager.Instance.SpriteDataSo.Gold02, _requiredGold);
|
2024-11-11 09:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Interaction()
|
|
|
|
{
|
|
|
|
if (_isInteracting) return;
|
2024-11-21 11:05:59 +00:00
|
|
|
|
|
|
|
if (TycoonManager.Instance.TycoonStatus.CurrentGold < _requiredGold)
|
|
|
|
{
|
2024-12-10 06:49:15 +00:00
|
|
|
AudioManager.Instance.PlaySfx(_interactionFailedSfxName);
|
2024-11-21 11:05:59 +00:00
|
|
|
_unavailablePurchaseTween.Restart();
|
|
|
|
return;
|
|
|
|
}
|
2024-11-11 09:51:12 +00:00
|
|
|
|
|
|
|
StartCoroutine(nameof(OpenRewardBoxCoroutine));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void CancelInteraction()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator OpenRewardBoxCoroutine()
|
|
|
|
{
|
|
|
|
_isInteracting = true;
|
2024-11-11 12:23:27 +00:00
|
|
|
|
2024-11-15 07:28:13 +00:00
|
|
|
EventManager.InvokeAddedGold(-_requiredGold, false);
|
2024-11-12 09:15:42 +00:00
|
|
|
|
2024-11-11 09:51:12 +00:00
|
|
|
switch (_rewardBoxType)
|
|
|
|
{
|
|
|
|
case RewardBoxType.Normal:
|
|
|
|
EventManager.InvokeOpenedNormalRewardBox();
|
|
|
|
break;
|
|
|
|
case RewardBoxType.Rare:
|
|
|
|
EventManager.InvokeOpenedRareRewardBox();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
|
2024-12-17 13:50:27 +00:00
|
|
|
_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);
|
|
|
|
|
2024-11-11 09:51:12 +00:00
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|