添加插件

This commit is contained in:
2025-11-10 00:08:26 +08:00
parent 4059c207c0
commit 76f80db694
2814 changed files with 436400 additions and 178 deletions

View File

@@ -0,0 +1,50 @@
using UnityEngine;
namespace Obi.Samples
{
public class PinholeRatchet : MonoBehaviour
{
public ObiPinhole pinhole;
public bool direction = false;
public float teethSeparation = 0.1f;
public float distanceToNextTooth { get; private set; }
void Update()
{
if (pinhole == null || pinhole.rope == null)
return;
float restLength = (pinhole.rope as ObiRopeBase).restLength;
float normalizedTeethDistance = Mathf.Max(0.001f, teethSeparation / restLength);
var range = pinhole.range;
if (direction)
{
distanceToNextTooth = (range.y - pinhole.position) * restLength;
while (distanceToNextTooth > teethSeparation)
{
range.y -= normalizedTeethDistance;
distanceToNextTooth -= teethSeparation;
}
}
else
{
distanceToNextTooth = (pinhole.position - range.x) * restLength;
while (distanceToNextTooth > teethSeparation)
{
range.x += normalizedTeethDistance;
distanceToNextTooth -= teethSeparation;
}
}
pinhole.range = range;
}
public void OnDisable()
{
if (pinhole != null)
pinhole.range = new Vector2(0, 1);
}
}
}