142 lines
3.5 KiB
C#
142 lines
3.5 KiB
C#
using System;
|
|
using PhysicsTools;
|
|
using UnityEngine;
|
|
|
|
public class FishingLineController : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class SegmentParameters
|
|
{
|
|
public float drag = 1f;
|
|
|
|
public float angularDrag = 1f;
|
|
|
|
public float swingLimit = 10f;
|
|
|
|
public bool gravity = true;
|
|
|
|
public float massNormal = 0.02f;
|
|
|
|
public float massFloat = 0.05f;
|
|
}
|
|
|
|
public bool updateIceCollision;
|
|
|
|
[Space(10f)]
|
|
public float iceCollisionForce = 100f;
|
|
|
|
public ForceMode iceCollisionForceMode;
|
|
|
|
public Vector2 ropeFlyIncMargin = new Vector2(0.2f, 0.5f);
|
|
|
|
public float ropeFlyNearMargin = 0.05f;
|
|
|
|
public float ropeFlyNearMarginFloat = 0.1f;
|
|
|
|
public float flyRateFactor = 1f;
|
|
|
|
[Space(10f)]
|
|
public float ropeFishIncMargin = 0.1f;
|
|
|
|
public float ropeFishFloatIncMargin = 0.1f;
|
|
|
|
public float ropeProtectionMargin = 0.2f;
|
|
|
|
public float ropeStretchThreshold = 5f;
|
|
|
|
public float ropeStretchBreakThreshold = 5f;
|
|
|
|
public float ropeStretchInstantBreakThreshold = 3f;
|
|
|
|
public float fishingLineLooseThreshold = 1f;
|
|
|
|
public float waterInteractiveMultiplier = 0.5f;
|
|
|
|
[Space(10f)]
|
|
public float fishTargetSpeedPullMultiplier = 0.07f;
|
|
|
|
[Header("Segment Parameters")]
|
|
public float tightThreshold = 0.95f;
|
|
|
|
public float underwaterThreshold;
|
|
|
|
public float nearSwingLimit = 50f;
|
|
|
|
public float nearSwingDistance = 7f;
|
|
|
|
public SegmentParameters idle = new SegmentParameters();
|
|
|
|
public SegmentParameters near = new SegmentParameters();
|
|
|
|
public SegmentParameters fly = new SegmentParameters();
|
|
|
|
public SegmentParameters tight = new SegmentParameters();
|
|
|
|
public SegmentParameters water = new SegmentParameters();
|
|
|
|
public SegmentParameters air = new SegmentParameters();
|
|
|
|
[Space(10f)]
|
|
public SegmentParameters floatWater = new SegmentParameters();
|
|
|
|
public SegmentParameters floatFly = new SegmentParameters();
|
|
|
|
[HideInInspector]
|
|
public SegmentParameters ret = new SegmentParameters();
|
|
|
|
[HideInInspector]
|
|
public FishingHands fishingHands;
|
|
|
|
private void Start()
|
|
{
|
|
fishingHands = GetComponent<FishingHands>();
|
|
}
|
|
|
|
public SegmentParameters GetSegmentParameters(Segment segment, int segmentId, float looseTensionFactor, float distance, bool isFlying)
|
|
{
|
|
if ((bool)segment.waterInteractive)
|
|
{
|
|
segment.meshRenderer.enabled = !isFlying && (double)segment.seg.transform.position.y > -0.1 && segmentId < 30;
|
|
segment.waterInteractive.enabled = segment.meshRenderer.enabled;
|
|
segment.waterInteractive.Multiplier = ((!segment.meshRenderer.enabled) ? 0f : waterInteractiveMultiplier);
|
|
}
|
|
if (isFlying)
|
|
{
|
|
return fly;
|
|
}
|
|
if (looseTensionFactor > tightThreshold)
|
|
{
|
|
return tight;
|
|
}
|
|
if (segment.seg.transform.position.y <= underwaterThreshold)
|
|
{
|
|
return water;
|
|
}
|
|
return BlendParameters(air, tight, looseTensionFactor, distance);
|
|
}
|
|
|
|
public SegmentParameters GetFloatSegmentParameters(Segment segment, float looseTensionFactor, bool isFlying)
|
|
{
|
|
if (isFlying)
|
|
{
|
|
return floatFly;
|
|
}
|
|
return floatWater;
|
|
}
|
|
|
|
public SegmentParameters BlendParameters(SegmentParameters s1, SegmentParameters s2, float blend, float distance)
|
|
{
|
|
ret.drag = Mathf.Lerp(s1.drag, s2.drag, blend);
|
|
ret.angularDrag = Mathf.Lerp(s1.angularDrag, s2.angularDrag, blend);
|
|
ret.swingLimit = Mathf.Lerp(s1.swingLimit, s2.swingLimit, blend);
|
|
ret.gravity = ((!(blend > 0.5f)) ? s1.gravity : s2.gravity);
|
|
ret.massNormal = Mathf.Lerp(s1.massNormal, s2.massNormal, blend);
|
|
ret.massFloat = Mathf.Lerp(s1.massFloat, s2.massFloat, blend);
|
|
if (distance < nearSwingDistance)
|
|
{
|
|
ret.swingLimit = nearSwingLimit;
|
|
}
|
|
return ret;
|
|
}
|
|
}
|