将Spline移出Plugin,以调整SplineRenderer的OnWillCameraRender

This commit is contained in:
SoulliesOfficial
2025-03-01 22:58:20 -05:00
parent 860d7393fb
commit 5d775ae687
529 changed files with 237 additions and 119 deletions

View File

@@ -0,0 +1,51 @@
namespace Dreamteck.Splines
{
using UnityEngine;
public class ObjectControllerCustomRuleBase : ScriptableObject
{
protected ObjectController currentController;
protected SplineSample currentSample;
protected int currentObjectIndex;
protected int totalObjects;
protected float currentObjectPercent
{
get { return (float)currentObjectIndex / (totalObjects - 1); }
}
public void SetContext(ObjectController context, SplineSample sample, int currentObject, int totalObjects)
{
currentController = context;
currentSample = sample;
this.currentObjectIndex = currentObject;
this.totalObjects = totalObjects;
}
/// <summary>
/// Implement this method to create custom positioning behaviors. The returned offset should be in local coordinates.
/// </summary>
/// <returns>Vector3 offset in local coordinates</returns>
public virtual Vector3 GetOffset()
{
return currentSample.position;
}
/// <summary>
/// Implement this method to create custom rotation behaviors. The returned rotation is in world space
/// </summary>
/// <returns>Quaternion rotation in world coordinates</returns>
public virtual Quaternion GetRotation()
{
return currentSample.rotation;
}
/// <summary>
/// Implement this method to create custom scaling behaviors.
/// </summary>
/// <returns>Vector3 scale</returns>
public virtual Vector3 GetScale()
{
return Vector3.one * currentSample.size;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a81cd2dca8dd58a46a1ff2451e09a21e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 956119420e783ba4e8c22ab8c32ed5e8, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
namespace Dreamteck.Splines
{
using UnityEngine;
//Use the CreateAssetMenu attribute to add the object to the Create Asset context menu
//After that, go to Assets/Create/Dreamteck/Splines/... and create the scriptable object
[CreateAssetMenu(menuName = "Dreamteck/Splines/Object Controller Rules/Sine Rule")]
public class ObjectControllerSineRule : ObjectControllerCustomRuleBase
{
[SerializeField] private bool _useSplinePercent = false;
[SerializeField] private float _frequency = 1f;
[SerializeField] private float _amplitude = 1f;
[SerializeField] private float _angle = 0f;
[SerializeField] private float _minScale = 1f;
[SerializeField] private float _maxScale = 1f;
[SerializeField] [Range(0f, 1f)] private float _offset = 0f;
public bool useSplinePercent
{
get { return _useSplinePercent; }
set { _useSplinePercent = value; }
}
public float frequency
{
get { return _frequency; }
set { _frequency = value; }
}
public float amplitude
{
get { return _amplitude; }
set { _amplitude = value; }
}
public float angle
{
get { return _angle; }
set { _angle = value; }
}
public float minScale
{
get { return _minScale; }
set { _minScale = value; }
}
public float maxScale
{
get { return _maxScale; }
set { _maxScale = value; }
}
public float offset
{
get { return _offset; }
set {
_offset = value;
if(_offset > 1)
{
_offset -= Mathf.FloorToInt(_offset);
}
if(_offset < 0)
{
_offset += Mathf.FloorToInt(-_offset);
}
}
}
//Override GetOffset, GetRotation and GetScale to implement custom behaviors
//Use the information from currentSample, currentObjectIndex, totalObjects and currentObjectPercent
public override Vector3 GetOffset()
{
float sin = GetSine();
return Quaternion.AngleAxis(_angle, Vector3.forward) * Vector3.up * sin * _amplitude;
}
public override Vector3 GetScale()
{
return Vector3.Lerp(Vector3.one * _minScale, Vector3.one * _maxScale, GetSine());
}
private float GetSine()
{
float objectPercent = _useSplinePercent ? (float)currentSample.percent : currentObjectPercent;
return Mathf.Sin((Mathf.PI * _offset) + objectPercent * Mathf.PI * _frequency);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 34dc4bc87da1557438d48f8b38533bd8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 956119420e783ba4e8c22ab8c32ed5e8, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
namespace Dreamteck.Splines
{
using UnityEngine;
//Use the CreateAssetMenu attribute to add the object to the Create Asset context menu
//After that, go to Assets/Create/Dreamteck/Splines/... and create the scriptable object
[CreateAssetMenu(menuName = "Dreamteck/Splines/Object Controller Rules/Spiral Rule")]
public class ObjectControllerSpiralRule : ObjectControllerCustomRuleBase
{
[SerializeField] private bool _useSplinePercent = false;
[SerializeField] private float _revolve = 360f;
[SerializeField] private Vector2 _startSize = Vector2.one;
[SerializeField] private Vector2 _endSize = Vector2.one;
[SerializeField] [Range(0f, 1f)] private float _offset = 0f;
public bool useSplinePercent
{
get { return _useSplinePercent; }
set { _useSplinePercent = value; }
}
public float revolve
{
get { return _revolve; }
set { _revolve = value; }
}
public Vector2 startSize
{
get { return _startSize; }
set { _startSize = value; }
}
public Vector2 endSize
{
get { return _endSize; }
set { _endSize = value; }
}
public float offset
{
get { return _offset; }
set {
_offset = value;
if(_offset > 1)
{
_offset -= Mathf.FloorToInt(_offset);
}
if(_offset < 0)
{
_offset += Mathf.FloorToInt(-_offset);
}
}
}
//Override GetOffset, GetRotation and GetScale to implement custom behaviors
//Use the information from currentSample, currentObjectIndex, totalObjects and currentObjectPercent
public override Vector3 GetOffset()
{
Vector3 offset = Quaternion.AngleAxis(_revolve * GetPercent(), Vector3.forward) * Vector3.up;
Vector2 scale = Vector2.Lerp(_startSize, _endSize, GetPercent());
offset.x *= scale.x;
offset.y *= scale.y;
return offset;
}
public override Quaternion GetRotation()
{
return currentSample.rotation * Quaternion.AngleAxis(_revolve * -GetPercent(), Vector3.forward);
}
private float GetPercent()
{
float percent = _useSplinePercent ? (float)currentSample.percent : currentObjectPercent + _offset;
if (percent > 1)
{
percent -= Mathf.FloorToInt(percent);
}
if (percent < 0)
{
percent += Mathf.FloorToInt(-percent);
}
return percent;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: daebc70828e501444b23046e124e96f4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 956119420e783ba4e8c22ab8c32ed5e8, type: 3}
userData:
assetBundleName:
assetBundleVariant: