using System; using UnityEngine; [AddComponentMenu("Modifiers/Waving")] public class MegaWaving : MegaModifier { public float amp = 0.01f; public float flex = 1f; public float wave = 1f; public float phase; public float Decay; public bool animate; public float Speed = 1f; public MegaAxis waveaxis; private float time; private float dy; private int ix; private int iz = 2; private float t; public override string ModName() { return "Waving"; } public override string GetHelpURL() { return "?page_id=308"; } public static float WaveFunc(float radius, float t, float amp, float waveLen, float phase, float decay) { float f = (float)Math.PI * 2f * (radius / waveLen + phase); return amp * Mathf.Sin(f) * Mathf.Exp((0f - decay) * Mathf.Abs(radius)); } public override Vector3 Map(int i, Vector3 p) { p = tm.MultiplyPoint3x4(p); float num = Mathf.Abs(2f * p[iz]); num *= num; p[ix] += flex * WaveFunc(p[iz], time, amp * 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) { if (wave == 0f) { wave = 1E-06f; } dy = Decay / 1000f; switch (waveaxis) { case MegaAxis.X: ix = 0; iz = 2; break; case MegaAxis.Y: ix = 1; iz = 2; break; case MegaAxis.Z: ix = 2; iz = 0; break; } return true; } }