浮漂修改

This commit is contained in:
2026-02-27 00:40:45 +08:00
parent 9a92e30a5f
commit fedef338c1
11 changed files with 1268 additions and 175 deletions

View File

@@ -41538,8 +41538,8 @@ MonoBehaviour:
Dependencies: []
Tags:
- Name: main/plyaer.bundle
Hash: e4ec05a4b781eddaae2f07fc44c008f4
Size: 378599896
Hash: 0765d7b38fb20176d24357d15a00b8f2
Size: 378600019
Assets:
- Path: Assets/ResRaw/Prefabs/Line/fishing line float set.prefab
Address: Plyaer/fishing line float set

BIN
Assets/New Terrain 12.asset Normal file

Binary file not shown.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e465e80fb4cc6eb468c18e24b9c28c2a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 15600000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -70,6 +70,7 @@ MonoBehaviour:
groundCastDistance: 2.5
groundSampleStep: 3
groundInterpolate: 1
groundUpdateEvery: 1
renderSubdivisionsIdle: 6
renderSubdivisionsMoving: 2
movingSpeedThreshold: 2
@@ -453,6 +454,7 @@ GameObject:
- component: {fileID: 54298866000586118}
- component: {fileID: 153691655494134957}
- component: {fileID: 2717383850592950062}
- component: {fileID: 3104700584461846010}
m_Layer: 16
m_Name: Float
m_TagString: Untagged
@@ -618,6 +620,30 @@ MonoBehaviour:
m_EditorClassIdentifier: Assembly-CSharp::NBF.BobberController
_rbody: {fileID: 54298866000586118}
joint: {fileID: 153691655494134957}
_buoyancy: {fileID: 3104700584461846010}
--- !u!114 &3104700584461846010
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1858052053854210}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dd1aa9f0de8b435448c6893ecc60d021, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Buoyancy
includeDeformation: 1
sphereRadiusApproximation: 0.1
waveForceMultiplier: 0.01
currentSpeedMultiplier: 0.01
dragMultiplier: 1
defaultRigidbodyDrag: 5
underwaterRigidbodyAngularDrag: 5
overwaterRigidbodyAngularDrag: 1
surfaceTensionDamping: 10
applyForceWithRandomOffset: 0
drawDebug: 1
--- !u!1 &1933124697579601
GameObject:
m_ObjectHideFlags: 0
@@ -688,6 +714,7 @@ MonoBehaviour:
groundCastDistance: 2.5
groundSampleStep: 3
groundInterpolate: 1
groundUpdateEvery: 1
renderSubdivisionsIdle: 6
renderSubdivisionsMoving: 2
movingSpeedThreshold: 2

View File

@@ -10,7 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 4943038628811238}
- component: {fileID: 4160997794325361152}
- component: {fileID: -1878270173486354861}
- component: {fileID: 642471695031276768}
m_Layer: 0
m_Name: bob_25004
m_TagString: Untagged
@@ -31,12 +31,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4033285271709525}
- {fileID: 4753668062539042}
- {fileID: 4391537656274936}
- {fileID: 4219322353105327}
- {fileID: 4083127709589988}
- {fileID: 4696959239802335}
- {fileID: 2628037665683154556}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: -0, z: -0}
--- !u!114 &4160997794325361152
@@ -56,8 +51,8 @@ MonoBehaviour:
topConnector: {fileID: 4753668062539042}
bottomConnector: {fileID: 4391537656274936}
waterline: {fileID: 4083127709589988}
--- !u!65 &-1878270173486354861
BoxCollider:
--- !u!136 &642471695031276768
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@@ -74,9 +69,11 @@ BoxCollider:
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 0.005, y: 0.005, z: 0.005}
m_Center: {x: 0, y: -0.01, z: 0}
serializedVersion: 2
m_Radius: 0.002
m_Height: 0.03
m_Direction: 1
m_Center: {x: 0, y: 0.01, z: 0}
--- !u!1 &1236424003946422
GameObject:
m_ObjectHideFlags: 0
@@ -86,7 +83,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 4219322353105327}
- component: {fileID: 136815202583894138}
m_Layer: 0
m_Name: _body
m_TagString: Untagged
@@ -102,36 +98,13 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1236424003946422}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.028749999, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4943038628811238}
m_Father: {fileID: 2628037665683154556}
m_LocalEulerAnglesHint: {x: 0, y: -0, z: -0}
--- !u!136 &136815202583894138
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1236424003946422}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.002
m_Height: 0.035
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1256211692469512
GameObject:
m_ObjectHideFlags: 0
@@ -162,7 +135,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4943038628811238}
m_Father: {fileID: 2628037665683154556}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!136 &136849029598565726
CapsuleCollider:
@@ -211,12 +184,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1342355430950628}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.00627, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4943038628811238}
m_Father: {fileID: 2628037665683154556}
m_LocalEulerAnglesHint: {x: 0, y: -0, z: -0}
--- !u!1 &1364623190328362
GameObject:
@@ -242,12 +215,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1364623190328362}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.0375, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4943038628811238}
m_Father: {fileID: 2628037665683154556}
m_LocalEulerAnglesHint: {x: 0, y: -0, z: -0}
--- !u!1 &1435124216471202
GameObject:
@@ -273,12 +246,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1435124216471202}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.05351, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4943038628811238}
m_Father: {fileID: 2628037665683154556}
m_LocalEulerAnglesHint: {x: 0, y: -0, z: -0}
--- !u!1 &1792318500355349
GameObject:
@@ -306,12 +279,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1792318500355349}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4943038628811238}
m_Father: {fileID: 2628037665683154556}
m_LocalEulerAnglesHint: {x: 0, y: -0, z: -0}
--- !u!33 &33680541704296896
MeshFilter:
@@ -369,3 +342,40 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &1696436611728297872
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2628037665683154556}
m_Layer: 0
m_Name: bob
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2628037665683154556
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1696436611728297872}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.04, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4033285271709525}
- {fileID: 4753668062539042}
- {fileID: 4391537656274936}
- {fileID: 4219322353105327}
- {fileID: 4083127709589988}
- {fileID: 4696959239802335}
m_Father: {fileID: 4943038628811238}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ namespace NBF
[SerializeField] private Rigidbody _rbody;
[SerializeField] private ConfigurableJoint joint;
[SerializeField] private Buoyancy _buoyancy;
public Rigidbody rbody => _rbody;
public void SetJoint(Rigidbody rb)
@@ -15,7 +15,7 @@ namespace NBF
joint = joint == null ? GetComponent<ConfigurableJoint>() : joint;
joint.connectedBody = rb;
}
public void SetJointDistance(float limit)
{
joint.linearLimit = new SoftJointLimit
@@ -23,5 +23,16 @@ namespace NBF
limit = limit
};
}
public void SetDetectCollisionEnabled(bool en)
{
_rbody.detectCollisions = en;
_buoyancy.EnablePhysics(en);
}
public void SetVelocity(Vector3 velocity)
{
_rbody.linearVelocity = velocity;
}
}
}

