250 lines
6.1 KiB
C#
250 lines
6.1 KiB
C#
using UnityEngine;
|
|
|
|
public class Lure : MonoBehaviour
|
|
{
|
|
public enum MoveType
|
|
{
|
|
None = 0,
|
|
PowolnyWleczony = 1,
|
|
Wleczony = 2,
|
|
Opadający = 3,
|
|
PowolnyOpadający = 4
|
|
}
|
|
|
|
public Transform childTransform;
|
|
|
|
public Transform[] hooks;
|
|
|
|
public Transform fishPoint;
|
|
|
|
[HideInInspector]
|
|
public Rigidbody linkConnectorUp;
|
|
|
|
public HingeJoint hingeJointUp;
|
|
|
|
[HideInInspector]
|
|
public FishingLine currentFishingLine;
|
|
|
|
[HideInInspector]
|
|
public FishStats takeFish;
|
|
|
|
[HideInInspector]
|
|
public Rigidbody rigidbody;
|
|
|
|
[HideInInspector]
|
|
public WaterDisplacementObject waterDisplacementObject;
|
|
|
|
private BaitStats baitStats;
|
|
|
|
private bool isRendererEnabled = true;
|
|
|
|
private Animator animator;
|
|
|
|
public ParticleSystem smuuggeParticle;
|
|
|
|
[HideInInspector]
|
|
public float percentEfficacy;
|
|
|
|
public MoveType LureMoveType = MoveType.Wleczony;
|
|
|
|
[HideInInspector]
|
|
public MoveType currentMoveType;
|
|
|
|
private MoveType newMoveType;
|
|
|
|
private float delayMoveTypeTimer;
|
|
|
|
private float moveTowardsFactor;
|
|
|
|
private float moveUpperFactor;
|
|
|
|
private void Start()
|
|
{
|
|
baitStats = GetComponent<BaitStats>();
|
|
rigidbody = GetComponent<Rigidbody>();
|
|
waterDisplacementObject = GetComponent<WaterDisplacementObject>();
|
|
animator = GetComponent<Animator>();
|
|
if (smuuggeParticle != null && smuuggeParticle.isPlaying)
|
|
{
|
|
smuuggeParticle.Stop();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
RotationToVelocity();
|
|
RotationHooks();
|
|
CheckIsCorrectTerrainPosition();
|
|
ShowWaterFX();
|
|
MoveTypeController();
|
|
if ((bool)takeFish)
|
|
{
|
|
if (isRendererEnabled)
|
|
{
|
|
EnableDisableMeshRenderers(value: false);
|
|
}
|
|
}
|
|
else if (!isRendererEnabled)
|
|
{
|
|
EnableDisableMeshRenderers(value: true);
|
|
}
|
|
}
|
|
|
|
private void MoveTypeController()
|
|
{
|
|
if (waterDisplacementObject.deepProbe.z == 0f)
|
|
{
|
|
moveTowardsFactor = 0f;
|
|
moveUpperFactor = 0f;
|
|
percentEfficacy = 0f;
|
|
currentMoveType = MoveType.None;
|
|
newMoveType = MoveType.None;
|
|
return;
|
|
}
|
|
float num = (Mathf.Abs(rigidbody.velocity.x) + Mathf.Abs(rigidbody.velocity.z)) * 0.5f;
|
|
moveTowardsFactor = Mathf.MoveTowards(moveTowardsFactor, Mathf.Clamp01(num * 1.5f), Time.deltaTime * 0.5f);
|
|
moveUpperFactor = Mathf.MoveTowards(moveUpperFactor, Mathf.Clamp01((0f - rigidbody.velocity.y) * 1.3f), Time.deltaTime * 0.5f);
|
|
if (moveTowardsFactor > 0.1f && moveTowardsFactor < 0.3f)
|
|
{
|
|
newMoveType = MoveType.PowolnyWleczony;
|
|
}
|
|
else if (moveTowardsFactor >= 0.3f && moveTowardsFactor < 0.7f)
|
|
{
|
|
newMoveType = MoveType.Wleczony;
|
|
}
|
|
else if (moveTowardsFactor <= 0.1f)
|
|
{
|
|
if (moveUpperFactor > 0f && moveUpperFactor < 0.4f)
|
|
{
|
|
newMoveType = MoveType.PowolnyOpadający;
|
|
}
|
|
else if (moveUpperFactor >= 0.4f && moveUpperFactor < 0.8f)
|
|
{
|
|
newMoveType = MoveType.Opadający;
|
|
}
|
|
else
|
|
{
|
|
newMoveType = MoveType.None;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
newMoveType = MoveType.None;
|
|
}
|
|
if (currentMoveType == LureMoveType)
|
|
{
|
|
percentEfficacy = Mathf.MoveTowards(percentEfficacy, 1f, Time.deltaTime * 0.1f);
|
|
}
|
|
else
|
|
{
|
|
percentEfficacy = Mathf.MoveTowards(percentEfficacy, 0f, Time.deltaTime * 0.5f);
|
|
}
|
|
if (newMoveType != currentMoveType)
|
|
{
|
|
delayMoveTypeTimer += Time.deltaTime;
|
|
if (delayMoveTypeTimer > 1f)
|
|
{
|
|
currentMoveType = newMoveType;
|
|
delayMoveTypeTimer = 0f;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CheckIsCorrectTerrainPosition()
|
|
{
|
|
if (waterDisplacementObject.deepProbe.z > 0f && waterDisplacementObject.deepProbe.x == 0f)
|
|
{
|
|
ScriptsHandler.Instance.m_PlayerMain.ResetCast();
|
|
}
|
|
}
|
|
|
|
public void Link(Rigidbody connector)
|
|
{
|
|
if (connector.transform.parent.GetComponent<LineHandler>().lineType == LineHandler.LineType.OneSegment)
|
|
{
|
|
currentFishingLine = connector.transform.parent.GetComponent<LineHandler>().currentRodFishingLineComponent;
|
|
if (!(currentFishingLine.lure != this))
|
|
{
|
|
currentFishingLine.lure = this;
|
|
linkConnectorUp = connector;
|
|
base.transform.position = linkConnectorUp.position;
|
|
hingeJointUp.connectedBody = linkConnectorUp;
|
|
linkConnectorUp.GetComponent<MeshRenderer>().enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RotationToVelocity()
|
|
{
|
|
if (waterDisplacementObject.deepProbe.z == 0f || (bool)takeFish)
|
|
{
|
|
animator.SetFloat("Speed", 0f);
|
|
rigidbody.freezeRotation = false;
|
|
return;
|
|
}
|
|
rigidbody.freezeRotation = true;
|
|
animator.SetFloat("Speed", rigidbody.velocity.sqrMagnitude);
|
|
Vector3 vector = new Vector3(rigidbody.velocity.x, 0f, rigidbody.velocity.z);
|
|
if (vector != Vector3.zero)
|
|
{
|
|
Quaternion b = Quaternion.LookRotation(vector, Vector3.up);
|
|
base.transform.rotation = Quaternion.Slerp(base.transform.rotation, b, rigidbody.velocity.magnitude * 5f * Time.deltaTime);
|
|
float num = Mathf.Clamp(rigidbody.velocity.magnitude, 0f, 5f);
|
|
rigidbody.AddForce(base.transform.right * childTransform.localEulerAngles.y * num * Time.deltaTime * 10f);
|
|
}
|
|
}
|
|
|
|
private void RotationHooks()
|
|
{
|
|
if ((bool)takeFish)
|
|
{
|
|
for (int i = 0; i < hooks.Length; i++)
|
|
{
|
|
hooks[i].localEulerAngles = Vector3.zero;
|
|
}
|
|
return;
|
|
}
|
|
Vector3 forward = new Vector3(rigidbody.velocity.x, rigidbody.velocity.y, rigidbody.velocity.z);
|
|
for (int j = 0; j < hooks.Length; j++)
|
|
{
|
|
hooks[j].rotation = Quaternion.LookRotation(forward, Vector3.up);
|
|
}
|
|
}
|
|
|
|
private void EnableDisableMeshRenderers(bool value)
|
|
{
|
|
MeshRenderer[] componentsInChildren = base.gameObject.GetComponentsInChildren<MeshRenderer>();
|
|
SkinnedMeshRenderer[] componentsInChildren2 = base.gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
|
|
MeshRenderer[] array = componentsInChildren;
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i].enabled = value;
|
|
}
|
|
SkinnedMeshRenderer[] array2 = componentsInChildren2;
|
|
for (int i = 0; i < array2.Length; i++)
|
|
{
|
|
array2[i].enabled = value;
|
|
}
|
|
isRendererEnabled = value;
|
|
}
|
|
|
|
private void ShowWaterFX()
|
|
{
|
|
if (smuuggeParticle == null)
|
|
{
|
|
return;
|
|
}
|
|
if (base.transform.position.y >= waterDisplacementObject.waterHeightPosition - 0.05f && base.transform.position.y <= waterDisplacementObject.waterHeightPosition + 0.05f && !takeFish && rigidbody.velocity.magnitude > 0.1f)
|
|
{
|
|
if (!smuuggeParticle.isEmitting)
|
|
{
|
|
smuuggeParticle.Play();
|
|
}
|
|
}
|
|
else if (smuuggeParticle.isPlaying)
|
|
{
|
|
smuuggeParticle.Stop();
|
|
}
|
|
}
|
|
}
|