90 lines
2.5 KiB
C#
90 lines
2.5 KiB
C#
using System;
|
|
using DDD.Audios;
|
|
using UnityEngine;
|
|
|
|
namespace DDD.Tycoons
|
|
{
|
|
[Serializable]
|
|
public class Mushroom : InteractionFurniture
|
|
{
|
|
[SerializeField]
|
|
private float _playerHoldingTime = 3f;
|
|
|
|
[SerializeField]
|
|
private Sprite _heartSprite;
|
|
|
|
[SerializeField]
|
|
private string _cleaningSfxName = "CleaningFloor";
|
|
|
|
private bool _isPlayerInteracting;
|
|
|
|
private void Update()
|
|
{
|
|
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
|
}
|
|
|
|
if (HoldingElapsedTime >= 1f)
|
|
{
|
|
TycoonManager.Instance.TycoonStatus.CurrentPlayerHealth++;
|
|
|
|
Destroy();
|
|
}
|
|
|
|
float playerHoldingDeltaTime = Time.deltaTime / _playerHoldingTime;
|
|
if (_isPlayerInteracting)
|
|
{
|
|
InteractionCanvas.BalloonUi.PauseTween();
|
|
HoldingElapsedTime += playerHoldingDeltaTime;
|
|
}
|
|
else
|
|
{
|
|
InteractionCanvas.BalloonUi.ResumeTween();
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
HoldingElapsedTime -= playerHoldingDeltaTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
InteractionCanvas.BalloonUi.OrderItem(0, TycoonManager.Instance.TycoonStageController.StageDataSo.MushroomWaitTime);
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = true;
|
|
_isPlayerInteracting = true;
|
|
AudioManager.Instance.PlaySfx(_cleaningSfxName);
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
|
|
_isPlayerInteracting = false;
|
|
AudioManager.Instance.StopSfx(_cleaningSfxName);
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpAnything();
|
|
}
|
|
|
|
private void Destroy()
|
|
{
|
|
if (_isPlayerInteracting)
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
|
|
}
|
|
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
} |