去掉obi,使用自写绳索

This commit is contained in:
2026-02-23 20:51:03 +08:00
parent cb636f862d
commit 91e2309eeb
2011 changed files with 2593 additions and 190578 deletions

View File

@@ -1,9 +1,9 @@
using Obi;
// using Obi;
using UnityEngine;
public class RodLine : MonoBehaviour
{
private ObiRope obiRope;
// private ObiRope obiRope;
private LineRenderer lineRenderer;

View File

@@ -1,44 +1,512 @@
using NBC;
using NBF;
using Obi;
using NBF;
using UnityEngine;
[RequireComponent(typeof(LineRenderer))]
public class Rope : MonoBehaviour
{
private FRod _rod;
public bool isFloatRope;
[SerializeField] private ObiRope rope;
[Header("Anchors")] [SerializeField] public Rigidbody startAnchor;
[SerializeField] public Rigidbody endAnchor;
[SerializeField] private ObiRopeCursor cursor;
[Header("Physics (Dynamic Nodes, Fixed Segment Len)")] [SerializeField, Min(0.01f), Tooltip("物理每段固定长度(越小越细致越耗)")]
private float physicsSegmentLen = 0.15f;
[SerializeField] private float percentageElasticity = 0.2f;
[SerializeField, Range(2, 200)] private int minPhysicsNodes = 12;
[SerializeField, Range(2, 400)] [Tooltip("物理节点上限(仅用于性能保护;与“最大长度不限制”不是一回事)")]
private int maxPhysicsNodes = 120;
[SerializeField] private float gravityStrength = 2.0f;
[SerializeField, Range(0f, 1f)] private float velocityDampen = 0.95f;
[SerializeField, Range(0.0f, 1.0f)] [Tooltip("约束修正强度越大越硬。0.6~0.9 常用")]
private float stiffness = 0.8f;
[SerializeField, Range(1, 80)] [Tooltip("迭代次数。鱼线 10~30 通常够用")]
private int iterations = 20;
[Header("Length Control (No Min/Max Clamp)")]
[Tooltip("初始总长度(米)。如果为 0则用 physicsSegmentLen*(minPhysicsNodes-1) 作为初始长度")]
[SerializeField, Min(0f)]
private float initialLength = 0f;
[Tooltip("长度变化平滑时间(越小越跟手,越大越稳)")] [SerializeField, Min(0.0001f)]
private float lengthSmoothTime = 0.15f;
[Tooltip("当长度在变化时额外把速度压掉一些防抖。0=不额外处理1=变化时几乎清速度")] [SerializeField, Range(0f, 1f)]
private float lengthChangeVelocityKill = 0.6f;
[Tooltip("允许的最小松弛余量(避免目标长度刚好等于锚点距离时抖动)")] [SerializeField, Min(0f)]
private float minSlack = 0.002f;
[Header("Head Segment Clamp")] [Tooltip("第一段(起点->第1节点允许的最小长度避免收线时第一段被压到0导致数值炸")] [SerializeField, Min(0.0001f)]
private float headMinLen = 0.01f;
[Header("Simple Ground/Water Constraint (Cheap)")] [SerializeField]
private bool constrainToGround = true;
[SerializeField] private LayerMask groundMask = ~0;
[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] private bool constrainToWater = false;
[SerializeField] private float waterHeight = 0f;
[SerializeField, Min(0f)] private float waterRadius = 0.01f;
[Header("Render (High Resolution)")] [SerializeField, Min(1), Tooltip("每段物理线段插值加密的数量(越大越顺,越耗)")]
private int renderSubdivisions = 6;
[SerializeField, Tooltip("是否使用 Catmull-Rom 平滑(推荐开启)")]
private bool smooth = true;
[SerializeField, Min(0.0001f)] private float lineWidth = 0.002f;
private LineRenderer lr;
// physics
private int physicsNodes;
private Vector3[] pCurr;
private Vector3[] pPrev;
// render
private Vector3[] rPoints;
private int rCountCached = -1;
private Vector3 gravity;
// length control runtime
private float targetLength;
private float currentLength;
private float lengthSmoothVel;
// Only-head-change trick:
// Total rest length = headRestLen + (physicsNodes - 2) * physicsSegmentLen
private float headRestLen;
private float stretchScale;
private void Awake()
{
rope = GetComponent<ObiRope>();
lr = GetComponent<LineRenderer>();
gravity = new Vector3(0f, -gravityStrength, 0f);
InitLengthSystem();
AllocateAndInitNodes();
RebuildRenderBufferIfNeeded();
}
private FRod _rod;
public void Init(FRod rod)
{
_rod = rod;
}
public void LineLength_OnValueChanged(float length)
private void OnValidate()
{
cursor = cursor == null ? GetComponent<ObiRopeCursor>() : cursor;
var old = stretchScale;
stretchScale = Mathf.Clamp(length - percentageElasticity, 0f, float.PositiveInfinity);
// cursor.ChangeLength(length);
if (stretchScale != old)
renderSubdivisions = Mathf.Max(renderSubdivisions, 1);
iterations = Mathf.Clamp(iterations, 1, 80);
groundCastDistance = Mathf.Max(groundCastDistance, 0.01f);
groundCastHeight = Mathf.Max(groundCastHeight, 0f);
lineWidth = Mathf.Max(lineWidth, 0.0001f);
lengthSmoothTime = Mathf.Max(lengthSmoothTime, 0.0001f);
physicsSegmentLen = Mathf.Max(physicsSegmentLen, 0.01f);
minPhysicsNodes = Mathf.Max(minPhysicsNodes, 2);
maxPhysicsNodes = Mathf.Max(maxPhysicsNodes, minPhysicsNodes);
headMinLen = Mathf.Max(headMinLen, 0.0001f);
}
private void InitLengthSystem()
{
// 没有 min/max 长度限制:初始长度只做一个“非负”保障
float defaultLen = physicsSegmentLen * (Mathf.Max(minPhysicsNodes, 2) - 1);
currentLength = (initialLength > 0f) ? initialLength : defaultLen;
targetLength = currentLength;
}
private void AllocateAndInitNodes()
{
// 若锚点存在:最小长度就是两锚点直线距离 + minSlack防抖
if (startAnchor && endAnchor)
{
Log.Info($"rope name={gameObject.name} stretchScale={stretchScale}");
float minFeasible = Vector3.Distance(startAnchor.position, endAnchor.position) + minSlack;
currentLength = Mathf.Max(currentLength, minFeasible);
targetLength = Mathf.Max(targetLength, minFeasible);
}
physicsNodes = Mathf.Clamp(ComputeDesiredNodes(currentLength), 2, maxPhysicsNodes);
pCurr = new Vector3[physicsNodes];
pPrev = new Vector3[physicsNodes];
// 初始从起点往下排
Vector3 start = startAnchor ? startAnchor.position : transform.position;
Vector3 dir = Vector3.down;
for (int i = 0; i < physicsNodes; i++)
{
Vector3 pos = start + dir * (physicsSegmentLen * i);
pCurr[i] = pos;
pPrev[i] = pos;
}
UpdateHeadRestLenFromCurrentLength();
if (startAnchor && endAnchor)
LockAnchorsHard();
}
private int ComputeDesiredNodes(float lengthMeters)
{
// nodes = floor(length/segLen)+1
int desired = Mathf.FloorToInt(Mathf.Max(0f, lengthMeters) / physicsSegmentLen) + 1;
desired = Mathf.Clamp(desired, minPhysicsNodes, maxPhysicsNodes);
return desired;
}
/// <summary>设置目标总长度(米)。不做最小/最大长度限制(最小可行由锚点距离决定)。</summary>
public void SetTargetLength(float lengthMeters)
{
targetLength = Mathf.Max(0f, lengthMeters);
}
/// <summary>增加/减少目标总长度(米)。正数放线,负数收线。</summary>
public void AddTargetLength(float deltaMeters)
{
SetTargetLength(targetLength + deltaMeters);
}
public float GetCurrentLength() => currentLength;
public float GetTargetLength() => targetLength;
public float GetAnchorDistance()
{
if (startAnchor != null && endAnchor != null)
{
return Vector3.Distance(startAnchor.position, endAnchor.position);
}
return 0;
}
private void FixedUpdate2()
{
if (!startAnchor || !endAnchor)
return;
gravity.y = -gravityStrength;
UpdateLengthSmooth(); // 只保证 >= 锚点直线距离 + minSlack
UpdateNodesFromLength(); // 只从头部增/减节点
UpdateHeadRestLenFromCurrentLength(); // 第一段补余量 => 变化集中在头部
Simulate();
for (int it = 0; it < iterations; it++)
{
SolveDistanceConstraints_HeadOnly();
LockAnchorsHard();
}
if (constrainToWater || constrainToGround)
ConstrainToGroundAndWater();
LockAnchorsHard();
}
private void LateUpdate()
{
DrawHighResLine();
FixedUpdate2();
}
private void UpdateLengthSmooth()
{
float anchorDist = Vector3.Distance(startAnchor.position, endAnchor.position);
float minFeasible = anchorDist + minSlack;
// ✅ 最小长度 = 起点终点直线距离(+slack),最大不限制
float desired = Mathf.Max(targetLength, minFeasible);
float prevLen = currentLength;
currentLength = Mathf.SmoothDamp(
currentLength,
desired,
ref lengthSmoothVel,
lengthSmoothTime,
Mathf.Infinity,
Time.fixedDeltaTime
);
float lenDelta = Mathf.Abs(currentLength - prevLen);
if (lenDelta > 1e-5f && lengthChangeVelocityKill > 0f && pPrev != null)
{
float kill = Mathf.Clamp01(lengthChangeVelocityKill);
for (int i = 1; i < physicsNodes - 1; i++)
pPrev[i] = Vector3.Lerp(pPrev[i], pCurr[i], kill);
}
}
private void Update()
private void UpdateNodesFromLength()
{
rope.stretchingScale = stretchScale;
int desired = ComputeDesiredNodes(currentLength);
if (desired == physicsNodes) return;
while (physicsNodes < desired)
AddNodeAtStart();
while (physicsNodes > desired)
RemoveNodeAtStart();
RebuildRenderBufferIfNeeded();
}
private void AddNodeAtStart()
{
int newCount = Mathf.Min(physicsNodes + 1, maxPhysicsNodes);
if (newCount == physicsNodes) return;
Vector3[] newCurr = new Vector3[newCount];
Vector3[] newPrev = new Vector3[newCount];
newCurr[0] = pCurr[0];
newPrev[0] = pPrev[0];
for (int i = 2; i < newCount; i++)
{
newCurr[i] = pCurr[i - 1];
newPrev[i] = pPrev[i - 1];
}
Vector3 s = startAnchor.position;
Vector3 dir = Vector3.down;
if (physicsNodes >= 2)
{
Vector3 toOld1 = (pCurr[1] - s);
if (toOld1.sqrMagnitude > 1e-6f) dir = toOld1.normalized;
}
Vector3 pos = s + dir * physicsSegmentLen;
newCurr[1] = pos;
newPrev[1] = pos;
pCurr = newCurr;
pPrev = newPrev;
physicsNodes = newCount;
LockAnchorsHard();
}
private void RemoveNodeAtStart()
{
int newCount = Mathf.Max(physicsNodes - 1, 2);
if (newCount == physicsNodes) return;
Vector3[] newCurr = new Vector3[newCount];
Vector3[] newPrev = new Vector3[newCount];
newCurr[0] = pCurr[0];
newPrev[0] = pPrev[0];
for (int i = 1; i < newCount - 1; i++)
{
newCurr[i] = pCurr[i + 1];
newPrev[i] = pPrev[i + 1];
}
newCurr[newCount - 1] = pCurr[physicsNodes - 1];
newPrev[newCount - 1] = pPrev[physicsNodes - 1];
pCurr = newCurr;
pPrev = newPrev;
physicsNodes = newCount;
LockAnchorsHard();
}
private void UpdateHeadRestLenFromCurrentLength()
{
int fixedSegCount = Mathf.Max(0, physicsNodes - 2);
float baseLen = fixedSegCount * physicsSegmentLen;
headRestLen = currentLength - baseLen;
// 第一段允许在一个合理范围内变动(太长会像橡皮筋,太短会炸)
headRestLen = Mathf.Clamp(headRestLen, headMinLen, physicsSegmentLen * 1.5f);
}
private void Simulate()
{
float dt = Time.fixedDeltaTime;
for (int i = 0; i < physicsNodes; i++)
{
Vector3 v = (pCurr[i] - pPrev[i]) * velocityDampen;
pPrev[i] = pCurr[i];
pCurr[i] += v;
pCurr[i] += gravity * dt;
}
LockAnchorsHard();
}
private void LockAnchorsHard()
{
if (!startAnchor || !endAnchor || pCurr == null || pPrev == null || physicsNodes < 2) return;
float dt = Time.fixedDeltaTime;
Vector3 s = startAnchor.position;
Vector3 e = endAnchor.position;
pCurr[0] = s;
pPrev[0] = s - startAnchor.linearVelocity * dt;
int last = physicsNodes - 1;
pCurr[last] = e;
pPrev[last] = e - endAnchor.linearVelocity * dt;
}
private void SolveDistanceConstraints_HeadOnly()
{
for (int i = 0; i < physicsNodes - 1; i++)
{
float rest = (i == 0) ? headRestLen : physicsSegmentLen;
Vector3 a = pCurr[i];
Vector3 b = pCurr[i + 1];
Vector3 delta = b - a;
float dist = delta.magnitude;
if (dist < 1e-6f) continue;
float diff = (dist - rest) / dist;
Vector3 corr = delta * diff * stiffness;
if (i != 0)
pCurr[i] += corr * 0.5f;
if (i + 1 != physicsNodes - 1)
pCurr[i + 1] -= corr * 0.5f;
}
}
private void ConstrainToGroundAndWater()
{
for (int i = 1; i < physicsNodes - 1; i++)
{
Vector3 p = pCurr[i];
if (constrainToWater)
{
float minY = waterHeight + waterRadius;
if (p.y < minY) p.y = minY;
}
if (constrainToGround)
{
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 DrawHighResLine()
{
if (pCurr == null || physicsNodes < 2) return;
RebuildRenderBufferIfNeeded();
lr.startWidth = lineWidth;
lr.endWidth = lineWidth;
if (!smooth)
{
lr.positionCount = physicsNodes;
lr.SetPositions(pCurr);
return;
}
int idx = 0;
for (int seg = 0; seg < physicsNodes - 1; seg++)
{
Vector3 p0 = pCurr[Mathf.Max(seg - 1, 0)];
Vector3 p1 = pCurr[seg];
Vector3 p2 = pCurr[seg + 1];
Vector3 p3 = pCurr[Mathf.Min(seg + 2, physicsNodes - 1)];
for (int s = 0; s < renderSubdivisions; s++)
{
float t = s / (float)renderSubdivisions;
Vector3 pt = CatmullRom_XZ_LinearY(p0, p1, p2, p3, t);
// 如果水面约束开启:渲染点也夹一下,避免视觉上又穿回去
if (constrainToWater)
{
float minY = waterHeight + waterRadius;
if (pt.y < minY) pt.y = minY;
}
rPoints[idx++] = pt;
}
}
rPoints[idx++] = pCurr[physicsNodes - 1];
lr.positionCount = idx;
lr.SetPositions(rPoints);
}
private void RebuildRenderBufferIfNeeded()
{
int targetCount = (physicsNodes - 1) * renderSubdivisions + 1;
if (rPoints == null || rCountCached != targetCount)
{
rPoints = new Vector3[targetCount];
rCountCached = targetCount;
}
}
private static Vector3 CatmullRom(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{
float t2 = t * t;
float t3 = t2 * t;
return 0.5f * (
(2f * p1) +
(-p0 + p2) * t +
(2f * p0 - 5f * p1 + 4f * p2 - p3) * t2 +
(-p0 + 3f * p1 - 3f * p2 + p3) * t3
);
}
private void OnDrawGizmosSelected()
{
if (pCurr == null) return;
Gizmos.color = Color.yellow;
for (int i = 0; i < pCurr.Length; i++)
Gizmos.DrawSphere(pCurr[i], 0.01f);
}
private static Vector3 CatmullRom_XZ_LinearY(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{
// XZ 做 Catmull-Rom
Vector3 cr = CatmullRom(p0, p1, p2, p3, t);
// Y 不做样条,改成线性(不会过冲)
cr.y = Mathf.Lerp(p1.y, p2.y, t);
return cr;
}
}

View File

@@ -2,14 +2,14 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Obi;
// using Obi;
using UnityEngine;
namespace NBF
{
public class FLine : FGearBase
{
[SerializeField] private ObiParticleAttachment startParticleAttachment;
// [SerializeField] private ObiParticleAttachment startParticleAttachment;
[SerializeField] private bool isLureConnect;
[SerializeField] private RodLine rodLine;
[SerializeField] private Rope fishingRope;
@@ -31,7 +31,7 @@ namespace NBF
protected override void OnInit()
{
var tipRb = Rod.Asset.LineConnectorRigidbody;
startParticleAttachment.target = tipRb.transform;
// startParticleAttachment.target = tipRb.transform;
if (isLureConnect)
{
Lure.SetJoint(tipRb);
@@ -39,6 +39,7 @@ namespace NBF
}
else
{
fishingRope.startAnchor = tipRb;
Bobber.SetJoint(tipRb);
Lure.SetJoint(Bobber.rbody);
Lure.gameObject.SetActive(true);
@@ -78,15 +79,15 @@ namespace NBF
public void EnableLineRenderers()
{
foreach (ObiRopeExtrudedRenderer item in GetComponentsInChildren<ObiRopeExtrudedRenderer>().ToList())
{
item.enabled = true;
}
// foreach (ObiRopeExtrudedRenderer item in GetComponentsInChildren<ObiRopeExtrudedRenderer>().ToList())
// {
// item.enabled = true;
// }
}
public void SetObiRopeStretch(float value)
{
fishingRope.LineLength_OnValueChanged(value);
fishingRope.SetTargetLength(value);
}
}
}

View File

@@ -1,194 +1,194 @@
using NBF;
using Obi;
using UnityEngine;
public class FLineHandler : MonoBehaviour
{
public enum LineType
{
None = 0,
OneSegment = 1,
TwoSegment = 2,
ThereSegment = 3
}
public LineType lineType = LineType.TwoSegment;
// public ObiParticleAttachment startParticleAttachment;
public ObiRope obiRopeSegment_1;
public ObiRope obiRopeSegment_2;
public ObiRope obiRopeSegment_3;
public FixedLine LineConnector_0;
public SpringJoint LineConnector_1;
public SpringJoint LineConnector_2;
public SpringJoint LineConnector_3;
// [HideInInspector] public FFishingLine currentRodFishingLineComponent;
// public ObiParticleAttachment toRodConnector;
// public float PhisicsLineOut { get; set; }
public float ObiLineOut;
[HideInInspector] public Rigidbody EndLineRigidbody_0;
[HideInInspector] public Rigidbody EndLineRigidbody_1;
[HideInInspector] public Rigidbody EndLineRigidbody_2;
[HideInInspector] public Rigidbody EndLineRigidbody_3;
// public JointPinchController pinchController;
public FRod Rod;
private Transform waterPlane;
public LineRenderer LineRenderer1;
public LineRenderer LineRenderer2;
// public float ropeToHookDistance;
void Start()
{
ObiLineOut = obiRopeSegment_1.stretchingScale;
if ((bool)LineConnector_0)
{
EndLineRigidbody_0 = LineConnector_0.GetComponent<Rigidbody>();
}
if ((bool)LineConnector_1)
{
EndLineRigidbody_1 = LineConnector_1.GetComponent<Rigidbody>();
}
if ((bool)LineConnector_2)
{
EndLineRigidbody_2 = LineConnector_2.GetComponent<Rigidbody>();
// var fixedJoint = LineConnector_2.GetComponent<FixedJoint>();
// pinchController = LineConnector_2.gameObject.AddComponent<JointPinchController>();
}
if ((bool)LineConnector_3)
{
EndLineRigidbody_3 = LineConnector_3.GetComponent<Rigidbody>();
}
waterPlane = GameObject.FindGameObjectWithTag("Water").transform;
Debug.LogError($"rope.restLength={obiRopeSegment_1.restLength} LineConnector_1={LineConnector_1.maxDistance}");
}
void Update()
{
if (!Rod) return;
// ropeToHookDistance = Vector3.Distance(toRodConnector.transform.position, LineConnector_1.transform.position);
ObiLineOut = 0.1f + Rod.lineLength;
float target = (0f - Mathf.Clamp(Rod.linelenghtDiferent, -1f, 0f)) * 0.1f;
if (Rod.linelenghtDiferent >= 0f)
{
obiRopeSegment_1.stretchCompliance = Mathf.MoveTowards(obiRopeSegment_1.stretchCompliance, target,
Time.smoothDeltaTime * (1f * Rod.linelenghtDiferent));
}
else
{
obiRopeSegment_1.stretchCompliance = Mathf.MoveTowards(obiRopeSegment_1.stretchCompliance, target,
Time.smoothDeltaTime * 0.1f);
}
if (Rod.lineLength == 0f)
{
obiRopeSegment_1.stretchCompliance = 0f;
}
if ((bool)obiRopeSegment_2)
{
if (!Rod.currentFish)
{
obiRopeSegment_2.stretchCompliance = obiRopeSegment_2.stretchingScale * 0.004f;
}
else
{
obiRopeSegment_2.stretchCompliance = 0f;
}
//TODO:TEST
obiRopeSegment_2.stretchingScale = 0.13F;
}
obiRopeSegment_1.stretchingScale = ObiLineOut;
obiRopeSegment_1.stretchingScale = 1;
LineConnector_1.maxDistance = 0.1f + Rod.lineLength;
if (Input.GetKey(KeyCode.E))
{
// var speed = 1;
// obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
// Debug.Log(obiRopeSegment_1.restLength);
}
// var addLength = LineConnector_1.maxDistance - obiRopeSegment_1.restLength;
// if (Mathf.Abs(addLength) > 0.001f)
// {
// obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
// }
// if (!Mathf.Approximately(LineConnector_1.maxDistance, obiRopeSegment_1.restLength))
// {
// obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
// }
// obiRopeCursor_1.pos
// LineConnector_1.minDistance = LineConnector_1.maxDistance;
}
public void SetSegmentTwoLenght(float lenght)
{
LineConnector_2.maxDistance = lenght;
// obiRopeCursor_2.ChangeLength(lenght);
// LineConnector_2.minDistance = LineConnector_2.maxDistance;
}
private void FixedUpdate()
{
// BindRod();
LineWaterDisplacement();
}
private void BindRod()
{
if (!Rod || !Rod.Asset) return;
LineConnector_0.transform.position = Rod.Asset.lineConnector.position;
}
private void LineWaterDisplacement()
{
if (!waterPlane)
{
return;
}
for (int i = 0; i < obiRopeSegment_1.activeParticleCount; i++)
{
if (obiRopeSegment_1.GetParticlePosition(i).y < waterPlane.position.y)
{
// obiRopeSegment_1.AddForceParticle(i, Vector3.up * 10f, ForceMode.Acceleration);
}
}
}
}
// using NBF;
// using Obi;
// using UnityEngine;
//
// public class FLineHandler : MonoBehaviour
// {
// public enum LineType
// {
// None = 0,
// OneSegment = 1,
// TwoSegment = 2,
// ThereSegment = 3
// }
//
// public LineType lineType = LineType.TwoSegment;
//
// // public ObiParticleAttachment startParticleAttachment;
//
// public ObiRope obiRopeSegment_1;
//
// public ObiRope obiRopeSegment_2;
//
// public ObiRope obiRopeSegment_3;
//
// public FixedLine LineConnector_0;
//
// public SpringJoint LineConnector_1;
//
// public SpringJoint LineConnector_2;
//
// public SpringJoint LineConnector_3;
//
// // [HideInInspector] public FFishingLine currentRodFishingLineComponent;
//
// // public ObiParticleAttachment toRodConnector;
//
// // public float PhisicsLineOut { get; set; }
//
// public float ObiLineOut;
//
// [HideInInspector] public Rigidbody EndLineRigidbody_0;
//
// [HideInInspector] public Rigidbody EndLineRigidbody_1;
//
// [HideInInspector] public Rigidbody EndLineRigidbody_2;
//
// [HideInInspector] public Rigidbody EndLineRigidbody_3;
//
// // public JointPinchController pinchController;
//
// public FRod Rod;
//
// private Transform waterPlane;
//
//
// public LineRenderer LineRenderer1;
// public LineRenderer LineRenderer2;
//
// // public float ropeToHookDistance;
//
// void Start()
// {
// ObiLineOut = obiRopeSegment_1.stretchingScale;
// if ((bool)LineConnector_0)
// {
// EndLineRigidbody_0 = LineConnector_0.GetComponent<Rigidbody>();
// }
//
// if ((bool)LineConnector_1)
// {
// EndLineRigidbody_1 = LineConnector_1.GetComponent<Rigidbody>();
// }
//
// if ((bool)LineConnector_2)
// {
// EndLineRigidbody_2 = LineConnector_2.GetComponent<Rigidbody>();
// // var fixedJoint = LineConnector_2.GetComponent<FixedJoint>();
// // pinchController = LineConnector_2.gameObject.AddComponent<JointPinchController>();
// }
//
// if ((bool)LineConnector_3)
// {
// EndLineRigidbody_3 = LineConnector_3.GetComponent<Rigidbody>();
// }
//
// waterPlane = GameObject.FindGameObjectWithTag("Water").transform;
//
// Debug.LogError($"rope.restLength={obiRopeSegment_1.restLength} LineConnector_1={LineConnector_1.maxDistance}");
// }
//
//
// void Update()
// {
// if (!Rod) return;
//
//
// // ropeToHookDistance = Vector3.Distance(toRodConnector.transform.position, LineConnector_1.transform.position);
//
// ObiLineOut = 0.1f + Rod.lineLength;
// float target = (0f - Mathf.Clamp(Rod.linelenghtDiferent, -1f, 0f)) * 0.1f;
// if (Rod.linelenghtDiferent >= 0f)
// {
// obiRopeSegment_1.stretchCompliance = Mathf.MoveTowards(obiRopeSegment_1.stretchCompliance, target,
// Time.smoothDeltaTime * (1f * Rod.linelenghtDiferent));
// }
// else
// {
// obiRopeSegment_1.stretchCompliance = Mathf.MoveTowards(obiRopeSegment_1.stretchCompliance, target,
// Time.smoothDeltaTime * 0.1f);
// }
//
// if (Rod.lineLength == 0f)
// {
// obiRopeSegment_1.stretchCompliance = 0f;
// }
//
// if ((bool)obiRopeSegment_2)
// {
// if (!Rod.currentFish)
// {
// obiRopeSegment_2.stretchCompliance = obiRopeSegment_2.stretchingScale * 0.004f;
// }
// else
// {
// obiRopeSegment_2.stretchCompliance = 0f;
// }
//
// //TODO:TEST
// obiRopeSegment_2.stretchingScale = 0.13F;
// }
//
// obiRopeSegment_1.stretchingScale = ObiLineOut;
// obiRopeSegment_1.stretchingScale = 1;
// LineConnector_1.maxDistance = 0.1f + Rod.lineLength;
// if (Input.GetKey(KeyCode.E))
// {
// // var speed = 1;
// // obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
// // Debug.Log(obiRopeSegment_1.restLength);
// }
//
// // var addLength = LineConnector_1.maxDistance - obiRopeSegment_1.restLength;
// // if (Mathf.Abs(addLength) > 0.001f)
// // {
// // obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
// // }
//
// // if (!Mathf.Approximately(LineConnector_1.maxDistance, obiRopeSegment_1.restLength))
// // {
// // obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
// // }
//
// // obiRopeCursor_1.pos
//
//
// // LineConnector_1.minDistance = LineConnector_1.maxDistance;
// }
//
//
// public void SetSegmentTwoLenght(float lenght)
// {
// LineConnector_2.maxDistance = lenght;
// // obiRopeCursor_2.ChangeLength(lenght);
// // LineConnector_2.minDistance = LineConnector_2.maxDistance;
// }
//
// private void FixedUpdate()
// {
// // BindRod();
// LineWaterDisplacement();
// }
//
// private void BindRod()
// {
// if (!Rod || !Rod.Asset) return;
// LineConnector_0.transform.position = Rod.Asset.lineConnector.position;
// }
//
// private void LineWaterDisplacement()
// {
// if (!waterPlane)
// {
// return;
// }
//
// for (int i = 0; i < obiRopeSegment_1.activeParticleCount; i++)
// {
// if (obiRopeSegment_1.GetParticlePosition(i).y < waterPlane.position.y)
// {
// // obiRopeSegment_1.AddForceParticle(i, Vector3.up * 10f, ForceMode.Acceleration);
// }
// }
// }
// }

View File

@@ -4,7 +4,6 @@ using System.Collections.Generic;
using Fantasy;
using NBC.Asset;
using NBF.Utils;
using Obi;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -295,7 +294,9 @@ namespace NBF
Line.transform.position = Asset.lineConnector.position;
Line.Init(this.Player, this);
var obiSolver = solver.GetComponent<ObiSolver>();
// var obiSolver = solver.GetComponent<ObiSolver>();
// obiSolver.parameters.ambientWind = Vector3.zero;
// obiSolver.wind.
// obiSolver.simulateWhenInvisible
}
}