去掉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

@@ -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
}
}