233 lines
7.5 KiB
C#
233 lines
7.5 KiB
C#
using DDD.Audios;
|
|
using DDD.Interfaces;
|
|
using DDD.Items;
|
|
using DDD.Players;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace DDD.Tycoons
|
|
{
|
|
public static class TrashCanSpineAnimation
|
|
{
|
|
public const string ChangeRandomBox = "ChangeRandomBox";
|
|
public const string RandomBoxHolding = "RandomBoxHold";
|
|
public const string RandomBoxIdle = "RandomBoxIdle";
|
|
public const string RandomBoxSpit = "RandomBoxSpit";
|
|
public const string Open = "TrashCanOpen";
|
|
public const string Close = "TrashCanClose";
|
|
public const string Stop = "TrashCanCloseStop";
|
|
}
|
|
|
|
public class TrashCan : InteractionFurniture
|
|
{
|
|
[SerializeField]
|
|
private SpineController _spineController;
|
|
|
|
[SerializeField]
|
|
private float _discardHoldingTime = 0.5f;
|
|
|
|
[SerializeField]
|
|
private float _randomChangeHoldingTime = 1f;
|
|
|
|
[SerializeField]
|
|
private bool _canRandomChange;
|
|
|
|
[SerializeField]
|
|
private bool _isChanged;
|
|
|
|
[Title("사운드")]
|
|
[SerializeField]
|
|
private string _discardSfxName = "DiscardCocktail";
|
|
|
|
[SerializeField]
|
|
private string _changeRandomBoxSfxName = "ChangeRandomBox";
|
|
|
|
[SerializeField]
|
|
private string _changeRandomCocktailSfxName = "ChangeRandomCocktail";
|
|
|
|
private bool _isPlayerInteracting;
|
|
private bool _canInteraction = true;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
_spineController = GetComponent<SpineController>();
|
|
|
|
EventManager.OnChangedRandomBox += ChangeRandomBox;
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.Stop, false);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_isChanged)
|
|
{
|
|
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
|
|
{
|
|
_canInteraction = true;
|
|
}
|
|
}
|
|
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
|
}
|
|
|
|
if (HoldingElapsedTime >= 1f)
|
|
{
|
|
if (_isChanged)
|
|
{
|
|
ChangeRandomCocktail();
|
|
}
|
|
else
|
|
{
|
|
DiscardItem();
|
|
}
|
|
}
|
|
|
|
float randomChangeHoldingDeltaTime = Time.deltaTime / _randomChangeHoldingTime;
|
|
float discardHoldingDeltaTime = Time.deltaTime / _discardHoldingTime;
|
|
if (_isPlayerInteracting)
|
|
{
|
|
if (_isChanged)
|
|
{
|
|
HoldingElapsedTime += randomChangeHoldingDeltaTime;
|
|
}
|
|
else
|
|
{
|
|
HoldingElapsedTime += discardHoldingDeltaTime;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
if (_isChanged)
|
|
{
|
|
HoldingElapsedTime -= randomChangeHoldingDeltaTime;
|
|
}
|
|
else
|
|
{
|
|
HoldingElapsedTime -= discardHoldingDeltaTime;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
EventManager.OnChangedRandomBox -= ChangeRandomBox;
|
|
}
|
|
|
|
public void ChangeRandomBox()
|
|
{
|
|
if (!_canRandomChange) return;
|
|
|
|
AudioManager.Instance.PlaySfx(_changeRandomBoxSfxName);
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.ChangeRandomBox, false);
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.RandomBoxIdle, true);
|
|
_isChanged = true;
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
_isPlayerInteracting = true;
|
|
|
|
if (_isChanged)
|
|
{
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.RandomBoxHolding, true);
|
|
}
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
_isPlayerInteracting = false;
|
|
|
|
if (_isChanged)
|
|
{
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.RandomBoxIdle, false);
|
|
}
|
|
else
|
|
{
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.Stop, false);
|
|
}
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpAnything() &&
|
|
((_isChanged && _canInteraction) || !_isChanged);
|
|
}
|
|
|
|
public override void ShowInteractionUi()
|
|
{
|
|
if (_isChanged)
|
|
{
|
|
UpdateLocalizedString("InteractionTrashCanChange");
|
|
}
|
|
else
|
|
{
|
|
UpdateLocalizedString("InteractionTrashCanDiscard");
|
|
}
|
|
|
|
_spineController.EnableCustomMaterial();
|
|
EventManager.InvokeShowInteractionUi(InteractionMessage);
|
|
IsShowing = true;
|
|
}
|
|
|
|
public override void HideInteractionUi()
|
|
{
|
|
_spineController.DisableCustomMaterial();
|
|
EventManager.InvokeHideInteractionUi();
|
|
IsShowing = false;
|
|
}
|
|
|
|
private void DiscardItem()
|
|
{
|
|
CocktailData discardCocktailData = null;
|
|
if (!CurrentTycoonPlayer.TycoonPickupHandler.IsUnfinishedCocktailPickedUp)
|
|
{
|
|
var discardCocktailDataIdx = CurrentTycoonPlayer.TycoonPickupHandler.CurrentPickupItem.Idx;
|
|
//discardCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(discardCocktailDataIdx);
|
|
}
|
|
|
|
AudioManager.Instance.PlaySfx(_discardSfxName);
|
|
EventManager.InvokeCocktailDiscarded(discardCocktailData, true);
|
|
|
|
HoldingElapsedTime = 0f;
|
|
_isPlayerInteracting = false;
|
|
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.Open, false);
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.Close, false);
|
|
}
|
|
|
|
private void ChangeRandomCocktail()
|
|
{
|
|
IPickup playerCurrentPickupItem = CurrentTycoonPlayer.TycoonPickupHandler.CurrentPickupItem;
|
|
if (playerCurrentPickupItem != null)
|
|
{
|
|
//CocktailData discardCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(playerCurrentPickupItem.Idx);
|
|
//EventManager.InvokeCocktailServedToCustomer(discardCocktailData, false);
|
|
}
|
|
|
|
CocktailData randomCocktail = TycoonManager.Instance.TycoonIngredientController.GetRandomCocktailData();
|
|
EventManager.InvokeChangedRandomCocktail(randomCocktail);
|
|
EventManager.InvokeCocktailCompleted(randomCocktail, false);
|
|
InteractionCanvas.BalloonUi.OrderItem(0, TycoonManager.Instance.TycoonStageController.StageDataSo.RandomChangeWaitTime);
|
|
AudioManager.Instance.PlaySfx(_changeRandomCocktailSfxName);
|
|
|
|
HoldingElapsedTime = 0f;
|
|
_canInteraction = false;
|
|
_isPlayerInteracting = false;
|
|
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.RandomBoxSpit, false);
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.RandomBoxIdle, true);
|
|
}
|
|
}
|
|
} |