165 lines
3.2 KiB
C#
165 lines
3.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Ripple")]
|
|
public class MegaRipple : MegaModifier
|
|
{
|
|
public float amp;
|
|
|
|
public float amp2;
|
|
|
|
public float flex = 1f;
|
|
|
|
public float wave = 1f;
|
|
|
|
public float phase;
|
|
|
|
public float Decay;
|
|
|
|
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 ModName()
|
|
{
|
|
return "Ripple";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=308";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
float num;
|
|
if (amp != amp2)
|
|
{
|
|
float magnitude = p.magnitude;
|
|
if (magnitude == 0f)
|
|
{
|
|
num = amp;
|
|
}
|
|
else
|
|
{
|
|
float num2 = Mathf.Acos(p.x / magnitude) / (float)Math.PI;
|
|
num2 = ((!(num2 > 0.5f)) ? num2 : (1f - num2));
|
|
num2 *= 2f;
|
|
num2 = Mathf.SmoothStep(0f, 1f, num2);
|
|
num = amp * (1f - num2) + amp2 * num2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
num = amp;
|
|
}
|
|
float y = p.y;
|
|
p.y = 0f;
|
|
float magnitude2 = p.magnitude;
|
|
p.y = y + flex * MegaUtils.WaveFunc(magnitude2, time, num, wave, phase, dy);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
if (animate)
|
|
{
|
|
float num = Time.deltaTime;
|
|
if (num == 0f)
|
|
{
|
|
num = 0.01f;
|
|
}
|
|
t += num * Speed;
|
|
phase = t;
|
|
}
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
dy = Decay / 1000f;
|
|
return true;
|
|
}
|
|
|
|
private Vector3 GetPos(float u, float radius)
|
|
{
|
|
Vector3 zero = Vector3.zero;
|
|
zero.x = radius * Mathf.Cos(u * (float)Math.PI * 2f);
|
|
zero.z = radius * 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(radius, t, amp * (1f - num) + amp2 * num, wave, phase, dy);
|
|
return zero;
|
|
}
|
|
|
|
private void MakeCircle(float t, float radius, 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;
|
|
for (int i = 0; i < numCircleSegs; i++)
|
|
{
|
|
float u = (float)i / (float)numCircleSegs;
|
|
zero = GetPos(u, radius);
|
|
zero2 = GetPos(u, r1);
|
|
if ((i & 1) == 1)
|
|
{
|
|
Gizmos.color = gizCol1;
|
|
}
|
|
else
|
|
{
|
|
Gizmos.color = gizCol2;
|
|
}
|
|
if (i > 0)
|
|
{
|
|
Gizmos.DrawLine(vector, zero);
|
|
}
|
|
else
|
|
{
|
|
to = zero;
|
|
}
|
|
Gizmos.DrawLine(zero2, zero);
|
|
vector = zero;
|
|
}
|
|
Gizmos.DrawLine(vector, to);
|
|
}
|
|
|
|
public override void DrawGizmo(MegaModContext context)
|
|
{
|
|
Gizmos.color = Color.yellow;
|
|
Matrix4x4 identity = Matrix4x4.identity;
|
|
Vector3 pos = gizmoPos;
|
|
pos.x = 0f - pos.x;
|
|
pos.y = 0f - pos.y;
|
|
pos.z = 0f - pos.z;
|
|
Vector3 s = gizmoScale;
|
|
s.x = 1f - (s.x - 1f);
|
|
s.y = 1f - (s.y - 1f);
|
|
identity.SetTRS(pos, Quaternion.Euler(gizmoRot), s);
|
|
Gizmos.matrix = base.transform.localToWorldMatrix * identity;
|
|
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;
|
|
}
|
|
}
|
|
}
|