Transitioning - Done!
This commit is contained in:
parent
76edfff94f
commit
53c23effe5
@ -154,6 +154,9 @@ MonoBehaviour:
|
|||||||
type: 3}
|
type: 3}
|
||||||
resolution: 50
|
resolution: 50
|
||||||
function: 4
|
function: 4
|
||||||
|
transitionMode: 2
|
||||||
|
functionDuration: 1
|
||||||
|
transitionDuration: 1
|
||||||
--- !u!4 &75389716
|
--- !u!4 &75389716
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -768,3 +771,5 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
display: {fileID: 1844483591}
|
display: {fileID: 1844483591}
|
||||||
|
displayMode: 0
|
||||||
|
sampleDuration: 1
|
||||||
|
@ -3,7 +3,7 @@ using static UnityEngine.Mathf;
|
|||||||
|
|
||||||
public static class FunctionLibrary
|
public static class FunctionLibrary
|
||||||
{
|
{
|
||||||
public delegate Vector3 Function(float u, float v, float y);
|
public delegate Vector3 Function(float u, float v, float t);
|
||||||
|
|
||||||
public enum FunctionName { Wave, MultiWave, Ripple, Sphere, Torus }
|
public enum FunctionName { Wave, MultiWave, Ripple, Sphere, Torus }
|
||||||
|
|
||||||
@ -84,4 +84,9 @@ public static class FunctionLibrary
|
|||||||
p.z = s * Cos(PI * u);
|
p.z = s * Cos(PI * u);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vector3 Morph(float u, float v, float t, Function from, Function to, float progress)
|
||||||
|
{
|
||||||
|
return Vector3.LerpUnclamped(from(u, v, t), to(u, v, t), SmoothStep(0.0f, 1.0f, progress));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,17 @@ public class Graph : MonoBehaviour
|
|||||||
[SerializeField, Min(0.0f)]
|
[SerializeField, Min(0.0f)]
|
||||||
float functionDuration = 1.0f;
|
float functionDuration = 1.0f;
|
||||||
|
|
||||||
|
[SerializeField, Min(0.0f)]
|
||||||
|
float transitionDuration = 1.0f;
|
||||||
|
|
||||||
Transform[] points;
|
Transform[] points;
|
||||||
|
|
||||||
float duration = 0.0f;
|
float duration = 0.0f;
|
||||||
|
|
||||||
|
bool transitioning;
|
||||||
|
|
||||||
|
FunctionLibrary.FunctionName transitionFunction;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
var step = 2f / resolution;
|
var step = 2f / resolution;
|
||||||
@ -40,13 +47,30 @@ public class Graph : MonoBehaviour
|
|||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
duration += Time.deltaTime;
|
duration += Time.deltaTime;
|
||||||
if (duration >= functionDuration)
|
if (transitioning)
|
||||||
|
{
|
||||||
|
if (duration >= transitionDuration)
|
||||||
|
{
|
||||||
|
duration -= transitionDuration;
|
||||||
|
transitioning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (duration >= functionDuration)
|
||||||
{
|
{
|
||||||
duration -= functionDuration;
|
duration -= functionDuration;
|
||||||
|
transitioning = true;
|
||||||
|
transitionFunction = function;
|
||||||
PickNextFunction();
|
PickNextFunction();
|
||||||
}
|
}
|
||||||
|
if (transitioning)
|
||||||
|
{
|
||||||
|
UpdateFunctionTransition();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
UpdateFunction();
|
UpdateFunction();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void PickNextFunction()
|
private void PickNextFunction()
|
||||||
{
|
{
|
||||||
@ -54,7 +78,6 @@ public class Graph : MonoBehaviour
|
|||||||
function = transitionMode == TransitionMode.Cycle ?
|
function = transitionMode == TransitionMode.Cycle ?
|
||||||
FunctionLibrary.GetNextFunctionName(function) :
|
FunctionLibrary.GetNextFunctionName(function) :
|
||||||
FunctionLibrary.GetRandomFunctionNameOtherThan(function);
|
FunctionLibrary.GetRandomFunctionNameOtherThan(function);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateFunction()
|
private void UpdateFunction()
|
||||||
@ -76,4 +99,25 @@ public class Graph : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateFunctionTransition()
|
||||||
|
{
|
||||||
|
FunctionLibrary.Function
|
||||||
|
from = FunctionLibrary.GetFunction(transitionFunction),
|
||||||
|
to = FunctionLibrary.GetFunction(function);
|
||||||
|
float progress = duration / transitionDuration;
|
||||||
|
float time = Time.time;
|
||||||
|
float step = 2f / resolution;
|
||||||
|
float v = 0.5f * step - 1f;
|
||||||
|
for (int i = 0, x = 0, z = 0; i < points.Length; i++, x++)
|
||||||
|
{
|
||||||
|
if (x == resolution)
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
z += 1;
|
||||||
|
v = (z + 0.5f) * step - 1f;
|
||||||
|
}
|
||||||
|
float u = (x + 0.5f) * step - 1f;
|
||||||
|
points[i].localPosition = FunctionLibrary.Morph(u, v, time, from, to, progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user