using System; using NBF; using UnityEngine; namespace Test { public class BobberTest : MonoBehaviour { public Rigidbody rb; public FLine line; public float lineLength = 1f; public float floatLength = 0.5f; public float Tension = 0; public void Start() { line.InitTest(rb); //有浮漂 line.Lure.SetJointDistance(floatLength); line.Bobber.SetJointDistance(lineLength - floatLength); line.SetTargetLength(lineLength - floatLength); } private void Update() { if (Input.GetKeyDown(KeyCode.Alpha0)) { SetLineLength(lineLength); } else if (Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.Equals)) { lineLength += 0.1f; SetLineLength(lineLength); } else if (Input.GetKeyDown(KeyCode.Minus)) { lineLength -= 0.1f; SetLineLength(lineLength); } } public void SetLineLength(float lineLength, bool stretchRope = true) { Debug.Log($"lineLength={lineLength}"); if (!line) return; if (line.LineType == LineType.Spinning) { //没有浮漂类型 line.Lure.SetJointDistance(lineLength); if (stretchRope) { line.SetTargetLength(Tension > 0f ? 0f : lineLength); } } else { //有浮漂 line.Lure.SetJointDistance(floatLength); line.Bobber.SetJointDistance(lineLength - floatLength); if (stretchRope) { line.SetTargetLength(Tension > 0f ? 0f : lineLength - floatLength); } } } } }