Installed Surge, fixed compile errors, moved a bunch of external stuff into folder

This commit is contained in:
2025-09-10 10:53:04 +02:00
parent a3649c65b0
commit 52bd7ef585
433 changed files with 10589 additions and 4 deletions

View File

@@ -0,0 +1,105 @@
/// <summary>
/// SURGE FRAMEWORK
/// Author: Bob Berkebile
/// Email: bobb@pixelplacement.com
///
/// Methods for evaluating curves.
///
/// </summary>
using UnityEngine;
namespace Pixelplacement
{
public static class BezierCurves
{
//Quadratic Bezier:
public static Vector3 GetPoint (Vector3 startPosition, Vector3 controlPoint, Vector3 endPosition, float percentage)
{
percentage = Mathf.Clamp01 (percentage);
float oneMinusT = 1f - percentage;
return oneMinusT * oneMinusT * startPosition + 2f * oneMinusT * percentage * controlPoint + percentage * percentage * endPosition;
}
public static Vector3 GetFirstDerivative (Vector3 startPoint, Vector3 controlPoint, Vector3 endPosition, float percentage)
{
percentage = Mathf.Clamp01 (percentage);
return 2f * (1f - percentage) * (controlPoint - startPoint) + 2f * percentage * (endPosition - controlPoint);
}
//Cubic Bezier:
public static Vector3 GetPoint (Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, float percentage, bool evenDistribution, int distributionSteps)
{
if (evenDistribution)
{
int maxPoint = distributionSteps + 1;
float[] arcLengths = new float[maxPoint];
Vector3 previousPoint = Locate(startPosition, endPosition, startTangent, endTangent, 0);
float sum = 0;
//store arc lengths:
for (int i = 1; i < maxPoint; i++)
{
Vector3 p = Locate(startPosition, endPosition, startTangent, endTangent, i / (float)maxPoint);
sum += Vector3.Distance(previousPoint, p);
arcLengths[i] = sum;
previousPoint = p;
}
float targetLength = percentage * arcLengths[distributionSteps];
//search:
int low = 0;
int high = distributionSteps;
int index = 0;
while (low < high)
{
index = low + (((high - low) / 2) | 0);
if (arcLengths[index] < targetLength)
{
low = index + 1;
}
else
{
high = index;
}
}
//adjust:
if (arcLengths[index] > targetLength)
{
index--;
}
float lengthBefore = arcLengths[index];
//interpolate or use as is:
if (lengthBefore == targetLength)
{
return Locate(startPosition, endPosition, startTangent, endTangent, index / distributionSteps);
}
else
{
return Locate(startPosition, endPosition, startTangent, endTangent, (index + (targetLength - lengthBefore) / (arcLengths[index + 1] - lengthBefore)) / distributionSteps);
}
}
return Locate(startPosition, endPosition, startTangent, endTangent, percentage);
}
public static Vector3 GetFirstDerivative (Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, float percentage)
{
percentage = Mathf.Clamp01 (percentage);
float oneMinusT = 1f - percentage;
return 3f * oneMinusT * oneMinusT * (startTangent - startPosition) + 6f * oneMinusT * percentage * (endTangent - startTangent) + 3f * percentage * percentage * (endPosition - endTangent);
}
private static Vector3 Locate(Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, float percentage)
{
percentage = Mathf.Clamp01(percentage);
float oneMinusT = 1f - percentage;
return oneMinusT * oneMinusT * oneMinusT * startPosition + 3f * oneMinusT * oneMinusT * percentage * startTangent + 3f * oneMinusT * percentage * percentage * endTangent + percentage * percentage * percentage * endPosition;
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 09965dbc9fd354a369b626ee0e9ba143
timeCreated: 1482974494
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 107312
packageName: Surge
packageVersion: 1.0.48
assetPath: Assets/Pixelplacement/Surge/Spline/Objects/BezierCurves.cs
uploadId: 467433

View File

@@ -0,0 +1,29 @@
/// <summary>
/// SURGE FRAMEWORK
/// Author: Bob Berkebile
/// Email: bobb@pixelplacement.com
///
/// Holds details of a spline's curve.
///
/// </summary>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Pixelplacement
{
public struct CurveDetail
{
//Public Variables:
public int currentCurve;
public float currentCurvePercentage;
//Constructor:
public CurveDetail (int currentCurve, float currentCurvePercentage)
{
this.currentCurve = currentCurve;
this.currentCurvePercentage = currentCurvePercentage;
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5612bd02e9949884bbed28239455d20e
timeCreated: 1505174773
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 107312
packageName: Surge
packageVersion: 1.0.48
assetPath: Assets/Pixelplacement/Surge/Spline/Objects/CurveDetail.cs
uploadId: 467433

View File

@@ -0,0 +1,527 @@
/// <summary>
/// SURGE FRAMEWORK
/// Author: Bob Berkebile
/// Email: bobb@pixelplacement.com
///
/// Creates and manages splines.
///
/// </summary>
using UnityEngine;
using System.Collections.Generic;
using System;
namespace Pixelplacement
{
public enum SplineDirection { Forward, Backwards }
[ExecuteInEditMode]
public class Spline : MonoBehaviour
{
//Public Events:
public event Action OnSplineChanged;
//Private Classes
private class SplineReparam
{
//Public Variables:
public float length;
public float percentage;
//Constructors:
public SplineReparam(float length, float percentage)
{
this.length = length;
this.percentage = percentage;
}
}
//Public Variables:
public Color color = Color.yellow;
[Range(0, 1)] public float toolScale = .1f;
public TangentMode defaultTangentMode;
public SplineDirection direction;
public bool loop;
public SplineFollower[] followers;
//Private Variables:
private SplineAnchor[] _anchors;
private int _curveCount;
private int _previousAnchorCount;
private int _previousChildCount;
private bool _wasLooping;
private bool _previousLoopChoice;
private bool _anchorsChanged;
private SplineDirection _previousDirection;
private float _curvePercentage = 0;
private int _operatingCurve = 0;
private float _currentCurve = 0;
private int _previousLength;
private int _slicesPerCurve = 10;
private List<SplineReparam> _splineReparams = new List<SplineReparam>();
private bool _lengthDirty = true;
//Public Properties:
public float Length
{
get;
private set;
}
public SplineAnchor[] Anchors
{
get
{
//if loop is toggled make sure we reset anchors:
if (loop != _wasLooping)
{
_previousAnchorCount = -1;
_wasLooping = loop;
}
if (!loop)
{
if (transform.childCount != _previousAnchorCount || transform.childCount == 0)
{
_anchors = GetComponentsInChildren<SplineAnchor>();
_previousAnchorCount = transform.childCount;
}
return _anchors;
}
else
{
if (transform.childCount != _previousAnchorCount || transform.childCount == 0)
{
//for a loop we need an array whose last element is the first element:
_anchors = GetComponentsInChildren<SplineAnchor>();
Array.Resize(ref _anchors, _anchors.Length + 1);
_anchors[_anchors.Length - 1] = _anchors[0];
_previousAnchorCount = transform.childCount;
}
return _anchors;
}
}
}
public Color SecondaryColor
{
get
{
Color secondaryColor = Color.Lerp(color, Color.black, .2f);
return secondaryColor;
}
}
//Init:
void Reset()
{
//if we don't have at least 2 anchors, fix it:
if (Anchors.Length < 2)
{
AddAnchors(2 - Anchors.Length);
}
}
//Loop:
void Update()
{
//place followers (if supplied and something relavent changed):
if (followers != null && followers.Length > 0 && Anchors.Length >= 2)
{
bool needToUpdate = false;
//was anything else changed?
if (_anchorsChanged || _previousChildCount != transform.childCount || direction != _previousDirection || loop != _previousLoopChoice)
{
_previousChildCount = transform.childCount;
_previousLoopChoice = loop;
_previousDirection = direction;
_anchorsChanged = false;
needToUpdate = true;
}
//were any followers moved?
for (int i = 0; i < followers.Length; i++)
{
if (followers[i].WasMoved || needToUpdate)
{
followers[i].UpdateOrientation(this);
}
}
}
//manage anchors:
bool anchorChanged = false;
if (Anchors.Length > 1)
{
for (int i = 0; i < Anchors.Length; i++)
{
//if this spline has changed notify and wipe cached percentage:
if (Anchors[i].Changed)
{
anchorChanged = true;
Anchors[i].Changed = false;
_anchorsChanged = true;
}
//if this isn't a loop then the first and last tangents are unnecessary:
if (!loop)
{
//turn first tangent off:
if (i == 0)
{
Anchors[i].SetTangentStatus(false, true);
continue;
}
//turn last tangent off:
if (i == Anchors.Length - 1)
{
Anchors[i].SetTangentStatus(true, false);
continue;
}
//turn both tangents on:
Anchors[i].SetTangentStatus(true, true);
}
else
{
//all tangents are needed in a loop:
Anchors[i].SetTangentStatus(true, true);
}
}
}
//length changed:
if (_previousLength != Anchors.Length || anchorChanged)
{
HangleLengthChange();
_previousLength = Anchors.Length;
}
}
//Event Handlers:
private void HangleLengthChange()
{
_lengthDirty = true;
//fire event:
OnSplineChanged?.Invoke();
}
//Private Methods:
private float Reparam(float percent)
{
if (_lengthDirty) CalculateLength();
//TODO: consider optimization of reversing this if the percent is > .5f to go in either direction:
for (int i = 0; i < _splineReparams.Count; i++)
{
float currentPercentage = _splineReparams[i].length / Length;
if (currentPercentage == percent)
{
return _splineReparams[i].percentage;
}
if (currentPercentage > percent)
{
float fromP = _splineReparams[i - 1].length / Length;
float toP = currentPercentage;
//slide scale to 0:
float maxAdjusted = toP - fromP;
float percentAdjusted = percent - fromP;
//find out percentage:
float inBetweenPercentage = percentAdjusted / maxAdjusted;
float location = Mathf.Lerp(_splineReparams[i - 1].percentage, _splineReparams[i].percentage, inBetweenPercentage);
return location;
}
}
return 0;
}
//Public Methods:
/// <summary>
/// Calculates the length of this spline and puts the result into the Length property.
/// </summary>
public void CalculateLength()
{
//prep:
int totalSlices = (Anchors.Length - 1) * _slicesPerCurve;
Length = 0;
_splineReparams.Clear();
//initial entries:
_splineReparams.Add(new SplineReparam(0, 0));
//find spline length:
for (int i = 1; i < totalSlices + 1; i++)
{
//percent ends:
float percent = i / (float)totalSlices;
float previousPercent = (i - 1) / (float)totalSlices;
//position ends:
Vector3 start = GetPosition(previousPercent, false);
Vector3 end = GetPosition(percent, false);
//length:
float distance = Vector3.Distance(start, end);
Length += distance;
//reparameterization cache:
_splineReparams.Add(new SplineReparam(Length, percent));
}
_lengthDirty = false;
return;
}
/// <summary>
/// Get the up vector at a percentage along the spline.
/// </summary>
public Vector3 Up(float percentage, bool normalized = true)
{
Quaternion lookRotation = Quaternion.LookRotation(GetDirection(percentage, normalized));
return lookRotation * Vector3.up;
}
/// <summary>
/// Get the right vector at a percentage along the spline.
/// </summary>
public Vector3 Right(float percentage, bool normalized = true)
{
Quaternion lookRotation = Quaternion.LookRotation(GetDirection(percentage, normalized));
return lookRotation * Vector3.right;
}
/// <summary>
/// Get the forward vector at a percentage along the spline - this is simply a wrapper for the direction since they are the same thing.
/// </summary>
public Vector3 Forward(float percentage, bool normalized = true)
{
return GetDirection(percentage, normalized);
}
/// <summary>
/// Returns a facing vector at the given percentage along the spline to allow content to properly orient along the spline.
/// </summary>
public Vector3 GetDirection(float percentage, bool normalized = true)
{
if (normalized) percentage = Reparam(percentage);
//get direction:
CurveDetail curveDetail = GetCurve(percentage);
//avoid an error in editor usage where this index can be -1:
if (curveDetail.currentCurve < 0) return Vector3.zero;
SplineAnchor startAnchor = Anchors[curveDetail.currentCurve];
SplineAnchor endAnchor = Anchors[curveDetail.currentCurve + 1];
return BezierCurves.GetFirstDerivative(startAnchor.Anchor.position, endAnchor.Anchor.position, startAnchor.OutTangent.position, endAnchor.InTangent.position, curveDetail.currentCurvePercentage).normalized;
}
/// <summary>
/// Returns a position on the spline at the given percentage.
/// </summary>
public Vector3 GetPosition(float percentage, bool normalized = true)
{
if (normalized) percentage = Reparam(percentage);
//evaluate curve:
CurveDetail curveDetail = GetCurve(percentage);
//avoid an error in editor usage where this index can be -1:
if (curveDetail.currentCurve < 0) return Vector3.zero;
SplineAnchor startAnchor = Anchors[curveDetail.currentCurve];
SplineAnchor endAnchor = Anchors[curveDetail.currentCurve + 1];
return BezierCurves.GetPoint(startAnchor.Anchor.position, endAnchor.Anchor.position, startAnchor.OutTangent.position, endAnchor.InTangent.position, curveDetail.currentCurvePercentage, true, 100);
}
/// <summary>
/// Returns a position on the spline at the given percentage with a relative offset.
/// </summary>
public Vector3 GetPosition(float percentage, Vector3 relativeOffset, bool normalized = true)
{
if (normalized) percentage = Reparam(percentage);
//get position and look rotation:
Vector3 position = GetPosition(percentage);
Quaternion lookRotation = Quaternion.LookRotation(GetDirection(percentage));
//get each axis at the current position:
Vector3 up = lookRotation * Vector3.up;
Vector3 right = lookRotation * Vector3.right;
Vector3 forward = lookRotation * Vector3.forward;
//translate position:
Vector3 offset = position + right * relativeOffset.x;
offset += up * relativeOffset.y;
offset += forward * relativeOffset.z;
return offset;
}
/// <summary>
/// Given a world point and a number of divisions (think resolution) this returns the closest point on the spline.
/// </summary>
public float ClosestPoint(Vector3 point, int divisions = 100)
{
//make sure we have at least one division:
if (divisions <= 0) divisions = 1;
//variables:
float shortestDistance = float.MaxValue;
Vector3 position = Vector3.zero;
Vector3 offset = Vector3.zero;
float closestPercentage = 0;
float percentage = 0;
float distance = 0;
//iterate spline and find the closest point on the spline to the provided point:
for (float i = 0; i < divisions + 1; i++)
{
percentage = i / divisions;
position = GetPosition(percentage);
offset = position - point;
distance = offset.sqrMagnitude;
//if this point is closer than any others so far:
if (distance < shortestDistance)
{
shortestDistance = distance;
closestPercentage = percentage;
}
}
return closestPercentage;
}
/// <summary>
/// Makes a spline longer.
/// </summary>
public GameObject[] AddAnchors(int count)
{
//refs:
GameObject anchorTemplate = Resources.Load("Anchor") as GameObject;
//create return array:
GameObject[] returnObjects = new GameObject[count];
for (int i = 0; i < count; i++)
{
//previous anchor refs:
Transform previousPreviousAnchor = null;
Transform previousAnchor = null;
if (Anchors.Length == 1)
{
previousPreviousAnchor = transform;
previousAnchor = Anchors[0].transform;
}
else if (Anchors.Length > 1)
{
previousPreviousAnchor = Anchors[Anchors.Length - 2].transform;
previousAnchor = Anchors[Anchors.Length - 1].transform;
}
//create a new anchor:
GameObject newAnchor = Instantiate<GameObject>(anchorTemplate);
newAnchor.name = newAnchor.name.Replace("(Clone)", "");
SplineAnchor anchor = newAnchor.GetComponent<SplineAnchor>();
anchor.tangentMode = defaultTangentMode;
newAnchor.transform.parent = transform;
newAnchor.transform.rotation = Quaternion.LookRotation(transform.forward);
//tilt tangents for variety as we add new anchors:
//anchor.Tilt (new Vector3 (0, 0, 0));
anchor.InTangent.Translate(Vector3.up * .5f);
anchor.OutTangent.Translate(Vector3.up * -.5f);
//position new anchor:
if (previousPreviousAnchor != null && previousAnchor != null)
{
//determine direction for next placement:
Vector3 direction = (previousAnchor.position - previousPreviousAnchor.position).normalized;
if (direction == Vector3.zero) direction = transform.forward;
//place from the previous anchor in the correct direction:
newAnchor.transform.position = previousAnchor.transform.position + (direction * 1.5f);
}
else
{
newAnchor.transform.localPosition = Vector3.zero;
}
//catalog this new anchor for return:
returnObjects[i] = newAnchor;
}
return returnObjects;
}
/// <summary>
/// Gets the current curve at the percentage.
/// </summary>
public CurveDetail GetCurve(float percentage)
{
//clamp or loop percentage:
if (loop)
{
percentage = Mathf.Repeat(percentage, 1);
}
else
{
percentage = Mathf.Clamp01(percentage);
}
//curve identification and evaluation:
if (Anchors.Length == 2)
{
//direction reversed?
if (direction == SplineDirection.Backwards)
{
percentage = 1 - percentage;
}
//simply evaluate the curve since there is only one:
return new CurveDetail(0, percentage);
}
else
{
//figure out which curve we are operating on from the spline and a percentage along it:
_curveCount = Anchors.Length - 1;
_currentCurve = _curveCount * percentage;
if ((int)_currentCurve == _curveCount)
{
_currentCurve = _curveCount - 1;
_curvePercentage = 1;
}
else
{
_curvePercentage = _currentCurve - (int)_currentCurve;
}
_currentCurve = (int)_currentCurve;
_operatingCurve = (int)_currentCurve;
//direction reversed?
if (direction == SplineDirection.Backwards)
{
_curvePercentage = 1 - _curvePercentage;
_operatingCurve = (_curveCount - 1) - _operatingCurve;
}
return new CurveDetail(_operatingCurve, _curvePercentage);
}
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f1ec11ed173ba4d8d99e75c4bf174d82
timeCreated: 1483123464
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 107312
packageName: Surge
packageVersion: 1.0.48
assetPath: Assets/Pixelplacement/Surge/Spline/Objects/Spline.cs
uploadId: 467433

View File

@@ -0,0 +1,268 @@
/// <summary>
/// SURGE FRAMEWORK
/// Author: Bob Berkebile
/// Email: bobb@pixelplacement.com
///
/// Interface for a spline's anchor and tangents.
///
/// </summary>
using UnityEngine;
using System.Collections;
namespace Pixelplacement
{
public enum TangentMode {Mirrored, Aligned, Free}
[ExecuteInEditMode]
public class SplineAnchor : MonoBehaviour
{
//Public Variables:
public TangentMode tangentMode;
//Public Properties:
public bool RenderingChange
{
get; set;
}
public bool Changed
{
get; set;
}
public Transform Anchor
{
get
{
if (!_initialized) Initialize();
return _anchor;
}
private set
{
_anchor = value;
}
}
public Transform InTangent
{
get
{
if (!_initialized) Initialize();
return _inTangent;
}
private set
{
_inTangent = value;
}
}
public Transform OutTangent
{
get
{
if (!_initialized) Initialize();
return _outTangent;
}
private set
{
_outTangent = value;
}
}
//Private Variables:
bool _initialized;
[SerializeField][HideInInspector] Transform _masterTangent;
[SerializeField][HideInInspector] Transform _slaveTangent;
TangentMode _previousTangentMode;
Vector3 _previousInPosition;
Vector3 _previousOutPosition;
Vector3 _previousAnchorPosition;
Bounds _skinnedBounds;
Transform _anchor;
Transform _inTangent;
Transform _outTangent;
//Init:
void Awake ()
{
Initialize ();
}
//Loop:
void Update ()
{
//don't let an anchor scale:
transform.localScale = Vector3.one;
//initialization:
if (!_initialized)
{
Initialize ();
}
//override any skinned mesh bounds changes:
Anchor.localPosition = Vector3.zero;
//has the anchor moved?
if (_previousAnchorPosition != transform.position)
{
Changed = true;
RenderingChange = true;
_previousAnchorPosition = transform.position;
}
//run a tangent operation if mode has changed:
if (_previousTangentMode != tangentMode)
{
Changed = true;
RenderingChange = true;
TangentChanged ();
_previousTangentMode = tangentMode;
}
//detect tangent movements:
if (InTangent.localPosition != _previousInPosition)
{
Changed = true;
RenderingChange = true;
_previousInPosition = InTangent.localPosition;
_masterTangent = InTangent;
_slaveTangent = OutTangent;
TangentChanged ();
return;
}
if (OutTangent.localPosition != _previousOutPosition)
{
Changed = true;
RenderingChange = true;
_previousOutPosition = OutTangent.localPosition;
_masterTangent = OutTangent;
_slaveTangent = InTangent;
TangentChanged ();
return;
}
}
//Private Methods:
void TangentChanged ()
{
//calculate tangent positions:
switch (tangentMode)
{
case TangentMode.Free:
break;
case TangentMode.Mirrored:
Vector3 mirroredOffset = _masterTangent.position - transform.position;
_slaveTangent.position = transform.position - mirroredOffset;
break;
case TangentMode.Aligned:
float distance = Vector3.Distance (_slaveTangent.position, transform.position);
Vector3 alignedOffset = (_masterTangent.position - transform.position).normalized;
_slaveTangent.position = transform.position - (alignedOffset * distance);
break;
}
//cache tangent positions:
_previousInPosition = InTangent.localPosition;
_previousOutPosition = OutTangent.localPosition;
}
//Private Methods:
void Initialize ()
{
_initialized = true;
//grabs references:
InTangent = transform.GetChild (0);
OutTangent = transform.GetChild (1);
Anchor = transform.GetChild (2);
//prepopulate master and slave tangents:
_masterTangent = InTangent;
_slaveTangent = OutTangent;
//hide some things to reduce clutter:
Anchor.hideFlags = HideFlags.HideInHierarchy;
foreach (var item in GetComponentsInChildren<Renderer>())
{
if (Application.isEditor)
{
item.sharedMaterial.hideFlags = HideFlags.HideInInspector;
}
else
{
Destroy(item);
}
}
foreach (var item in GetComponentsInChildren<MeshFilter>())
{
if (Application.isEditor)
{
item.hideFlags = HideFlags.HideInInspector;
}
else
{
Destroy(item);
}
}
foreach (var item in GetComponentsInChildren<MeshRenderer>())
{
if (Application.isEditor)
{
item.hideFlags = HideFlags.HideInInspector;
}
else
{
Destroy(item);
}
}
foreach (var item in GetComponentsInChildren<SkinnedMeshRenderer>())
{
if (Application.isEditor)
{
item.hideFlags = HideFlags.HideInInspector;
}
}
//synchronize status variables:
_previousTangentMode = tangentMode;
_previousInPosition = InTangent.localPosition;
_previousOutPosition = OutTangent.localPosition;
_previousAnchorPosition = transform.position;
}
//Public Methods:
public void SetTangentStatus (bool inStatus, bool outStatus)
{
InTangent.gameObject.SetActive (inStatus);
OutTangent.gameObject.SetActive (outStatus);
}
public void Tilt (Vector3 angles)
{
//save current rotation and rotate as requested:
Quaternion rotation = transform.localRotation;
transform.Rotate (angles);
//get world position of tangents:
Vector3 inPosition = InTangent.position;
Vector3 outPosition = OutTangent.position;
//reverse rotation and set tangent positions:
//transform.localRotation = rotation;
InTangent.position = inPosition;
OutTangent.position = outPosition;
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 486ab05eb713a42cbb73a3d0cadf09ed
timeCreated: 1483118697
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 107312
packageName: Surge
packageVersion: 1.0.48
assetPath: Assets/Pixelplacement/Surge/Spline/Objects/SplineAnchor.cs
uploadId: 467433

View File

@@ -0,0 +1,65 @@
/// <summary>
/// SURGE FRAMEWORK
/// Author: Bob Berkebile
/// Email: bobb@pixelplacement.com
///
/// Used for easily attaching objects to a spline for inspector usage.
///
/// </summary>
using UnityEngine;
using System.Collections;
namespace Pixelplacement
{
[System.Serializable]
public class SplineFollower
{
//Public Variables:
public Transform target;
public float percentage = -1;
public bool faceDirection;
//Public Properties:
public bool WasMoved
{
get
{
if (percentage != _previousPercentage || faceDirection != _previousFaceDirection) {
_previousPercentage = percentage;
_previousFaceDirection = faceDirection;
return true;
} else {
return false;
}
}
}
//Private Variables:
float _previousPercentage;
bool _previousFaceDirection;
bool _detached;
//Public Methods:
public void UpdateOrientation (Spline spline)
{
if (target == null) return;
//clamp percentage:
if (!spline.loop) percentage = Mathf.Clamp01 (percentage);
//look in direction of spline?
if (faceDirection)
{
if (spline.direction == SplineDirection.Forward)
{
target.LookAt (target.position + spline.GetDirection (percentage));
}else{
target.LookAt (target.position - spline.GetDirection (percentage));
}
}
target.position = spline.GetPosition (percentage);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 484db4cb0f8e7f24b8e7012ba84c9e47
timeCreated: 1485806915
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 107312
packageName: Surge
packageVersion: 1.0.48
assetPath: Assets/Pixelplacement/Surge/Spline/Objects/SplineFollower.cs
uploadId: 467433

View File

@@ -0,0 +1,19 @@
/// <summary>
/// SURGE FRAMEWORK
/// Author: Bob Berkebile
/// Email: bobb@pixelplacement.com
///
/// A helper for allowing correct selection in the scene view instead of choosing the prefab root which is normal Unity operation.
///
/// </summary>
using UnityEngine;
using System.Collections;
namespace Pixelplacement
{
[SelectionBase]
public class SplineTangent : MonoBehaviour
{
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5980d28f81eb545d78e1d84e1449a10f
timeCreated: 1483149639
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 107312
packageName: Surge
packageVersion: 1.0.48
assetPath: Assets/Pixelplacement/Surge/Spline/Objects/SplineTangent.cs
uploadId: 467433