using UnityEngine; [AddComponentMenu("Modifiers/Warps/Spherify")] public class MegaSpherifyWarp : MegaWarp { public float percent; public float FallOff; private float per; private float xsize; private float ysize; private float zsize; private float size; public override string WarpName() { return "Spherify"; } public override string GetHelpURL() { return "?page_id=322"; } 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)); float num = magnitude; float num2 = size / num; float num3 = Mathf.Exp((0f - FallOff) * Mathf.Abs(num)); p.x += Mathf.Sign(p.x) * ((Mathf.Abs(p.x * num2) - Mathf.Abs(p.x)) * per) * num3; p.y += Mathf.Sign(p.y) * ((Mathf.Abs(p.y * num2) - Mathf.Abs(p.y)) * per) * num3; p.z += Mathf.Sign(p.z) * ((Mathf.Abs(p.z * num2) - Mathf.Abs(p.z)) * per) * num3; p = Vector3.Lerp(a, p, t); return invtm.MultiplyPoint3x4(p); } private void Update() { Prepare(Decay); } public override bool Prepare(float decay) { tm = base.transform.worldToLocalMatrix; invtm = tm.inverse; totaldecay = Decay + decay; if (totaldecay < 0f) { totaldecay = 0f; } xsize = Width; ysize = Height; zsize = Length; size = ((!(xsize > ysize)) ? ysize : xsize); size = ((!(zsize > size)) ? size : zsize); size /= 2f; per = percent / 100f; return true; } }