Files
2026-03-04 10:03:45 +08:00

96 lines
1.6 KiB
C#

using UnityEngine;
namespace ShiningGames.UFS2
{
public class TestRod : MonoBehaviour
{
[SerializeField]
private TestReel _Reel;
[SerializeField]
private TestAtachment _Attachment;
[SerializeField]
private float _ReelModifier;
private bool _IsRodCasting;
private Animator _Animator;
[SerializeField]
private float _StopReelAttachmentVelocityThreshold = 0.025f;
private Vector3 _LastAttachmentPosition;
private void Start()
{
_Animator = GetComponent<Animator>();
}
private void OnEnable()
{
_Attachment.OnEnterToWater += StopLengthCast;
}
private void OnDisable()
{
_Attachment.OnEnterToWater -= StopLengthCast;
}
private void Update()
{
if (Input.GetMouseButtonDown(1))
{
PrepareCasting();
}
if (Input.GetMouseButtonUp(1))
{
Cast();
}
if (Input.GetMouseButton(0))
{
_Reel.ReelLine();
}
CastingUpdateHandler();
}
private void Cast()
{
_Animator.SetTrigger("cast");
}
private void CastingUpdateHandler()
{
if (_IsRodCasting)
{
float velocityMagnitude = _Attachment.VelocityMagnitude;
Vector3.Distance(_LastAttachmentPosition, _Attachment.transform.position);
if (_IsRodCasting)
{
_Reel.UnwindLine(_Attachment.Speed * _ReelModifier);
}
if (velocityMagnitude < _StopReelAttachmentVelocityThreshold)
{
StopLengthCast();
}
}
}
private void PrepareCasting()
{
_Animator.SetTrigger("prepareCast");
}
public void LengthCast()
{
_LastAttachmentPosition = _Attachment.transform.position;
_IsRodCasting = true;
}
public void StopLengthCast()
{
_IsRodCasting = false;
}
}
}