测试代码
This commit is contained in:
33
Assets/Scripts/ThirdParty/PhysicsTools/Rope.cs
vendored
33
Assets/Scripts/ThirdParty/PhysicsTools/Rope.cs
vendored
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
// using UltimateWater;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
@@ -535,9 +534,11 @@ namespace PhysicsTools
|
||||
float num3 = 1f;
|
||||
int num4 = lstSegments.Count;
|
||||
// if (num4 > 30 && GameController.Instance.useFastRopeDraw)
|
||||
// {
|
||||
// num4 = 30;
|
||||
// }
|
||||
if (num4 > 30)
|
||||
{
|
||||
num4 = 30;
|
||||
}
|
||||
|
||||
List<PosOri> list2 = new List<PosOri>();
|
||||
int num5 = 0;
|
||||
if (lstSegments.Count > 0)
|
||||
@@ -1172,7 +1173,7 @@ namespace PhysicsTools
|
||||
{
|
||||
if (lstSegments.Count < num + 1 + 1)
|
||||
{
|
||||
// UnityEngine.Debug.LogError("!!! changeLength lstSegments size error index !!!: " + num);
|
||||
UnityEngine.Debug.LogError("!!! changeLength lstSegments size error index !!!: " + num);
|
||||
// if (GameController.Instance.fishingPlayer.currentState == FishingPlayer.PlayerState.FISHING ||
|
||||
// GameController.Instance.fishingPlayer.currentState == FishingPlayer.PlayerState.ICE_FISHING)
|
||||
// {
|
||||
@@ -1450,22 +1451,22 @@ namespace PhysicsTools
|
||||
getSegmentProperties(), this);
|
||||
segment.seg.transform.parent = base.gameObject.transform;
|
||||
// if ((bool)GameController.Instance)
|
||||
// {
|
||||
// segment.meshRenderer.enabled = true;
|
||||
// segment.meshRenderer.material = GameController.Instance.waterInteractiveMaterial;
|
||||
// segment.meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
|
||||
// }
|
||||
// else
|
||||
{
|
||||
segment.meshRenderer.enabled = false;
|
||||
segment.meshRenderer.enabled = true;
|
||||
// segment.meshRenderer.material = GameController.Instance.waterInteractiveMaterial;
|
||||
segment.meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
|
||||
}
|
||||
|
||||
// if (totalLength <= 105f)
|
||||
// else
|
||||
// {
|
||||
// segment.waterInteractive = segment.seg.AddComponent<WaterInteractive>();
|
||||
// segment.waterInteractive.Multiplier = 1.5f;
|
||||
// segment.meshRenderer.enabled = false;
|
||||
// }
|
||||
|
||||
if (totalLength <= 105f)
|
||||
{
|
||||
// segment.waterInteractive = segment.seg.AddComponent<WaterInteractive>();
|
||||
// segment.waterInteractive.Multiplier = 1.5f;
|
||||
}
|
||||
|
||||
return segment;
|
||||
}
|
||||
|
||||
|
||||
3
Assets/Scripts/ThirdParty/PhysicsTools/Test.meta
vendored
Normal file
3
Assets/Scripts/ThirdParty/PhysicsTools/Test.meta
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2aeb581d8e0340a7b32560ea8d661608
|
||||
timeCreated: 1762030053
|
||||
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