123 lines
3.6 KiB
C#
123 lines
3.6 KiB
C#
using System;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Players;
|
|
using BlueWater.Uis;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public static class PumpSpineAnimation
|
|
{
|
|
public const string Idle = "Idle";
|
|
public const string Run = "Run";
|
|
}
|
|
|
|
[Serializable]
|
|
public class Pump : InteractionFurniture
|
|
{
|
|
[SerializeField]
|
|
private SpineController _spineController;
|
|
|
|
[SerializeField]
|
|
private float _playerHoldingTime = 1f;
|
|
|
|
[SerializeField]
|
|
private PumpingMessage _pumpingMessageObject;
|
|
|
|
[SerializeField]
|
|
private Vector3 _offset;
|
|
|
|
[SerializeField, Range(0, 1000)]
|
|
private int addedLiquid = 400;
|
|
|
|
[SerializeField]
|
|
private string _attackSfxName = "AttackWhip";
|
|
|
|
[SerializeField]
|
|
private string _playPumpSfxName = "PlayPump";
|
|
|
|
private bool _isPlayerInteracting;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
_spineController = GetComponent<SpineController>();
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
_spineController.PlayAnimation(PumpSpineAnimation.Idle, true);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
|
}
|
|
|
|
if (HoldingElapsedTime > _playerHoldingTime)
|
|
{
|
|
HoldingElapsedTime -= _playerHoldingTime;
|
|
|
|
EventManager.InvokeAddBarrels(addedLiquid);
|
|
var pumpingMessage = Instantiate(_pumpingMessageObject, transform.position + _offset,
|
|
Quaternion.identity, TycoonUiManager.Instance.WorldCanvas.transform);
|
|
pumpingMessage.Initialize(addedLiquid);
|
|
}
|
|
|
|
float playerHoldingDeltaTime = Time.deltaTime / _playerHoldingTime;
|
|
if (_isPlayerInteracting)
|
|
{
|
|
HoldingElapsedTime += playerHoldingDeltaTime;
|
|
}
|
|
else
|
|
{
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
HoldingElapsedTime -= playerHoldingDeltaTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
AudioManager.Instance.PlaySfx(_attackSfxName, true);
|
|
AudioManager.Instance.PlaySfx(_playPumpSfxName, true);
|
|
GameManager.Instance.CurrentTycoonPlayer.IsPumping = true;
|
|
_isPlayerInteracting = true;
|
|
_spineController.PlayAnimation(PumpSpineAnimation.Run, true);
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
AudioManager.Instance.StopSfx(_attackSfxName);
|
|
AudioManager.Instance.StopSfx(_playPumpSfxName);
|
|
GameManager.Instance.CurrentTycoonPlayer.IsPumping = false;
|
|
_isPlayerInteracting = false;
|
|
_spineController.PlayAnimation(PumpSpineAnimation.Idle, true);
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpAnything();
|
|
}
|
|
|
|
public override void ShowInteractionUi()
|
|
{
|
|
_spineController.EnableCustomMaterial();
|
|
EventManager.InvokeShowInteractionUi(InteractionMessage);
|
|
IsShowing = true;
|
|
}
|
|
|
|
public override void HideInteractionUi()
|
|
{
|
|
_spineController.DisableCustomMaterial();
|
|
EventManager.InvokeHideInteractionUi();
|
|
IsShowing = false;
|
|
}
|
|
}
|
|
} |