新增脚本
This commit is contained in:
56
Assets/Scripts/Fishing/Rope/RodLine.cs
Normal file
56
Assets/Scripts/Fishing/Rope/RodLine.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Obi;
|
||||
using UnityEngine;
|
||||
|
||||
public class RodLine : MonoBehaviour
|
||||
{
|
||||
private ObiRope obiRope;
|
||||
|
||||
private LineRenderer lineRenderer;
|
||||
|
||||
private Transform[] points;
|
||||
|
||||
public void GenerateLineRendererRope(Transform[] points, float thickness)
|
||||
{
|
||||
if (points.Length < 2)
|
||||
{
|
||||
Debug.LogError("LineRenderer requires at least two points.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.points = points;
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
lineRenderer = base.gameObject.GetComponent<LineRenderer>();
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
lineRenderer = base.gameObject.AddComponent<LineRenderer>();
|
||||
}
|
||||
}
|
||||
|
||||
lineRenderer.positionCount = points.Length;
|
||||
lineRenderer.startWidth = thickness;
|
||||
lineRenderer.endWidth = thickness;
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
lineRenderer.SetPosition(i, points[i].position);
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
Transform transform = points[i];
|
||||
if ((bool)transform)
|
||||
{
|
||||
lineRenderer.SetPosition(i, transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Rope/RodLine.cs.meta
Normal file
3
Assets/Scripts/Fishing/Rope/RodLine.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5625b86b9e4b4482b82d83b962d0c873
|
||||
timeCreated: 1766759973
|
||||
35
Assets/Scripts/Fishing/Rope/Rope.cs
Normal file
35
Assets/Scripts/Fishing/Rope/Rope.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using NBF;
|
||||
using Obi;
|
||||
using UnityEngine;
|
||||
|
||||
public class Rope : MonoBehaviour
|
||||
{
|
||||
private FRod _rod;
|
||||
[SerializeField] private ObiRope rope;
|
||||
|
||||
[SerializeField] private ObiRopeCursor cursor;
|
||||
|
||||
[SerializeField] private float percentageElasticity = 0.2f;
|
||||
|
||||
private float stretchScale;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rope = GetComponent<ObiRope>();
|
||||
if (_rod)
|
||||
{
|
||||
LineLength_OnValueChanged(_rod.lineLength);
|
||||
}
|
||||
}
|
||||
|
||||
public void LineLength_OnValueChanged(float length)
|
||||
{
|
||||
cursor = ((cursor == null) ? GetComponent<ObiRopeCursor>() : cursor);
|
||||
stretchScale = Mathf.Clamp(length - percentageElasticity, 0f, float.PositiveInfinity);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
rope.stretchingScale = stretchScale;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Rope/Rope.cs.meta
Normal file
3
Assets/Scripts/Fishing/Rope/Rope.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98ba9d435a0e49c9bb527c34cc91894d
|
||||
timeCreated: 1766759607
|
||||
Reference in New Issue
Block a user