View File

@@ -0,0 +1,209 @@
using System;
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(Rigidbody))]
public class Buoyancy : MonoBehaviour
{
// ====== No water plugin dependency ======
[Header("Water (No Plugin)")]
[Tooltip("Fallback flat water level (Y). Set this to match your scene water height for now.")]
public float waterLevel = 0f;
[Tooltip("If false, buoyancy is disabled and rigidbody uses gravity.")]
public bool waterAvailable = true;
// ====== Original fields (kept) ======
public bool includeDeformation = true;
[Tooltip("Approxative radius of object for buoyancy.")]
public float sphereRadiusApproximation = 0.25f;
[Tooltip("Specifies the multiplier for the movement induced by other deformation (waves, swell... etc).")]
public float waveForceMultiplier = 1f;
[Tooltip("Specifies the multiplier for the movement induced by the current of the water surface.")]
public float currentSpeedMultiplier = 1f;
[Tooltip("Specifies the multiplier for the drag forces induced by the viscosity of the mediums.")]
public float dragMultiplier = 1f;
public float defaultRigidbodyDrag = 0.1f;
public float underwaterRigidbodyAngularDrag = 1f;
public float overwaterRigidbodyAngularDrag = 0.05f;
[Tooltip("Specifies the value for surface tension. A high value will stop the object bouncing faster on water.")]
public float surfaceTensionDamping = 10f;
[Tooltip("When enabled, the net force is applied with a random offset to create an angular velocity.")]
public bool applyForceWithRandomOffset;
// 原脚本里这个是 HDRP 的“自定义网格水面高度偏移”,这里保留字段但不再依赖水插件
[Tooltip("Optional extra offset added to sampled water height. Useful if your water mesh pivot isn't at surface level.")]
public float waterHeightOffset = 0f;
public bool drawDebug;
private Vector3 currentDirection;
private Vector3 A;
private Vector3 B;
private Vector3 C;
private Vector3 waterPosition;
private Vector3 normal;
private Vector3 deformationDirection;
private Rigidbody rigidbodyComponent;
private float h;
private float hNormalized;
private bool _isEnabled = true;
private void Start()
{
rigidbodyComponent = GetComponent<Rigidbody>();
rigidbodyComponent.useGravity = false;
rigidbodyComponent.linearDamping = defaultRigidbodyDrag;
}
public void EnablePhysics(bool set)
{
_isEnabled = set;
}
private void FixedUpdate()
{
// ✅ 关键:没有水 / 禁用时回到“用Unity重力”
if (!_isEnabled || !waterAvailable)
{
h = (hNormalized = 0f);
rigidbodyComponent.useGravity = true;
return;
}
rigidbodyComponent.useGravity = false;
FetchWaterSurfaceData(transform.position, out waterPosition, out normal, out currentDirection);
deformationDirection = Vector3.ProjectOnPlane(normal, Vector3.up);
h = Mathf.Clamp(
waterPosition.y - (transform.position.y - sphereRadiusApproximation),
0f,
2f * sphereRadiusApproximation
);
hNormalized = h * 1f / (2f * sphereRadiusApproximation);
float num = MathF.PI * h * h / 3f * (3f * sphereRadiusApproximation - h);
rigidbodyComponent.angularDamping = Mathf.Lerp(overwaterRigidbodyAngularDrag, underwaterRigidbodyAngularDrag, hNormalized);
// === 以下保持原脚本单位/写法(尽量贴近原行为) ===
Vector3 b = rigidbodyComponent.mass * Physics.gravity;
Vector3 vector = Vector3.Lerp(Physics.gravity, b, hNormalized);
float num2 = 997f;
float num3 = 0.001293f;
float num4 = 1.81E-05f;
float num5 = 0.001f;
float num6 = 0.47f;
Vector3 vector2 = (0f - num2) * num * Physics.gravity;
Vector3 a = MathF.PI * 6f * sphereRadiusApproximation * num4 * -rigidbodyComponent.linearVelocity;
Vector3 b2 = MathF.PI * 6f * sphereRadiusApproximation * num5 * -rigidbodyComponent.linearVelocity;
Vector3 vector3 = Vector3.Lerp(a, b2, hNormalized) * dragMultiplier;
float num7 = Mathf.Lerp(
b: Mathf.Sqrt(2f * rigidbodyComponent.mass * (0f - Physics.gravity.y) /
(num2 * MathF.PI * Mathf.Pow(sphereRadiusApproximation, 2f) * num6)),
a: Mathf.Sqrt(2f * rigidbodyComponent.mass * (0f - Physics.gravity.y) /
(num3 * MathF.PI * Mathf.Pow(sphereRadiusApproximation, 2f) * num6)),
t: hNormalized
);
Vector3 force = vector + vector2 + vector3;
Vector3 vector4 = applyForceWithRandomOffset
? (new Vector3(
UnityEngine.Random.Range(-1f, 1f),
UnityEngine.Random.Range(-1f, 1f),
UnityEngine.Random.Range(-1f, 1f)
) * sphereRadiusApproximation / 5f)
: Vector3.zero;
rigidbodyComponent.AddForceAtPosition(force, transform.position + vector4, ForceMode.Acceleration);
if (hNormalized > 0f && hNormalized < 1f)
{
Vector3 force2 = -(Vector3.Dot(rigidbodyComponent.linearVelocity, Physics.gravity.normalized)
* Physics.gravity.normalized) * surfaceTensionDamping;
rigidbodyComponent.AddForce(force2, ForceMode.Acceleration);
if (includeDeformation)
{
rigidbodyComponent.AddForce(deformationDirection * waveForceMultiplier, ForceMode.Acceleration);
rigidbodyComponent.AddForce(currentDirection * currentSpeedMultiplier, ForceMode.Acceleration);
}
}
if (rigidbodyComponent.linearVelocity.magnitude > num7)
{
rigidbodyComponent.linearVelocity = rigidbodyComponent.linearVelocity.normalized * num7;
}
}
private Vector3 FetchWaterSurfaceData(Vector3 point, out Vector3 positionWS, out Vector3 normalWS, out Vector3 currentDirectionWS)
{
// ✅ 插件无关:统一从 GetWaterInfo 拿数据
GetWaterInfo(point, out float waterHeight, out normalWS, out currentDirectionWS);
positionWS = new Vector3(point.x, waterHeight + waterHeightOffset, point.z);
if (normalWS == Vector3.zero) normalWS = Vector3.up;
return positionWS;
}
/// <summary>
/// Water provider (no plugin dependency).
/// 默认:水平水面,高度 = waterLevel
/// 以后接 Crest5你只要改这个函数即可。
/// </summary>
protected virtual void GetWaterInfo(Vector3 worldPoint, out float waterHeight, out Vector3 waterNormal, out Vector3 waterCurrentDir)
{
waterHeight = waterLevel; // 默认水面高度可在Inspector里调对齐
waterNormal = Vector3.up; // 默认法线
waterCurrentDir = Vector3.zero; // 默认水流方向
}
public Vector3 GetCurrentWaterPosition() => waterPosition;
public float GetNormalizedHeightOfSphereBelowSurface() => hNormalized;
private void OnDrawGizmosSelected()
{
if (!drawDebug) return;
Gizmos.color = Color.magenta;
Gizmos.DrawLine(transform.position, transform.position + normal);
Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, transform.position + deformationDirection * 10f);
Gizmos.color = Color.red;
Gizmos.DrawLine(transform.position, transform.position + currentDirection);
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(transform.position, sphereRadiusApproximation);
Gizmos.color = Color.blue;
Gizmos.DrawSphere(A, sphereRadiusApproximation / 10f);
Gizmos.DrawSphere(B, sphereRadiusApproximation / 10f);
Gizmos.DrawSphere(C, sphereRadiusApproximation / 10f);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: dd1aa9f0de8b435448c6893ecc60d021