173 lines
3.3 KiB
C#
173 lines
3.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Warps/Ripple")]
|
|
public class MegaRippleWarp : MegaWarp
|
|
{
|
|
public float amp;
|
|
|
|
public float amp2;
|
|
|
|
public float flex = 1f;
|
|
|
|
public float wave = 1f;
|
|
|
|
public float phase;
|
|
|
|
public bool animate;
|
|
|
|
public float Speed = 1f;
|
|
|
|
public float radius = 1f;
|
|
|
|
public int segments = 10;
|
|
|
|
public int circles = 4;
|
|
|
|
private float time;
|
|
|
|
private float dy;
|
|
|
|
private float t;
|
|
|
|
public override string WarpName()
|
|
{
|
|
return "Ripple";
|
|
}
|
|
|
|
public override string GetIcon()
|
|
{
|
|
return "MegaRipple icon.png";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=2587";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
Vector3 a = p;
|
|
float magnitude = p.magnitude;
|
|
float num = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude));
|
|
float num2;
|
|
if (amp != amp2)
|
|
{
|
|
float magnitude2 = p.magnitude;
|
|
if (magnitude2 == 0f)
|
|
{
|
|
num2 = amp;
|
|
}
|
|
else
|
|
{
|
|
float num3 = Mathf.Acos(p.x / magnitude2) / (float)Math.PI;
|
|
num3 = ((!(num3 > 0.5f)) ? num3 : (1f - num3));
|
|
num3 *= 2f;
|
|
num3 = Mathf.SmoothStep(0f, 1f, num3);
|
|
num2 = amp * (1f - num3) + amp2 * num3;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
num2 = amp;
|
|
}
|
|
float y = p.y;
|
|
p.y = 0f;
|
|
float magnitude3 = p.magnitude;
|
|
p.y = y + flex * MegaUtils.WaveFunc(magnitude3, time, num2, wave, phase, dy);
|
|
p = Vector3.Lerp(a, p, num);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (animate)
|
|
{
|
|
t += Time.deltaTime * Speed;
|
|
phase = t;
|
|
}
|
|
}
|
|
|
|
public override bool Prepare(float decay)
|
|
{
|
|
tm = base.transform.worldToLocalMatrix;
|
|
invtm = tm.inverse;
|
|
dy = Decay / 1000f;
|
|
totaldecay = dy + decay;
|
|
if (totaldecay < 0f)
|
|
{
|
|
totaldecay = 0f;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private Vector3 GetPos(float u, float rad)
|
|
{
|
|
Vector3 zero = Vector3.zero;
|
|
zero.x = rad * Mathf.Cos(u * (float)Math.PI * 2f);
|
|
zero.z = rad * Mathf.Sin(u * (float)Math.PI * 2f);
|
|
float num = ((!(u > 0.5f)) ? u : (u - 0.5f));
|
|
num = ((!(num > 0.25f)) ? num : (0.5f - num));
|
|
num *= 4f;
|
|
num *= num;
|
|
zero.y = MegaUtils.WaveFunc(rad, t, amp * (1f - num) + amp2 * num, wave, phase, dy);
|
|
return zero;
|
|
}
|
|
|
|
private void MakeCircle(float t, float rad, float r1, float a1, float a2, float w, float s, float d, int numCircleSegs)
|
|
{
|
|
Vector3 vector = Vector3.zero;
|
|
Vector3 zero = Vector3.zero;
|
|
Vector3 zero2 = Vector3.zero;
|
|
Vector3 to = Vector3.zero;
|
|
Gizmos.color = MegaWarp.gCol2;
|
|
for (int i = 0; i < numCircleSegs; i++)
|
|
{
|
|
float u = (float)i / (float)numCircleSegs;
|
|
zero = GetPos(u, rad);
|
|
zero2 = GetPos(u, r1);
|
|
if (i > 0)
|
|
{
|
|
Gizmos.DrawLine(vector, zero);
|
|
}
|
|
else
|
|
{
|
|
to = zero;
|
|
}
|
|
Gizmos.color = MegaWarp.gCol1;
|
|
Gizmos.DrawLine(zero2, zero);
|
|
if ((i & 1) == 0)
|
|
{
|
|
Gizmos.color = MegaWarp.gCol1;
|
|
}
|
|
else
|
|
{
|
|
Gizmos.color = MegaWarp.gCol2;
|
|
}
|
|
vector = zero;
|
|
}
|
|
Gizmos.DrawLine(vector, to);
|
|
}
|
|
|
|
public override void DrawGizmo(Color col)
|
|
{
|
|
SetGizCols(col.a);
|
|
tm = Matrix4x4.identity;
|
|
invtm = tm.inverse;
|
|
if (Prepare(0f))
|
|
{
|
|
tm *= base.transform.localToWorldMatrix;
|
|
invtm = tm.inverse;
|
|
Gizmos.matrix = base.transform.localToWorldMatrix;
|
|
float r = 0f;
|
|
for (int i = 0; i < circles; i++)
|
|
{
|
|
float num = (float)i / (float)circles * radius;
|
|
MakeCircle(t, num, r, amp, amp2, wave, phase, dy, segments);
|
|
r = num;
|
|
}
|
|
}
|
|
}
|
|
}
|