增加线测试代码

This commit is contained in:
2026-03-05 23:54:32 +08:00
parent e82f2ea6b7
commit 06146e3d07
3 changed files with 23 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ public class RopeFishLineEditor : Editor
if (GUILayout.Button("打印总长度"))
{
Debug.Log($"总长度={_target.GetCurrentLength()} 目标长度={_target.GetTargetLength()}");
Debug.Log($"总长度={_target.GetCurrentLength()} 目标长度={_target.GetTargetLength()} smoot={_target.GetLengthSmoothVel()} relLen={_target.GetLengthByPoints()}");
}
// serializedObject.Update();
// EditorGUILayout.PropertyField(lookAtPoint);

View File

@@ -236,6 +236,27 @@ public class Rope : MonoBehaviour
public float GetCurrentLength() => _currentLength;
public float GetTargetLength() => _targetLength;
public float GetLengthSmoothVel() => _lengthSmoothVel;
public float GetLengthByPoints()
{
if (_rPoints == null || _lineRenderer == null) return 0f;
int count = _lineRenderer.positionCount;
if (count < 2) return 0f;
float totalLength = 0f;
for (int i = 1; i < count; i++)
{
Vector3 a = _rPoints[i - 1];
Vector3 b = _rPoints[i];
totalLength += Vector3.Distance(a, b);
}
return totalLength;
}
private void FixedUpdate()
{
if (!startAnchor || !endAnchor) return;

View File

@@ -121,7 +121,7 @@ namespace NBF
public void SetObiRopeStretch(float value)
{
Log.Error($"SetObiRopeStretch={value}");
fishingRope.SetTargetLength(value - 0.2f);
fishingRope.SetTargetLength(value);
}
}
}