新增脚本

This commit is contained in:
2025-12-26 23:11:06 +08:00
parent 45129be7dc
commit 028d054705
153 changed files with 2783 additions and 15441 deletions

View 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);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5625b86b9e4b4482b82d83b962d0c873
timeCreated: 1766759973

View 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;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 98ba9d435a0e49c9bb527c34cc91894d
timeCreated: 1766759607