Files
Fishing2/Assets/Scripts/Fishing/Item/FishingLine/FLineLogicNode.cs
2026-05-08 23:26:44 +08:00

74 lines
1.7 KiB
C#

using System;
using System.Collections;
using UnityEngine;
namespace NBF
{
public enum FLineLogicNodeType
{
Start,
Bobber,
Weight,
End
}
public class FLineLogicNode : MonoBehaviour
{
[Header("节点设置")] public FLineLogicNodeType NodeType = FLineLogicNodeType.Bobber;
[SerializeField] private Rope rope;
[SerializeField] private Rigidbody preRigidbody;
private Rigidbody _rb;
private ConfigurableJoint _joint;
private FLine _parentCable;
private float _lenght;
public Rigidbody PreRigidbody => preRigidbody;
public Rigidbody Rigidbody => _rb;
public FLine ParentCable => _parentCable;
public ConfigurableJoint Joint => _joint;
public float Lenght => _lenght;
public Rope Rope => rope;
private void Awake()
{
_rb = GetComponent<Rigidbody>();
_parentCable = GetComponentInParent<FLine>();
_joint = GetComponent<ConfigurableJoint>();
}
public void SetLenght(float lenght)
{
_lenght = lenght;
if (_joint)
{
_joint.linearLimit = new SoftJointLimit() { limit = lenght };
}
if (rope)
{
rope.SetTargetLength(lenght);
}
}
void FixedUpdate()
{
if (rope)
{
if(rope.startAnchor != _joint.connectedBody){}
rope.startAnchor = _joint.connectedBody;
}
}
public void SetConnectedBody(Rigidbody rig)
{
if (_joint)
{
_joint.connectedBody = rig;
}
}
}
}