163 lines
3.4 KiB
C#
163 lines
3.4 KiB
C#
using System;
|
|
using DarkTonic.MasterAudio;
|
|
using UFS3;
|
|
using UnityEngine;
|
|
|
|
public class Reel : MonoBehaviour, IInitializable<ReelData>
|
|
{
|
|
public Action<float> OnLineUnwind;
|
|
|
|
public Vector3 openEuler;
|
|
|
|
public Vector3 closeEuler;
|
|
|
|
[SerializeField]
|
|
private Vector3 rotateWorldUp = Vector3.forward;
|
|
|
|
[Tooltip("Use for handle for rotate it")]
|
|
[SerializeField]
|
|
private Transform crank;
|
|
|
|
[Tooltip("Transform for open close bail")]
|
|
[SerializeField]
|
|
private Transform bail;
|
|
|
|
[Tooltip("Rotor of bail")]
|
|
[SerializeField]
|
|
private Transform lineRoller;
|
|
|
|
[Tooltip("Up and down move when line-rolling")]
|
|
[SerializeField]
|
|
private Transform barrel;
|
|
|
|
[Tooltip("drag unwind spool")]
|
|
[SerializeField]
|
|
private Transform spool;
|
|
|
|
[Tooltip("Anchor for hand placement, setup position and rotation in playmode")]
|
|
[SerializeField]
|
|
private Transform ikAnchor;
|
|
|
|
[Tooltip("Transform for placing line from rod")]
|
|
[SerializeField]
|
|
private Transform lineOnRollerAnchor;
|
|
|
|
private float lastLineLength;
|
|
|
|
private bool isFishingEntered;
|
|
|
|
private Vector3 startBarrelLocalPosition;
|
|
|
|
private float _DragSetting = 0.5f;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve barrelMoveCurve;
|
|
|
|
private ReelData _ReelData;
|
|
|
|
private float barrelCurvePos;
|
|
|
|
private float crankRotateSpeedMultiply = 1f;
|
|
|
|
private bool _isBailClose;
|
|
|
|
private PlaySoundResult reelingSfx;
|
|
|
|
private float rotatorSpeed;
|
|
|
|
public float DragSetting => _DragSetting;
|
|
|
|
public Transform RopeAnchorOnRoller => lineOnRollerAnchor;
|
|
|
|
public Transform FingersIKAnchor => ikAnchor;
|
|
|
|
private void Start()
|
|
{
|
|
startBarrelLocalPosition = barrel.localPosition;
|
|
CloseBail();
|
|
}
|
|
|
|
private void OpenBail(bool isOpen)
|
|
{
|
|
if (isOpen)
|
|
{
|
|
bail.localEulerAngles = openEuler;
|
|
}
|
|
else
|
|
{
|
|
bail.localEulerAngles = closeEuler;
|
|
}
|
|
}
|
|
|
|
public void OpenBail()
|
|
{
|
|
if (_isBailClose)
|
|
{
|
|
_isBailClose = false;
|
|
OpenBail(isOpen: true);
|
|
SFXGameManagement.PlaySound("Bail Open", base.transform);
|
|
}
|
|
}
|
|
|
|
public void CloseBail()
|
|
{
|
|
if (!_isBailClose)
|
|
{
|
|
_isBailClose = true;
|
|
OpenBail(isOpen: false);
|
|
SFXGameManagement.PlaySound("Bail Close", base.transform);
|
|
}
|
|
}
|
|
|
|
public void SpinReel(float speed)
|
|
{
|
|
ReelUpdate(speed);
|
|
CloseBail();
|
|
}
|
|
|
|
public void SpoolUnwind(float speed)
|
|
{
|
|
float num = 0.25f;
|
|
float num2 = speed / num;
|
|
Vector3 localEulerAngles = spool.localEulerAngles;
|
|
localEulerAngles += rotateWorldUp * num2 * 90f;
|
|
spool.localEulerAngles = localEulerAngles;
|
|
}
|
|
|
|
public void SetDrag(float value)
|
|
{
|
|
_DragSetting = value;
|
|
}
|
|
|
|
private void ReelUpdate(float speed)
|
|
{
|
|
float num = speed * crankRotateSpeedMultiply;
|
|
crank.Rotate(Vector3.right, num * 360f);
|
|
Vector3 localEulerAngles = lineRoller.localEulerAngles;
|
|
localEulerAngles += rotateWorldUp * num * _ReelData.GearRatio * 360f;
|
|
lineRoller.localEulerAngles = localEulerAngles;
|
|
barrelCurvePos += num;
|
|
Vector3 localPosition = barrel.localPosition;
|
|
localPosition = startBarrelLocalPosition + rotateWorldUp * 0.01f * barrelMoveCurve.Evaluate(barrelCurvePos);
|
|
barrel.localPosition = localPosition;
|
|
}
|
|
|
|
public float TensioApply(float fishPowerMoment, float fishSpeed)
|
|
{
|
|
float num = _ReelData.MaxDrag * DragSetting;
|
|
float num2 = fishPowerMoment - num;
|
|
if (num2 > 0f && DragSetting < 1f)
|
|
{
|
|
float value = num2 / num * fishSpeed;
|
|
Debug.Log($"ryba nadmiar {num2}");
|
|
return Mathf.Clamp(value, 0f, fishSpeed) * Time.deltaTime;
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
public void Initialize(ReelData fishingSet)
|
|
{
|
|
_ReelData = fishingSet;
|
|
}
|
|
}
|