Files
Fishing2/Assets/Scripts/Test/BobberTest.cs
2026-03-26 16:03:53 +08:00

83 lines
2.4 KiB
C#

using System;
using DG.Tweening;
using NBF;
using UnityEngine;
namespace Test
{
public class BobberTest : MonoBehaviour
{
public Rigidbody rb;
public FLine line;
public Transform Terrain;
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);
line.SetLureLength(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);
}
else if (Input.GetKeyDown(KeyCode.K))
{
var pos = Terrain.localPosition;
Terrain.DOLocalMoveY(pos.y - 0.02f, 0.2f);
}
else if (Input.GetKeyDown(KeyCode.L))
{
var pos = Terrain.localPosition;
Terrain.DOLocalMoveY(pos.y + 0.02f, 0.2f);
}
}
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);
}
}
}
}
}