重新导入obi

This commit is contained in:
2026-04-06 11:35:18 +08:00
parent 05fa2d6e5e
commit ae3002a0e2
1643 changed files with 232496 additions and 13 deletions

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace Obi
{
public class ObiRopeAttach : MonoBehaviour
{
public ObiPathSmoother smoother;
[Range(0,1)]
public float m;
public void LateUpdate()
{
if (smoother != null)
{
ObiPathFrame section = smoother.GetSectionAt(m);
transform.position = smoother.transform.TransformPoint(section.position);
transform.rotation = smoother.transform.rotation * (Quaternion.LookRotation(section.tangent, section.binormal));
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 93cd44c04a2944349b4fe311545b7e05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Obi
{
/**
* This component plugs a prefab instance at each cut in the rope. Optionally, it will also place a couple instances at the start/end of an open rope.
*/
[RequireComponent(typeof(ObiRope))]
[RequireComponent(typeof(ObiPathSmoother))]
public class ObiRopePrefabPlugger : MonoBehaviour
{
public GameObject prefab; /**< prefab object being instantiated at the rope cuts.*/
public Vector3 instanceScale = Vector3.one;
public bool plugTears = true;
public bool plugStart = false;
public bool plugEnd = false;
private List<GameObject> instances; /**< instances of the prefab being rendered. */
private ObiPathSmoother smoother;
void OnEnable()
{
instances = new List<GameObject>();
smoother = GetComponent<ObiPathSmoother>();
smoother.OnCurveGenerated += UpdatePlugs;
}
void OnDisable()
{
smoother.OnCurveGenerated -= UpdatePlugs;
ClearPrefabInstances();
}
private GameObject GetOrCreatePrefabInstance(int index)
{
if (index < instances.Count)
return instances[index];
GameObject tearPrefabInstance = Instantiate(prefab);
tearPrefabInstance.hideFlags = HideFlags.HideAndDontSave;
instances.Add(tearPrefabInstance);
return tearPrefabInstance;
}
public void ClearPrefabInstances()
{
for (int i = 0; i < instances.Count; ++i)
DestroyImmediate(instances[i]);
instances.Clear();
}
// Update is called once per frame
void UpdatePlugs(ObiActor actor)
{
var rope = actor as ObiRopeBase;
// cache the rope's transform matrix/quaternion:
Matrix4x4 l2w = rope.transform.localToWorldMatrix;
Quaternion l2wRot = l2w.rotation;
int instanceIndex = 0;
// place prefabs at the start/end of each curve:
for (int c = 0; c < smoother.smoothChunks.Count; ++c)
{
ObiList<ObiPathFrame> curve = smoother.smoothChunks[c];
if ((plugTears && c > 0) ||
(plugStart && c == 0))
{
var instance = GetOrCreatePrefabInstance(instanceIndex++);
instance.SetActive(true);
ObiPathFrame frame = curve[0];
instance.transform.position = l2w.MultiplyPoint3x4(frame.position);
instance.transform.rotation = l2wRot * (Quaternion.LookRotation(-frame.tangent, frame.binormal));
instance.transform.localScale = instanceScale;
}
if ((plugTears && c < smoother.smoothChunks.Count - 1) ||
(plugEnd && c == smoother.smoothChunks.Count - 1))
{
var instance = GetOrCreatePrefabInstance(instanceIndex++);
instance.SetActive(true);
ObiPathFrame frame = curve[curve.Count - 1];
instance.transform.position = l2w.MultiplyPoint3x4(frame.position);
instance.transform.rotation = l2wRot * (Quaternion.LookRotation(frame.tangent, frame.binormal));
instance.transform.localScale = instanceScale;
}
}
// deactivate remaining instances:
for (int i = instanceIndex; i < instances.Count; ++i)
instances[i].SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4514513daf5b14cb689daa23e9d8575e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using UnityEngine;
namespace Obi
{
[RequireComponent(typeof(ObiRopeCursor))]
public class ObiRopeReel : MonoBehaviour
{
private ObiRopeCursor cursor;
private ObiRope rope;
[Header("Roll out/in thresholds")]
public float outThreshold = 0.8f;
public float inThreshold = 0.4f;
[Header("Roll out/in speeds")]
public float outSpeed = 0.05f;
public float inSpeed = 0.15f;
public void Awake()
{
cursor = GetComponent<ObiRopeCursor>();
rope = GetComponent<ObiRope>();
}
public void OnValidate()
{
// Make sure the range thresholds don't cross:
outThreshold = Mathf.Max(inThreshold, outThreshold);
}
// Update is called once per frame
void Update()
{
// get current and rest lengths:
float length = rope.CalculateLength();
float restLength = rope.restLength;
// calculate difference between current length and rest length:
float diff = Mathf.Max(0, length - restLength);
// if the rope has been stretched beyond the reel out threshold, increase its rest length:
if (diff > outThreshold)
restLength += diff * outSpeed;
// if the rope is not stretched past the reel in threshold, decrease its rest length:
if (diff < inThreshold)
restLength -= diff * inSpeed;
// set the new rest length:
cursor.ChangeLength(restLength);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4793f08b8350d44db99d1bc98daf625b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: