62 lines
1.1 KiB
C#
62 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Warps/Sinus Curve")]
|
|
public class MegaSinusCurveWarp : MegaWarp
|
|
{
|
|
public float scale = 1f;
|
|
|
|
public float wave = 1f;
|
|
|
|
public float speed = 1f;
|
|
|
|
public float phase;
|
|
|
|
public bool animate;
|
|
|
|
private Matrix4x4 mat = default(Matrix4x4);
|
|
|
|
public override string WarpName()
|
|
{
|
|
return "Sinus Curve";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "Bubble.htm";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
Vector3 a = p;
|
|
float magnitude = p.magnitude;
|
|
float t = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude));
|
|
p.y += Mathf.Sin(phase + p.x * wave + p.y + p.z) * scale;
|
|
p = Vector3.Lerp(a, p, t);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (animate)
|
|
{
|
|
phase += Time.deltaTime * speed;
|
|
}
|
|
Prepare(Decay);
|
|
}
|
|
|
|
public override bool Prepare(float decay)
|
|
{
|
|
totaldecay = Decay + decay;
|
|
if (totaldecay < 0f)
|
|
{
|
|
totaldecay = 0f;
|
|
}
|
|
tm = base.transform.worldToLocalMatrix;
|
|
invtm = tm.inverse;
|
|
mat = Matrix4x4.identity;
|
|
SetAxis(mat);
|
|
return true;
|
|
}
|
|
}
|