修改鱼线

This commit is contained in:
2026-03-12 23:08:05 +08:00
parent 98cd3a4aba
commit 2be6ab915a
8 changed files with 222 additions and 241 deletions

View File

@@ -18658,53 +18658,8 @@ MonoBehaviour:
- {fileID: 102900000, guid: aa3f5467c0c153642ac320466aee0ec1, type: 3}
FilterEnum: 0
Filter: '*'
- Path: Assets/ResRaw/Prefabs/Line/FishingRopeLong.asset
Address: Plyaer/FishingRopeLong
Type: Missing
Bundle: main/plyaer.bundle
Tags:
Group:
Name: Plyaer
Enable: 1
BundleMode: 0
AddressMode: 2
Tags:
Collectors:
- {fileID: 102900000, guid: aa3f5467c0c153642ac320466aee0ec1, type: 3}
FilterEnum: 0
Filter: '*'
- Path: Assets/ResRaw/Prefabs/Line/FishingRopeLong2.asset
Address: Plyaer/FishingRopeLong2
Type: Missing
Bundle: main/plyaer.bundle
Tags:
Group:
Name: Plyaer
Enable: 1
BundleMode: 0
AddressMode: 2
Tags:
Collectors:
- {fileID: 102900000, guid: aa3f5467c0c153642ac320466aee0ec1, type: 3}
FilterEnum: 0
Filter: '*'
- Path: Assets/ResRaw/Prefabs/Line/FishingRopeShort.asset
Address: Plyaer/FishingRopeShort
Type: Missing
Bundle: main/plyaer.bundle
Tags:
Group:
Name: Plyaer
Enable: 1
BundleMode: 0
AddressMode: 2
Tags:
Collectors:
- {fileID: 102900000, guid: aa3f5467c0c153642ac320466aee0ec1, type: 3}
FilterEnum: 0
Filter: '*'
- Path: Assets/ResRaw/Prefabs/Line/Float (4).prefab
Address: Plyaer/Float (4)
- Path: Assets/ResRaw/Prefabs/Line/LineHand1.prefab
Address: Plyaer/LineHand1
Type: GameObject
Bundle: main/plyaer.bundle
Tags:
@@ -18733,36 +18688,6 @@ MonoBehaviour:
- {fileID: 102900000, guid: aa3f5467c0c153642ac320466aee0ec1, type: 3}
FilterEnum: 0
Filter: '*'
- Path: Assets/ResRaw/Prefabs/Line/RopeSegment_4.asset
Address: Plyaer/RopeSegment_4
Type: Missing
Bundle: main/plyaer.bundle
Tags:
Group:
Name: Plyaer
Enable: 1
BundleMode: 0
AddressMode: 2
Tags:
Collectors:
- {fileID: 102900000, guid: aa3f5467c0c153642ac320466aee0ec1, type: 3}
FilterEnum: 0
Filter: '*'
- Path: Assets/ResRaw/Prefabs/Line/Spool.mat
Address: Plyaer/Spool
Type: Material
Bundle: main/plyaer.bundle
Tags:
Group:
Name: Plyaer
Enable: 1
BundleMode: 0
AddressMode: 2
Tags:
Collectors:
- {fileID: 102900000, guid: aa3f5467c0c153642ac320466aee0ec1, type: 3}
FilterEnum: 0
Filter: '*'
- Path: Assets/ResRaw/Prefabs/Player/Anim/AnimationClip/CameraCrouch.anim
Address: Plyaer/CameraCrouch
Type: AnimationClip

View File

