修改为joint
This commit is contained in:
197
Assets/Scripts/Fishing/New/View/Player/FishingLine/FLine.cs
Normal file
197
Assets/Scripts/Fishing/New/View/Player/FishingLine/FLine.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NBC;
|
||||
// using Obi;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public enum LineType
|
||||
{
|
||||
Hand,
|
||||
HandDouble,
|
||||
Spinning,
|
||||
SpinningFloat,
|
||||
}
|
||||
|
||||
public class FLine : FGearBase
|
||||
{
|
||||
public LineType LineType;
|
||||
|
||||
|
||||
[Header("连接点配置")] [SerializeField] private Transform anchorTransform;
|
||||
[SerializeField] private List<FLineLogicNode> lineNodes = new List<FLineLogicNode>();
|
||||
[SerializeField] private bool isLureConnect;
|
||||
[SerializeField] private RodLine rodLine;
|
||||
|
||||
/// <summary>
|
||||
/// 主线
|
||||
/// </summary>
|
||||
[SerializeField] private Rope fishingRope;
|
||||
|
||||
/// <summary>
|
||||
/// 浮漂和鱼钩线
|
||||
/// </summary>
|
||||
[SerializeField] private Rope bobberRope;
|
||||
|
||||
// public LureController Lure;
|
||||
// public BobberController Bobber;
|
||||
//
|
||||
// public JointPinchController PinchController;
|
||||
|
||||
public FLineLogicNode StartNode { get; private set; }
|
||||
public FLineLogicNode BobberNode => GetNode(FLineLogicNodeType.Bobber);
|
||||
public FLineLogicNode EndNode { get; private set; }
|
||||
|
||||
|
||||
public float LinelenghtDiferent;
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
var tipRb = Rod.Asset.LineConnectorRigidbody;
|
||||
if (isLureConnect)
|
||||
{
|
||||
// Lure.SetJoint(tipRb);
|
||||
// Lure.EnableCollision(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
fishingRope.startAnchor = tipRb;
|
||||
// Bobber.SetJoint(tipRb);
|
||||
// Lure.SetJoint(Bobber.rbody);
|
||||
// Lure.gameObject.SetActive(true);
|
||||
// Lure.EnableCollision(false);
|
||||
// Lure.SetKinematic(false);
|
||||
}
|
||||
|
||||
GetComponentsInChildren<Transform>(includeInactive: true).ToList().ForEach(delegate(Transform i)
|
||||
{
|
||||
i.gameObject.SetActive(true);
|
||||
});
|
||||
|
||||
StartCoroutine(LureUseGravity());
|
||||
if (isLureConnect)
|
||||
{
|
||||
fishingRope.Init(Rod);
|
||||
}
|
||||
else
|
||||
{
|
||||
fishingRope.Init(Rod);
|
||||
bobberRope.Init(Rod);
|
||||
}
|
||||
|
||||
// rodLine.GenerateLineRendererRope(guides.ToArray(), _LineThickness);
|
||||
}
|
||||
|
||||
private IEnumerator LureUseGravity()
|
||||
{
|
||||
yield return 1;
|
||||
EndNode.gameObject.SetActive(false);
|
||||
EndNode.gameObject.SetActive(true);
|
||||
yield return 1;
|
||||
EndNode.Rigidbody.useGravity = true;
|
||||
}
|
||||
|
||||
public void SetTargetLength(float value)
|
||||
{
|
||||
Log.Error($"SetObiRopeStretch={value}");
|
||||
if (value > 3)
|
||||
{
|
||||
// value -= 0.2f;
|
||||
}
|
||||
|
||||
fishingRope.SetTargetLength(value);
|
||||
}
|
||||
|
||||
public void SetLureLength(float value)
|
||||
{
|
||||
Log.Error($"SetObiRopeStretch={value}");
|
||||
bobberRope.SetTargetLength(value);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartNode = GetNode(FLineLogicNodeType.Start);
|
||||
EndNode = GetNode(FLineLogicNodeType.End);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
LinelenghtDiferent = GetLineDistance();
|
||||
|
||||
//非钓鱼状态
|
||||
Rod.PlayerItem.Tension = Mathf.Clamp(LinelenghtDiferent, 0f, 0.05f);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateAnchorNode();
|
||||
}
|
||||
|
||||
#region 连接点
|
||||
|
||||
private void UpdateAnchorNode()
|
||||
{
|
||||
if (anchorTransform == null || lineNodes.Count < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var startNode = lineNodes[0].Rigidbody;
|
||||
startNode.transform.SetPositionAndRotation(anchorTransform.position, anchorTransform.rotation);
|
||||
|
||||
if (!startNode.isKinematic)
|
||||
{
|
||||
startNode.linearVelocity = Vector3.zero;
|
||||
startNode.angularVelocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个节点
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public FLineLogicNode GetNode(FLineLogicNodeType type)
|
||||
{
|
||||
foreach (var node in lineNodes)
|
||||
{
|
||||
if (node.NodeType == type)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetLenght(float lenght, FLineLogicNodeType type = FLineLogicNodeType.Bobber)
|
||||
{
|
||||
var node = GetNode(type);
|
||||
if (node != null)
|
||||
{
|
||||
node.SetLenght(lenght);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tension
|
||||
|
||||
private float GetLineDistance()
|
||||
{
|
||||
//第一个节点到竿稍的位置-第一段鱼线长度
|
||||
return Vector3.Distance(StartNode.transform.position, bobberRope.transform.position) -
|
||||
fishingRope.GetCurrentLength();
|
||||
}
|
||||
|
||||
public float GetTension(float weight)
|
||||
{
|
||||
return weight * GetLineDistance();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user