From 3affe183f7382a6464ba78aad04e3dc30e962501 Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Mon, 23 Feb 2026 21:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BA=BF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Line/fishing line float set.prefab | 6 +++ Assets/Scripts/Editor/RopeEditor.cs | 29 -------------- Assets/Scripts/Fishing/Rope/Rope.cs | 40 +++++++++++-------- Assets/Scripts/Fishing/Tackle/FLine.cs | 4 +- 4 files changed, 33 insertions(+), 46 deletions(-) diff --git a/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab b/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab index 5ca0cb3cd..940aed557 100644 --- a/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab +++ b/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab @@ -59,6 +59,9 @@ MonoBehaviour: lengthChangeVelocityKill: 0.6 minSlack: 0.002 headMinLen: 0.01 + collisionMask: + serializedVersion: 2 + m_Bits: 0 constrainToGround: 1 groundMask: serializedVersion: 2 @@ -672,6 +675,9 @@ MonoBehaviour: lengthChangeVelocityKill: 0.6 minSlack: 0.002 headMinLen: 0.01 + collisionMask: + serializedVersion: 2 + m_Bits: 0 constrainToGround: 1 groundMask: serializedVersion: 2 diff --git a/Assets/Scripts/Editor/RopeEditor.cs b/Assets/Scripts/Editor/RopeEditor.cs index 3498e1499..528f4239d 100644 --- a/Assets/Scripts/Editor/RopeEditor.cs +++ b/Assets/Scripts/Editor/RopeEditor.cs @@ -15,35 +15,6 @@ public class RopeFishLineEditor : Editor public override void OnInspectorGUI() { base.OnInspectorGUI(); - if (GUILayout.Button("增加0.5长度")) - { - _target.AddTargetLength(0.5f); - } - - if (GUILayout.Button("减小0.5长度")) - { - _target.AddTargetLength(-0.5f); - } - - if (GUILayout.Button("增加0.1长度")) - { - _target.AddTargetLength(0.1f); - } - - if (GUILayout.Button("减小0.1长度")) - { - _target.AddTargetLength(-0.1f); - } - - if (GUILayout.Button("增加0.01长度")) - { - _target.AddTargetLength(0.01f); - } - - if (GUILayout.Button("减小0.01长度")) - { - _target.AddTargetLength(-0.01f); - } if (GUILayout.Button("打印总长度")) diff --git a/Assets/Scripts/Fishing/Rope/Rope.cs b/Assets/Scripts/Fishing/Rope/Rope.cs index bb6c0c1fb..25380c5ac 100644 --- a/Assets/Scripts/Fishing/Rope/Rope.cs +++ b/Assets/Scripts/Fishing/Rope/Rope.cs @@ -41,6 +41,11 @@ public class Rope : MonoBehaviour [Header("Head Segment Clamp")] [Tooltip("第一段(起点->第1节点)允许的最小长度,避免收线时第一段被压到0导致数值炸")] [SerializeField, Min(0.0001f)] private float headMinLen = 0.01f; + + [Header("Collision Filter")] + [SerializeField, Tooltip("只对这些Layer进行物理检测(Raycast/SphereCast等)。不在这里的层完全不检测。")] + private LayerMask collisionMask = ~0; + [Header("Simple Ground/Water Constraint (Cheap)")] [SerializeField] private bool constrainToGround = true; @@ -116,6 +121,10 @@ public class Rope : MonoBehaviour maxPhysicsNodes = Mathf.Max(maxPhysicsNodes, minPhysicsNodes); headMinLen = Mathf.Max(headMinLen, 0.0001f); + + // 如果你希望只用一个mask控制,避免 groundMask 忘了配 + if (groundMask == ~0) + groundMask = collisionMask; } private void InitLengthSystem() @@ -129,12 +138,13 @@ public class Rope : MonoBehaviour private void AllocateAndInitNodes() { // 若锚点存在:最小长度就是两锚点直线距离 + minSlack(防抖) - if (startAnchor && endAnchor) - { - float minFeasible = Vector3.Distance(startAnchor.position, endAnchor.position) + minSlack; - currentLength = Mathf.Max(currentLength, minFeasible); - targetLength = Mathf.Max(targetLength, minFeasible); - } + // if (startAnchor && endAnchor) + // { + // float minFeasible = Vector3.Distance(startAnchor.position, endAnchor.position) + minSlack; + // minFeasible -= 0.2f; + // currentLength = Mathf.Max(currentLength, minFeasible); + // targetLength = Mathf.Max(targetLength, minFeasible); + // } physicsNodes = Mathf.Clamp(ComputeDesiredNodes(currentLength), 2, maxPhysicsNodes); pCurr = new Vector3[physicsNodes]; @@ -170,12 +180,7 @@ public class Rope : MonoBehaviour { targetLength = Mathf.Max(0f, lengthMeters); } - - /// 增加/减少目标总长度(米)。正数放线,负数收线。 - public void AddTargetLength(float deltaMeters) - { - SetTargetLength(targetLength + deltaMeters); - } + public float GetCurrentLength() => currentLength; public float GetTargetLength() => targetLength; @@ -224,8 +229,9 @@ public class Rope : MonoBehaviour private void UpdateLengthSmooth() { - float anchorDist = Vector3.Distance(startAnchor.position, endAnchor.position); - float minFeasible = anchorDist + minSlack; + // float anchorDist = Vector3.Distance(startAnchor.position, endAnchor.position); + // float minFeasible = anchorDist + minSlack; + float minFeasible = 0.01f; // ✅ 最小长度 = 起点终点直线距离(+slack),最大不限制 float desired = Mathf.Max(targetLength, minFeasible); @@ -396,6 +402,8 @@ public class Rope : MonoBehaviour private void ConstrainToGroundAndWater() { + int groundLayerMask = collisionMask & groundMask; // ✅ 统一过滤:只检测指定层 + for (int i = 1; i < physicsNodes - 1; i++) { Vector3 p = pCurr[i]; @@ -406,10 +414,10 @@ public class Rope : MonoBehaviour if (p.y < minY) p.y = minY; } - if (constrainToGround) + if (constrainToGround && groundLayerMask != 0) { Vector3 origin = p + Vector3.up * groundCastHeight; - if (Physics.Raycast(origin, Vector3.down, out RaycastHit hit, groundCastDistance, groundMask, + if (Physics.Raycast(origin, Vector3.down, out RaycastHit hit, groundCastDistance, groundLayerMask, QueryTriggerInteraction.Ignore)) { float minY = hit.point.y + groundRadius; diff --git a/Assets/Scripts/Fishing/Tackle/FLine.cs b/Assets/Scripts/Fishing/Tackle/FLine.cs index 4ac27c021..964bca9e2 100644 --- a/Assets/Scripts/Fishing/Tackle/FLine.cs +++ b/Assets/Scripts/Fishing/Tackle/FLine.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using NBC; // using Obi; using UnityEngine; @@ -87,7 +88,8 @@ namespace NBF public void SetObiRopeStretch(float value) { - fishingRope.SetTargetLength(value); + Log.Error($"SetObiRopeStretch={value}"); + fishingRope.SetTargetLength(value-0.2f); } } } \ No newline at end of file