@@ -26,7 +26,7 @@ RenderSettings:
m_AmbientIntensity: 0.8050667
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.8679245, g: 0.8679245, b: 0.8679245, a: 1}
m_SkyboxMaterial: {fileID: 1948842527}
m_SkyboxMaterial: {fileID: 1352152231}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
@@ -594,10 +594,7 @@ MonoBehaviour:
_Resolution: 384
_GeometryDownSampleFactor: 2
_ExtentsSizeMultiplier: 100
_MultipleViewpoints: 0
_Viewpoint: {fileID: 0}
_CameraExclusions: -1
_DataBackgroundMode: 3
_CenterOfDetailDisplacementCorrection: 1
_SampleTerrainHeightForScale: 1
_ForceScaleChangeSmoothing: 0
@@ -633,11 +630,10 @@ MonoBehaviour:
_Portals:
rid: 2003882626816671964
_ShowWaterProxyPlane: 0
_EditModeFrameRate: 30
_FollowSceneCamera: 1
_EditorMultipleViewpoints: 1
_HeightQueries: 1
_Debug:
_SimulatePaused: 0
_AttachDebugGUI: 0
_ShowHiddenObjects: 0
_DisableFollowViewpoint: 0
@@ -645,8 +641,6 @@ MonoBehaviour:
_LogScaleChange: 0
_PauseOnScaleChange: 0
_IgnoreWavesForScaleChange: 0
_OverrideScale: 0
_ScaleOverride: 0
_ForceNoGraphics: 0
_Resources: {fileID: 11400000, guid: 0817af17dea584e5382e6216db162d4a, type: 2}
references:
@@ -657,7 +651,6 @@ MonoBehaviour:
data:
_Version: 0
_Enabled: 1
_MeshType: 0
_Layer: 4
_Material: {fileID: 2100000, guid: 5f4abc1146fb7bb44bbf906676601ad4, type: 2}
_VolumeMaterial: {fileID: 0}
@@ -665,7 +658,6 @@ MonoBehaviour:
_CastShadows: 0
_WaterBodyCulling: 1
_TimeSliceBoundsUpdateFrameCount: 1
_CameraExclusions: 6
_SurfaceSelfIntersectionFixMode: 4
_AllowRenderQueueSorting: 0
_Debug:
@@ -679,17 +671,13 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 100
_TextureFormat: 48
_Blur: 0
_BlurIterations: 1
_QuerySource: 1
_MaximumQueryCount: 4096
_CollisionLayers: -1
_BakedWaveData: {fileID: 0}
_WaveSampling: 0
_WaveResolutionMultiplier: 1
_AttenuationInShallows: 0.95
_ShallowsMaximumDepth: 1000
_CollisionSource: 2
_CollisionLayers: -1
_MaximumQueryCount: 4096
_BakedWaveData: {fileID: 0}
- rid: 2003882626816671951
type: {class: DepthLod, ns: WaveHarmonic.Crest, asm: WaveHarmonic.Crest}
data:
@@ -698,10 +686,6 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 100
_TextureFormat: 46
_Blur: 0
_BlurIterations: 1
_QuerySource: 1
_MaximumQueryCount: 512
_IncludeTerrainHeight: 1
_EnableSignedDistanceFields: 1
- rid: 2003882626816671952
@@ -712,8 +696,6 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 300
_TextureFormat: 45
_Blur: 0
_BlurIterations: 4
- rid: 2003882626816671953
type: {class: FoamLod, ns: WaveHarmonic.Crest, asm: WaveHarmonic.Crest}
data:
@@ -722,8 +704,6 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 100
_TextureFormat: 45
_Blur: 0
_BlurIterations: 1
_SimulationFrequency: 30
_Prewarm: 1
_Settings: {fileID: 0}
@@ -735,8 +715,6 @@ MonoBehaviour:
_Resolution: 512
_TextureFormatMode: 300
_TextureFormat: 46
_Blur: 0
_BlurIterations: 1
_SimulationFrequency: 60
_AttenuationInShallows: 1
_Settings: {fileID: 0}
@@ -748,10 +726,6 @@ MonoBehaviour:
_Resolution: 128
_TextureFormatMode: 100
_TextureFormat: 46
_Blur: 0
_BlurIterations: 1
_QuerySource: 1
_MaximumQueryCount: 1024
- rid: 2003882626816671956
type: {class: ShadowLod, ns: WaveHarmonic.Crest, asm: WaveHarmonic.Crest}
data:
@@ -760,8 +734,6 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 100
_TextureFormat: 6
_Blur: 1
_BlurIterations: 1
_SimulationFrequency: 60
_DynamicSoftShadows: 1
_SoftJitterExtinctionFactor: 0.75
@@ -779,8 +751,6 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 200
_TextureFormat: 23
_Blur: 0
_BlurIterations: 1
_ShorelineColorSource: 0
_ShorelineColor: {r: 0.513, g: 1, b: 1, a: 0.153}
_ShorelineColorMaximumDistance: 10
@@ -793,8 +763,6 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 200
_TextureFormat: 23
_Blur: 0
_BlurIterations: 1
_ShorelineColorSource: 0
_ShorelineColor: {r: 0, g: 0.588, b: 1, a: 1}
_ShorelineColorMaximumDistance: 10
@@ -807,8 +775,6 @@ MonoBehaviour:
_Resolution: 256
_TextureFormatMode: 100
_TextureFormat: 5
_Blur: 0
_BlurIterations: 1
_DefaultClippingState: 0
- rid: 2003882626816671960
type: {class: AlbedoLod, ns: WaveHarmonic.Crest, asm: WaveHarmonic.Crest}
@@ -818,8 +784,6 @@ MonoBehaviour:
_Resolution: 768
_TextureFormatMode: 100
_TextureFormat: 8
_Blur: 0
_BlurIterations: 1
- rid: 2003882626816671961
type: {class: WaterReflections, ns: WaveHarmonic.Crest, asm: WaveHarmonic.Crest}
data:
@@ -830,13 +794,13 @@ MonoBehaviour:
serializedVersion: 2
m_Bits: 1
_Resolution: 256
_Overscan: 1.5
_RenderOnlySingleCamera: 0
_Sky: 1
_DisablePixelLights: 1
_DisableShadows: 1
_HDR: 0
_Stencil: 0
_AllowMSAA: 0
_QualitySettingsOverride:
_OverrideLodBias: 0
_LodBias: 0.5
@@ -855,18 +819,17 @@ MonoBehaviour:
_Debug:
_ShowHiddenObjects: 0
_DisableRecursiveRendering: 0
_ForceCompatibility: 0
_AllowMSAA: 0
- rid: 2003882626816671962
type: {class: UnderwaterRenderer, ns: WaveHarmonic.Crest, asm: WaveHarmonic.Crest}
data:
_Version: 0
_Enabled: 1
_Layer: 4
_Material: {fileID: 2100000, guid: f2b096e4d95e646c49d48ece0afa0547, type: 2}
_EnvironmentalLightingEnable: 0
_EnvironmentalLightingWeight: 1
_EnvironmentalLightingVolumeProfile: {fileID: 0}
_CameraExclusions: 6
_AllCameras: 0
_CopyWaterMaterialParametersEachFrame: 1
_FarPlaneMultiplier: 0.68
_CullLimit: 0.001
@@ -877,15 +840,12 @@ MonoBehaviour:
_DisableHeightAboveWaterOptimization: 0
_DisableArtifactCorrection: 0
_OnlyReflectionCameras: 0
_Version: 0
_AllCameras: 0
- rid: 2003882626816671963
type: {class: Meniscus, ns: WaveHarmonic.Crest, asm: WaveHarmonic.Crest}
data:
_Enabled: 1
_Layer: 4
_Material: {fileID: 2100000, guid: 238e45299a5ec46308e9bf99ddf67963, type: 2}
_CameraExclusions: 6
- rid: 2003882626816671964
type: {class: PortalRenderer, ns: WaveHarmonic.Crest.Portals, asm: WaveHarmonic.Crest}
data:
@@ -1224,6 +1184,54 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!21 &1352152231
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Enviro/Skybox
m_Shader: {fileID: 4800000, guid: 34fee0a1b19b20b45aea7483b5f757da, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _GalaxyTex:
m_Texture: {fileID: 8900000, guid: 5734983fc81450b4187c3cfa5985edef, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MoonGlowTex:
m_Texture: {fileID: 2800000, guid: 6838e0810da4e49488b5d9a6ee76eb07, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MoonTex:
m_Texture: {fileID: 2800000, guid: c6fd9f694390e0245b6dca5812065950, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _StarsTex:
m_Texture: {fileID: 8900000, guid: b5a7175da0f133b4d951c19c9c2cebfc, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SunTex:
m_Texture: {fileID: 2800000, guid: c95bed5306e94f24ba5802d841607ac7, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors: []
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!1 &1511791494
GameObject:
m_ObjectHideFlags: 0
@@ -1440,54 +1448,6 @@ MonoBehaviour:
_MaximumSpeed: 100
_WarnOnSpeedClamp: 0
_DebugSubsteps: 0
--- !u!21 &1948842527
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Enviro/Skybox
m_Shader: {fileID: 4800000, guid: 34fee0a1b19b20b45aea7483b5f757da, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _GalaxyTex:
m_Texture: {fileID: 8900000, guid: 5734983fc81450b4187c3cfa5985edef, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MoonGlowTex:
m_Texture: {fileID: 2800000, guid: 6838e0810da4e49488b5d9a6ee76eb07, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MoonTex:
m_Texture: {fileID: 2800000, guid: c6fd9f694390e0245b6dca5812065950, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _StarsTex:
m_Texture: {fileID: 8900000, guid: b5a7175da0f133b4d951c19c9c2cebfc, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SunTex:
m_Texture: {fileID: 2800000, guid: c95bed5306e94f24ba5802d841607ac7, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors: []
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!1 &2034802495
GameObject:
m_ObjectHideFlags: 0
@@ -1504,7 +1464,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &2034802496
Transform:
m_ObjectHideFlags: 0

View File

@@ -22,7 +22,7 @@ namespace NBF
#region Rod专属
private bool _stretchRope;
private bool _stretchRope = true;
public bool StretchRope
{

View File

@@ -30,6 +30,7 @@ namespace NBF
{
protected override void Update(PlayerInput self)
{
self.UpdateInput();
self.UpdateMove();
}
}
@@ -46,6 +47,26 @@ namespace NBF
#region Input
private void UpdateInput()
{
if (Input.GetKeyDown(KeyCode.Alpha0))
{
// SetLineLength(lineLength);
}
else if (Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.Equals))
{
Player.HandItem.LineLength += 0.1f;
// lineLength += 0.1f;
// SetLineLength(lineLength);
}
else if (Input.GetKeyDown(KeyCode.Minus))
{
Player.HandItem.LineLength -= 0.1f;
// lineLength -= 0.1f;
// SetLineLength(lineLength);
}
}
private void AddInputEvent()
{
InputManager.OnPlayerPerformed += OnPlayerCanceled;

View File

@@ -55,17 +55,40 @@ public class Rope : MonoBehaviour
[SerializeField, Min(0f)] private float groundRadius = 0.01f;
[SerializeField, Min(0f)] private float groundCastHeight = 1.0f;
[SerializeField, Min(0.01f)] private float groundCastDistance = 2.5f;
[SerializeField, Range(1, 8), Tooltip("每隔多少个节点做一次地面检测;越大越省")]
private int groundSampleStep = 3;
[SerializeField, Tooltip("未采样的点用插值还是直接拷贝邻近采样值")]
private bool groundInterpolate = true;
[SerializeField, Range(1, 8), Tooltip("每隔多少次FixedUpdate更新一次地面约束")]
private int groundUpdateEvery = 2;
private int _groundFrameCounter;
[Header("Simple Water Float (Cheap)")]
[SerializeField, Tooltip("绳子落到水面以下时,是否把节点约束回水面")]
private bool constrainToWaterSurface = true;
[SerializeField, Tooltip("静态水面高度;如果你后面接波浪水面,可改成采样函数")]
private float waterLevelY = 0f;
[SerializeField, Min(0f), Tooltip("把线抬到水面上方一点,避免视觉穿插")]
private float waterSurfaceOffset = 0.002f;
[SerializeField, Range(1, 8), Tooltip("每隔多少个节点做一次水面约束采样;越大越省")]
private int waterSampleStep = 2;
[SerializeField, Tooltip("未采样节点是否插值水面高度")]
private bool waterInterpolate = true;
[SerializeField, Range(1, 8), Tooltip("每隔多少次FixedUpdate更新一次水面约束")]
private int waterUpdateEvery = 1;
[SerializeField, Range(0, 8), Tooltip("水面约束后,再做几次长度约束,减少局部折角")]
private int waterPostConstraintIterations = 2;
private int _waterFrameCounter;
[Header("Render (High Resolution)")] [SerializeField, Min(1), Tooltip("静止时每段物理线段插值加密数量(越大越顺,越耗)")]
private int renderSubdivisionsIdle = 6;
@@ -146,7 +169,6 @@ public class Rope : MonoBehaviour
InitLengthSystem();
AllocateAndInitNodes();
// ✅ 渲染点一次性分配到最大: (maxNodes-1)*idle + 1
int maxSubdiv = Mathf.Max(1, renderSubdivisionsIdle);
_rCapacity = (maxPhysicsNodes - 1) * maxSubdiv + 1;
_rPoints = new Vector3[_rCapacity];
@@ -172,6 +194,14 @@ public class Rope : MonoBehaviour
headMinLen = Mathf.Max(headMinLen, 0.0001f);
nodeHysteresis = Mathf.Max(0f, nodeHysteresis);
groundSampleStep = Mathf.Max(1, groundSampleStep);
groundUpdateEvery = Mathf.Max(1, groundUpdateEvery);
waterSampleStep = Mathf.Max(1, waterSampleStep);
waterUpdateEvery = Mathf.Max(1, waterUpdateEvery);
waterSurfaceOffset = Mathf.Max(0f, waterSurfaceOffset);
waterPostConstraintIterations = Mathf.Clamp(waterPostConstraintIterations, 0, 8);
}
private void InitLengthSystem()
@@ -235,7 +265,6 @@ public class Rope : MonoBehaviour
public void SetTargetLength(float lengthMeters) => _targetLength = Mathf.Max(0f, lengthMeters);
public float GetCurrentLength() => _currentLength;
public float GetTargetLength() => _targetLength;
public float GetLengthSmoothVel() => _lengthSmoothVel;
public float GetLengthByPoints()
@@ -256,20 +285,16 @@ public class Rope : MonoBehaviour
return totalLength;
}
private void FixedUpdate()
{
if (!startAnchor || !endAnchor) return;
// cache dt
_dt = Time.fixedDeltaTime;
if (_dt < 1e-6f) _dt = 1e-6f;
_dt2 = _dt * _dt;
// gravity
_gravity.y = -gravityStrength;
// drag cachesexp 比较贵,但这里每 FixedUpdate 一次OK
_kY = Mathf.Exp(-airDrag * _dt);
_kXZ = Mathf.Exp(-airDragXZ * _dt);
@@ -279,10 +304,8 @@ public class Rope : MonoBehaviour
Simulate_VerletFast();
// anchors
LockAnchorsHard();
// constraints
for (int it = 0; it < iterations; it++)
SolveDistanceConstraints_HeadOnly_Fast();
@@ -298,6 +321,20 @@ public class Rope : MonoBehaviour
}
}
if (constrainToWaterSurface)
{
_waterFrameCounter++;
if (_waterFrameCounter >= waterUpdateEvery)
{
_waterFrameCounter = 0;
ConstrainToWaterSurface();
// 水面抬升后补几次长度约束,让形状更顺一点
for (int it = 0; it < waterPostConstraintIterations; it++)
SolveDistanceConstraints_HeadOnly_Fast();
}
}
LockAnchorsHard();
}
@@ -307,7 +344,6 @@ public class Rope : MonoBehaviour
int last = _physicsNodes - 1;
// 用缓存 transform避免多次属性链
Vector3 s = _startTr.position;
Vector3 e = _endTr.position;
@@ -332,6 +368,20 @@ public class Rope : MonoBehaviour
Mathf.Infinity,
Time.fixedDeltaTime
);
// 长度变化时额外压一点速度,减少收放线时抖动
float delta = Mathf.Abs(_targetLength - _currentLength);
if (delta > 0.0001f && lengthChangeVelocityKill > 0f)
{
float keep = 1f - Mathf.Clamp01(lengthChangeVelocityKill);
for (int i = 1; i < _physicsNodes - 1; i++)
{
Vector3 curr = _pCurr[i];
Vector3 prev = _pPrev[i];
Vector3 disp = curr - prev;
_pPrev[i] = curr - disp * keep;
}
}
}
private void UpdateNodesFromLength()
@@ -369,7 +419,6 @@ public class Rope : MonoBehaviour
if (sq > 1e-6f) dir = toOld1 / Mathf.Sqrt(sq);
}
// inherit displacement (Verlet)
Vector3 inheritDisp = Vector3.zero;
if (oldCount >= 2 && firstOld < maxPhysicsNodes)
inheritDisp = (_pCurr[firstOld] - _pPrev[firstOld]);
@@ -378,7 +427,7 @@ public class Rope : MonoBehaviour
{
Vector3 pos = s + dir * (physicsSegmentLen * k);
_pCurr[k] = pos;
_pPrev[k] = pos - inheritDisp; // 保持动感
_pPrev[k] = pos - inheritDisp;
}
LockAnchorsHard();
@@ -408,13 +457,8 @@ public class Rope : MonoBehaviour
_headRestLen = Mathf.Clamp(_headRestLen, headMinLen, physicsSegmentLen * 1.5f);
}
/// <summary>
/// ✅ 更快的 Verlet去掉 /dt 和 *dt 抵消的无效计算
/// </summary>
private void Simulate_VerletFast()
{
// displacement = curr - prev
// next = curr + displacement*drag*dampen + gravity*dt^2
for (int i = 1; i < _physicsNodes - 1; i++)
{
Vector3 disp = _pCurr[i] - _pPrev[i];
@@ -447,9 +491,6 @@ public class Rope : MonoBehaviour
_pPrev[last] = e - endAnchor.linearVelocity * _dt;
}
/// <summary>
/// ✅ 约束:减少临时变量、用 sqrMagnitude + invDist
/// </summary>
private void SolveDistanceConstraints_HeadOnly_Fast()
{
int last = _physicsNodes - 1;
@@ -466,36 +507,14 @@ public class Rope : MonoBehaviour
if (sq < 1e-12f) continue;
float dist = Mathf.Sqrt(sq);
float diff = (dist - rest) / dist; // = 1 - rest/dist
float diff = (dist - rest) / dist;
Vector3 corr = delta * (diff * stiffness);
// i==0 锚点固定last 锚点固定
if (i != 0) _pCurr[i] = a + corr * 0.5f;
if (i + 1 != last) _pCurr[i + 1] = b - corr * 0.5f;
}
}
// private void ConstrainToGround()
// {
// if (groundMask == 0) return;
//
// // RaycastHit 是 struct这里不会 GC
// for (int i = 1; i < _physicsNodes - 1; i++)
// {
// Vector3 p = _pCurr[i];
// Vector3 origin = p + Vector3.up * groundCastHeight;
//
// if (Physics.Raycast(origin, Vector3.down, out RaycastHit hit, groundCastDistance, groundMask,
// QueryTriggerInteraction.Ignore))
// {
// float minY = hit.point.y + groundRadius;
// if (p.y < minY) p.y = minY;
// }
//
// _pCurr[i] = p;
// }
// }
private void ConstrainToGround()
{
if (groundMask == 0) return;
@@ -503,12 +522,9 @@ public class Rope : MonoBehaviour
int last = _physicsNodes - 1;
int step = Mathf.Max(1, groundSampleStep);
// 记录采样点的“最低允许Y”
// 不想分配数组就用局部变量滚动插值
int prevSampleIdx = 1;
float prevMinY = SampleMinY(_pCurr[prevSampleIdx]);
// 把采样点先处理掉
ApplyMinY(prevSampleIdx, prevMinY);
for (int i = 1 + step; i < last; i += step)
@@ -518,7 +534,6 @@ public class Rope : MonoBehaviour
if (groundInterpolate)
{
// 在两个采样点之间插值 minY视觉更平滑
int a = prevSampleIdx;
int b = i;
int span = b - a;
@@ -532,7 +547,6 @@ public class Rope : MonoBehaviour
}
else
{
// 直接用 prevMinY 填充中间点(更省)
for (int idx = prevSampleIdx + 1; idx < i; idx++)
ApplyMinY(idx, prevMinY);
}
@@ -541,7 +555,6 @@ public class Rope : MonoBehaviour
prevMinY = nextMinY;
}
// 尾巴剩余部分用最后一个采样值填
for (int i = prevSampleIdx + 1; i < last; i++)
ApplyMinY(i, prevMinY);
}
@@ -553,16 +566,84 @@ public class Rope : MonoBehaviour
QueryTriggerInteraction.Ignore))
return hit.point.y + groundRadius;
// 没命中就不抬(返回极小值)
return float.NegativeInfinity;
}
private void ApplyMinY(int i, float minY)
{
if (float.IsNegativeInfinity(minY)) return;
Vector3 p = _pCurr[i];
if (p.y < minY) p.y = minY;
_pCurr[i] = p;
if (p.y < minY)
{
p.y = minY;
_pCurr[i] = p;
// prev 同步抬上来,避免下一帧又被惯性拉回去造成抖动
Vector3 prev = _pPrev[i];
if (prev.y < minY) prev.y = minY;
_pPrev[i] = prev;
}
}
private void ConstrainToWaterSurface()
{
int last = _physicsNodes - 1;
if (last <= 1) return;
int step = Mathf.Max(1, waterSampleStep);
float surfaceY = waterLevelY + waterSurfaceOffset;
int prevSampleIdx = 1;
float prevSurfaceY = surfaceY;
ApplyWaterSurface(prevSampleIdx, prevSurfaceY);
for (int i = 1 + step; i < last; i += step)
{
float nextSurfaceY = surfaceY;
ApplyWaterSurface(i, nextSurfaceY);
if (waterInterpolate)
{
int a = prevSampleIdx;
int b = i;
int span = b - a;
for (int j = 1; j < span; j++)
{
int idx = a + j;
float t = j / (float)span;
float y = Mathf.Lerp(prevSurfaceY, nextSurfaceY, t);
ApplyWaterSurface(idx, y);
}
}
else
{
for (int idx = prevSampleIdx + 1; idx < i; idx++)
ApplyWaterSurface(idx, prevSurfaceY);
}
prevSampleIdx = i;
prevSurfaceY = nextSurfaceY;
}
for (int i = prevSampleIdx + 1; i < last; i++)
ApplyWaterSurface(i, prevSurfaceY);
}
private void ApplyWaterSurface(int i, float surfaceY)
{
Vector3 p = _pCurr[i];
if (p.y < surfaceY)
{
p.y = surfaceY;
_pCurr[i] = p;
// 同步 prev杀掉向下惯性避免反复穿透水面
Vector3 prev = _pPrev[i];
if (prev.y < surfaceY) prev.y = surfaceY;
_pPrev[i] = prev;
}
}
private void DrawHighResLine_Fast()
@@ -586,8 +667,6 @@ public class Rope : MonoBehaviour
int needed = (_physicsNodes - 1) * subdiv + 1;
if (needed > _rCapacity)
{
// 理论上不该发生_rCapacity 用 maxNodes & idle 分配)
// 保险扩容一次
_rCapacity = needed;
_rPoints = new Vector3[_rCapacity];
}
@@ -615,7 +694,6 @@ public class Rope : MonoBehaviour
float t2 = tc.t2[s];
float t3 = tc.t3[s];
// inline CatmullRom少一次函数调用
Vector3 cr =
0.5f * (
(2f * p1) +
@@ -624,7 +702,6 @@ public class Rope : MonoBehaviour
(-p0 + 3f * p1 - 3f * p2 + p3) * t3
);
// Linear Y
cr.y = p1.y + (p2.y - p1.y) * t;
_rPoints[idx++] = cr;
@@ -637,16 +714,13 @@ public class Rope : MonoBehaviour
_lineRenderer.SetPositions(_rPoints);
}
/// <summary>
/// ✅ 用 sqrMagnitude 比较阈值,避免 sqrt
/// </summary>
private int PickRenderSubdivisions_Fast()
{
int idle = Mathf.Max(1, renderSubdivisionsIdle);
int moving = Mathf.Max(1, renderSubdivisionsMoving);
float thr = movingSpeedThreshold;
float thrSq = (thr * _dt) * (thr * _dt); // 因为我们用 disp = curr-prev单位是米/step所以阈值要乘 dt
float thrSq = (thr * _dt) * (thr * _dt);
float sumSq = 0f;
int count = Mathf.Max(1, _physicsNodes - 2);

View File

@@ -32,9 +32,9 @@ namespace NBF
{
await LoginHelper.Login(InputAccount.text);
// await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
ChatTestPanel.Show();
// ChatTestPanel.Show();
// FishingShopPanel.Show();