测试代码
This commit is contained in:
145
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTest.cs
vendored
Normal file
145
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTest.cs
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace PhysicsTools
|
||||
{
|
||||
public class RopeTest : MonoBehaviour
|
||||
{
|
||||
public Rope rope;
|
||||
|
||||
public Transform startPosition;
|
||||
|
||||
public Transform throwPosition;
|
||||
|
||||
public Transform ropeStart;
|
||||
|
||||
public Transform ropeFloat;
|
||||
|
||||
public Transform ropeBait;
|
||||
|
||||
public Transform fishingPlayer;
|
||||
|
||||
public bool updateDistance;
|
||||
|
||||
public float incDist = 0.1f;
|
||||
|
||||
public float incDistThrow = 0.5f;
|
||||
|
||||
public float incDistWater = 0.1f;
|
||||
|
||||
public float maxLength = 25f;
|
||||
|
||||
public Vector3 throwDir = Vector3.zero;
|
||||
|
||||
public float throwForce = 1000f;
|
||||
|
||||
public float prevDistance = -1f;
|
||||
|
||||
public float currentDistance = -1f;
|
||||
|
||||
public float reelInSpeed = 0.01f;
|
||||
|
||||
[HideInInspector] public float reelInFactor;
|
||||
|
||||
private bool hitWater;
|
||||
|
||||
private bool wasThrown;
|
||||
|
||||
public bool hasFish;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
prevDistance = (currentDistance = CalculateDistance());
|
||||
ResetBait(true);
|
||||
ropeStart.parent = null;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (hitWater && rope.getLength() < 1f)
|
||||
{
|
||||
ResetBait();
|
||||
return;
|
||||
}
|
||||
|
||||
reelInFactor = 0f;
|
||||
if (Input.GetKey(KeyCode.N))
|
||||
{
|
||||
reelInFactor = reelInSpeed;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.M))
|
||||
{
|
||||
reelInFactor = 0f - reelInSpeed;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.B))
|
||||
{
|
||||
ThrowBait();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.V))
|
||||
{
|
||||
ResetBait(true);
|
||||
}
|
||||
|
||||
ReelIn(reelInFactor);
|
||||
if (!hitWater && ropeStart.position.y <= 0f)
|
||||
{
|
||||
incDist = incDistWater;
|
||||
hitWater = true;
|
||||
}
|
||||
|
||||
ropeStart.GetComponent<Rigidbody>().linearDamping = ((!(ropeStart.position.y <= 0f)) ? 0f : 5f);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
prevDistance = currentDistance;
|
||||
currentDistance = CalculateDistance();
|
||||
if (updateDistance && (!hitWater || hasFish) && rope.getLength() < maxLength && wasThrown &&
|
||||
rope.getLength() < currentDistance + incDist)
|
||||
{
|
||||
rope.changeLength(currentDistance - rope.getLength() + incDist);
|
||||
}
|
||||
|
||||
Debug.Log("currentDistance: " + currentDistance + " rope.getLength(): " + rope.getLength());
|
||||
}
|
||||
|
||||
public void ReelIn(float reelIn)
|
||||
{
|
||||
if (reelIn < 0f && rope.getLength() <= rope.segPropertiesCylinder.length)
|
||||
{
|
||||
reelIn = 0f;
|
||||
}
|
||||
|
||||
rope.rate = reelIn;
|
||||
}
|
||||
|
||||
public float CalculateDistance()
|
||||
{
|
||||
return Vector3.Distance(ropeStart.position, ropeFloat.position);
|
||||
}
|
||||
|
||||
public void ThrowBait()
|
||||
{
|
||||
incDist = incDistThrow;
|
||||
ropeStart.position = throwPosition.position;
|
||||
rope.regenerateRope(true);
|
||||
ropeStart.GetComponent<Rigidbody>().AddForce((fishingPlayer.forward + throwDir).normalized * throwForce);
|
||||
Debug.DrawLine(ropeStart.position,
|
||||
ropeStart.position + (fishingPlayer.forward + throwDir).normalized * throwForce, Color.yellow, 5f);
|
||||
wasThrown = true;
|
||||
}
|
||||
|
||||
public void ResetBait(bool quick = false)
|
||||
{
|
||||
if (quick)
|
||||
{
|
||||
ropeStart.position = startPosition.position;
|
||||
rope.regenerateRope(true);
|
||||
}
|
||||
|
||||
hitWater = false;
|
||||
wasThrown = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTest.cs.meta
vendored
Normal file
3
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTest.cs.meta
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8120306974a64ee3b78322d877915631
|
||||
timeCreated: 1762029973
|
||||
85
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTestLogic.cs
vendored
Normal file
85
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTestLogic.cs
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
// using UnityEngine;
|
||||
//
|
||||
// namespace PhysicsTools
|
||||
// {
|
||||
// public class RopeTestLogic : MonoBehaviour
|
||||
// {
|
||||
// public GameObject fishingRod;
|
||||
//
|
||||
// public GameObject bait;
|
||||
//
|
||||
// public GameObject baitStartPos;
|
||||
//
|
||||
// public GameObject rodEndPos;
|
||||
//
|
||||
// public UltimateRope rope;
|
||||
//
|
||||
// public float throwStrength = 10f;
|
||||
//
|
||||
// public float ropeLengthMargin = 3f;
|
||||
//
|
||||
// private bool isThrown;
|
||||
//
|
||||
// private void Start()
|
||||
// {
|
||||
// rope.Regenerate();
|
||||
// rope.GetComponent<RopeAdditionalParams>().UpdateNodes(rope);
|
||||
// }
|
||||
//
|
||||
// private void Update()
|
||||
// {
|
||||
// if (Input.GetKeyDown(KeyCode.T))
|
||||
// {
|
||||
// ThrowBait();
|
||||
// }
|
||||
//
|
||||
// if (Input.GetKeyDown(KeyCode.R))
|
||||
// {
|
||||
// ResetBait();
|
||||
// }
|
||||
//
|
||||
// if (Input.GetKeyDown(KeyCode.Z))
|
||||
// {
|
||||
// rope.ExtendRope(UltimateRope.ERopeExtensionMode.LinearExtensionIncrement, -0.1f);
|
||||
// }
|
||||
// else if (Input.GetKeyDown(KeyCode.X))
|
||||
// {
|
||||
// rope.ExtendRope(UltimateRope.ERopeExtensionMode.LinearExtensionIncrement, 0.1f);
|
||||
// }
|
||||
//
|
||||
// if (isThrown)
|
||||
// {
|
||||
// UpdateRope();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void UpdateRope()
|
||||
// {
|
||||
// float num = Vector3.Distance(rodEndPos.transform.position, bait.transform.position);
|
||||
// if (rope.m_fCurrentExtension < num + ropeLengthMargin - rope.RopeNodes[0].fLength)
|
||||
// {
|
||||
// rope.ExtendRope(UltimateRope.ERopeExtensionMode.LinearExtensionIncrement,
|
||||
// num + ropeLengthMargin - rope.RopeNodes[0].fLength - rope.m_fCurrentExtension);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void ThrowBait()
|
||||
// {
|
||||
// bait.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
|
||||
// Vector3 forward = base.transform.forward;
|
||||
// bait.GetComponent<Rigidbody>().isKinematic = false;
|
||||
// bait.GetComponent<Rigidbody>().AddForce(forward * throwStrength);
|
||||
// isThrown = true;
|
||||
// }
|
||||
//
|
||||
// public void ResetBait()
|
||||
// {
|
||||
// bait.transform.position = baitStartPos.transform.position;
|
||||
// bait.GetComponent<Rigidbody>().isKinematic = true;
|
||||
// bait.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
// bait.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
|
||||
// rope.ExtendRope(UltimateRope.ERopeExtensionMode.LinearExtensionIncrement, 0f - rope.m_fCurrentExtension);
|
||||
// isThrown = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
3
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTestLogic.cs.meta
vendored
Normal file
3
Assets/Scripts/ThirdParty/PhysicsTools/Test/RopeTestLogic.cs.meta
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15b3231410b74742829eccac62da7670
|
||||
timeCreated: 1762030063
|
||||
Reference in New Issue
Block a user