新增脚本

This commit is contained in:
2025-12-26 23:11:06 +08:00
parent 45129be7dc
commit 028d054705
153 changed files with 2783 additions and 15441 deletions

View File

@@ -8,13 +8,7 @@ namespace NBF
public FPlayer Player { get; protected set; }
public FRod Rod { get; protected set; }
public ItemInfo ItemInfo;
public HookAsset hookAsset;
private void Awake()
{
hookAsset = GetComponent<HookAsset>();
}
public virtual void Init(FPlayer player, FRod rod)
{

View File

@@ -1,12 +1,25 @@
using UnityEngine;
using Obi;
using UnityEngine;
namespace NBF
{
public class FLine : FGearBase
{
[SerializeField] private ObiParticleAttachment startParticleAttachment;
[SerializeField] private bool isLureConnect;
[SerializeField] private RodLine rodLine;
[SerializeField] private Rope fishingRope;
public float LineLength = 0.5f;
private float _groundSetting = 0.5f;
private float _LineOnSpool = 100f;
private float _LineThickness = 0.0007f;
protected override void OnInit()
{
}
}
}

View File

@@ -1,190 +1,190 @@
using System;
using NBF;
using Obi;
using Unity.VisualScripting;
using UnityEngine;
public class FLineHandler : MonoBehaviour
{
public enum LineType
{
None = 0,
OneSegment = 1,
TwoSegment = 2,
ThereSegment = 3
}
public LineType lineType = LineType.TwoSegment;
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 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 System;
// using NBF;
// using Obi;
// using Unity.VisualScripting;
// using UnityEngine;
//
// public class FLineHandler : MonoBehaviour
// {
// public enum LineType
// {
// None = 0,
// OneSegment = 1,
// TwoSegment = 2,
// ThereSegment = 3
// }
//
// public LineType lineType = LineType.TwoSegment;
//
// 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 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

@@ -30,10 +30,6 @@ namespace NBF
public FWeight Weight;
public FLine Line;
/// <summary>
/// 鱼线处理器
/// </summary>
public FLineHandler lineHandler;
public Transform GearRoot;
@@ -81,9 +77,12 @@ namespace NBF
var parent = GearRoot;
CreateFishingHandler();
List<ItemInfo> children = RoleModel.Instance.GetBindItems(itemInfo.Id);
ItemInfo lineItemInfo = null;
// CreateFishingHandler();
// children.Sort();
foreach (var child in children)
{
@@ -124,7 +123,13 @@ namespace NBF
Quaternion.identity);
Weight.SetItemInfo(child);
}
else if (itemType == ItemType.Line)
{
lineItemInfo = child;
}
}
yield return 1;
if (Reel)
@@ -136,40 +141,40 @@ namespace NBF
Reel.Init(player, this);
}
if (Bobber)
{
Bobber.Init(Player, this);
Bobber.transform.position = lineHandler.LineConnector_1.transform.position;
Bobber.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
lineHandler.LineConnector_1.GetComponent<Rigidbody>();
}
if (Hook)
{
Hook.Init(Player, this);
Hook.transform.position = lineHandler.LineConnector_2.transform.position;
Hook.transform.rotation = lineHandler.LineConnector_2.transform.rotation; // 确保旋转也同步
var target = lineHandler.LineConnector_2.GetComponent<Rigidbody>();
var joint = Hook.gameObject.GetComponent<ConfigurableJoint>();
joint.connectedBody = target;
// LureHookWaterDisplacement = Hook.GetComponent<FWaterDisplacement>();
}
if (Bait)
{
Bait.Init(Player, this);
Bait.transform.position = Hook.hookAsset.baitConnector.position;
Bait.transform.SetParent(Hook.hookAsset.baitConnector);
}
if (Lure)
{
Lure.Init(Player, this);
Lure.transform.position = lineHandler.LineConnector_1.transform.position;
Lure.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
lineHandler.LineConnector_1.GetComponent<Rigidbody>();
// LureHookWaterDisplacement = Lure.GetComponent<FWaterDisplacement>();
}
// if (Bobber)
// {
// Bobber.Init(Player, this);
// Bobber.transform.position = lineHandler.LineConnector_1.transform.position;
// Bobber.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
// lineHandler.LineConnector_1.GetComponent<Rigidbody>();
// }
//
// if (Hook)
// {
// Hook.Init(Player, this);
// Hook.transform.position = lineHandler.LineConnector_2.transform.position;
// Hook.transform.rotation = lineHandler.LineConnector_2.transform.rotation; // 确保旋转也同步
// var target = lineHandler.LineConnector_2.GetComponent<Rigidbody>();
// var joint = Hook.gameObject.GetComponent<ConfigurableJoint>();
// joint.connectedBody = target;
// // LureHookWaterDisplacement = Hook.GetComponent<FWaterDisplacement>();
// }
//
// if (Bait)
// {
// Bait.Init(Player, this);
// Bait.transform.position = Hook.hookAsset.baitConnector.position;
// Bait.transform.SetParent(Hook.hookAsset.baitConnector);
// }
//
// if (Lure)
// {
// Lure.Init(Player, this);
// Lure.transform.position = lineHandler.LineConnector_1.transform.position;
// Lure.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
// lineHandler.LineConnector_1.GetComponent<Rigidbody>();
// // LureHookWaterDisplacement = Lure.GetComponent<FWaterDisplacement>();
// }
if (Weight)
{
@@ -223,95 +228,5 @@ namespace NBF
rings = list.ToArray();
}
public void CreateFishingHandler()
{
if (lineHandler == null)
{
Debug.LogError("创建钓组=====");
var rodType = (ItemSubType)ItemInfo.Config.Type;
if (rodType == ItemSubType.RodTele)
{
CreateObiFishingLine(0);
}
else if (rodType == ItemSubType.RodSpine || rodType == ItemSubType.RodBolo)
{
CreateObiFishingLine(1);
}
}
}
public void CreateObiFishingLine(int currentLineTypeIndex)
{
// if ((bool)Owner.Gears.Reel && !currentLineHandler)
if (!lineHandler)
{
var indexNames = new[] { "FFishingLine_0", "FFishingLine_1" };
var path =
$"Assets/ResRaw/Prefabs/{indexNames[currentLineTypeIndex]}.prefab"; //$"GameItemsPrefabs/Lines/{indexNames[currentLineTypeIndex]}";
var prefab = Assets.Load<GameObject>(path);
// var toRodConnector = rodAsset.lineConnector.GetComponent<Rigidbody>();
GameObject obj = Instantiate(prefab, GearRoot.position, Quaternion.identity, GearRoot);
lineHandler = obj.GetComponent<FLineHandler>();
// lineHandler.transform.SetParent(toRodConnector.transform);
lineHandler.transform.position = Asset.lineConnector.position;
lineHandler.LineConnector_0.target = Asset.lineConnector; //.GetComponent<Rigidbody>();
// lineHandler.toRodConnector.target = rodAsset.lineConnector;
lineHandler.Rod = this;
// var obiSolver = lineHandler.GetComponent<ObiSolver>();
// SceneSettings.Instance.obiFixedUpdater.solvers.Add(obiSolver);
}
}
public void RenderLine()
{
if (!lineHandler)
{
return;
}
if (!Reel) return;
if (!Asset.lineRenderer) return;
// var reel = Reel;
// int num = 0;
// bool isBlockLineByFinger = reel.isBlockLineByFinger;
// if (reel.AnimatorCtrl.Unlock && isBlockLineByFinger && reel.reelAsset.type == ReelAsset.Type.Normal)
// {
// Asset.lineRenderer.positionCount = rings.Length + 3;
// }
// else
// {
// Asset.lineRenderer.positionCount = rings.Length + 2;
// }
//
// Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineIntersectHelper.position);
// num++;
// if (reel.AnimatorCtrl.Unlock && reel.reelAsset.type == ReelAsset.Type.Normal)
// {
// Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineIntersect.position);
// num++;
// if (isBlockLineByFinger)
// {
// // Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineFingerPoint.position);
// // num++;
// }
// }
// else
// {
// Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineConnector.position);
// num++;
// }
//
// for (int num2 = 0; num2 < rings.Length; num2++)
// {
// Asset.lineRenderer.SetPosition(num, rings[num2].point.position);
// num++;
// }
}
}
}