121 lines
2.8 KiB
C#
121 lines
2.8 KiB
C#
using System;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class FishingRodController : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class PhysicsParameters
|
|
{
|
|
public float jointTopDrivePositionSpring = 1500f;
|
|
|
|
public float jointTopDrivePositionDamper = 1f;
|
|
|
|
public float jointTopDriveMaximumForce = float.MaxValue;
|
|
|
|
public float rigidbodyMass = 130f;
|
|
}
|
|
|
|
[ReadOnly]
|
|
public FishingRod fishingRod;
|
|
|
|
[ReadOnly]
|
|
public ConfigurableJoint jointTop;
|
|
|
|
[ReadOnly]
|
|
public ConfigurableJoint jointBottom;
|
|
|
|
[ReadOnly]
|
|
public Rigidbody rigidbody;
|
|
|
|
public float distanceToAttachedFactor = 5f;
|
|
|
|
public float dirAddHack = 0.04f;
|
|
|
|
public bool clampBendDir;
|
|
|
|
public Vector2 maxBendAngle = new Vector2(-45f, 110f);
|
|
|
|
public Vector2 maxBendAngleIce = new Vector2(-45f, 190f);
|
|
|
|
public float physicsCubeWidth = 0.05f;
|
|
|
|
public PhysicsParameters normalParams = new PhysicsParameters();
|
|
|
|
public PhysicsParameters iceParams = new PhysicsParameters();
|
|
|
|
public PhysicsParameters flyParams = new PhysicsParameters();
|
|
|
|
public PhysicsParameters junkParams = new PhysicsParameters();
|
|
|
|
[HideInInspector]
|
|
public PhysicsParameters currentParams;
|
|
|
|
[HideInInspector]
|
|
public PhysicsParameters nextParams;
|
|
|
|
[ReadOnly]
|
|
public JointDrive jointTopDrive = default(JointDrive);
|
|
|
|
[HideInInspector]
|
|
public GameController gameController;
|
|
|
|
public void Initialize()
|
|
{
|
|
gameController = GameController.Instance;
|
|
if ((bool)fishingRod.rodPhysics)
|
|
{
|
|
ConfigurableJoint[] components = fishingRod.rodPhysics.GetComponents<ConfigurableJoint>();
|
|
if (components[0].anchor.y == 0f)
|
|
{
|
|
jointBottom = components[0];
|
|
jointTop = components[1];
|
|
}
|
|
else
|
|
{
|
|
jointBottom = components[1];
|
|
jointTop = components[0];
|
|
}
|
|
rigidbody = fishingRod.rodPhysics.GetComponent<Rigidbody>();
|
|
currentParams = flyParams;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
physicsCubeWidth = 0f;
|
|
}
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!gameController.iceLevel && !fishingRod.fishingHands.ThrowObjectOnWater())
|
|
{
|
|
nextParams = flyParams;
|
|
}
|
|
else
|
|
{
|
|
nextParams = ((!gameController.iceLevel) ? normalParams : iceParams);
|
|
}
|
|
if (currentParams != nextParams)
|
|
{
|
|
currentParams = nextParams;
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if (!(fishingRod.rodPhysics == null))
|
|
{
|
|
jointTopDrive.positionSpring = currentParams.jointTopDrivePositionSpring;
|
|
jointTopDrive.positionDamper = currentParams.jointTopDrivePositionDamper;
|
|
jointTopDrive.maximumForce = currentParams.jointTopDriveMaximumForce;
|
|
jointTop.xDrive = jointTopDrive;
|
|
jointTop.yDrive = jointTopDrive;
|
|
jointTop.zDrive = jointTopDrive;
|
|
rigidbody.mass = currentParams.rigidbodyMass;
|
|
fishingRod.rodPhysics.transform.localScale = new Vector3(physicsCubeWidth, fishingRod.rodPhysics.transform.localScale.y, physicsCubeWidth);
|
|
}
|
|
}
|
|
}
|