diff --git a/ExtensionMethods.cs b/ExtensionMethods.cs index 4ff26a2..1e04ca0 100644 --- a/ExtensionMethods.cs +++ b/ExtensionMethods.cs @@ -1,4 +1,4 @@ -// https://unity3d.com/learn/tutorials/topics/scripting/extension-methods +// https://unity3d.com/learn/tutorials/topics/scripting/extension-methods using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -223,26 +223,28 @@ public static AudioClip SpeakerSpecificClip(this AudioClip originalClip, int tar /// public static string Printable(this List list) { + if (list.Count == 0) return "Empty List"; string str = ""; for (int i = 0; i < list.Count; i++) { - str += i + ":{" + list[i].ToString() + "}"; - if (i != list.Count - 1) str += ", "; + str += i + ":{" + list[i].ToString() + "}"; + if (i != list.Count - 1) str += ", \n"; } - return str; + return str + "\n"; } /// /// Returns a log of items in an array. /// public static string Printable(this T[] array) - { + { + if (array.Length == 0) return "Empty Array"; string str = ""; for (int i = 0; i < array.Length; i++) { str += i + ":{" + array[i].ToString() + "}"; - if (i != array.Length - 1) str += ", "; + if (i != array.Length - 1) str += ", \n"; } - return str; + return str + "\n"; } /// /// Returns conversion to Unity Units/Meters from Feet @@ -370,178 +372,178 @@ private static string CheckForIrregularPlural(string word) /// Strongly recommended that the target transform shares the parent of this transform. /// - public static void SnapToSibling(this Transform tForm, Transform to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation[] SnapToSibling(this Transform tForm, Transform to, float duration) { - Wrj.Utils.MapToCurve.Linear.MatchSibling(tForm, to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Linear.MatchSibling(tForm, to, duration, false, 0, 0, 0, false, null); } /// /// Move, rotate and scale the transform to the position of another over time. /// /// Strongly recommended that the target transform shares the parent of this transform. /// - public static void SnapToSibling(this GameObject go, Transform to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation[] SnapToSibling(this GameObject go, Transform to, float duration) { - go.transform.SnapToSibling(to, duration); + return go.transform.SnapToSibling(to, duration); } /// /// Move, rotate and scale the transform to the position of another over time. /// /// Strongly recommended that the target transform shares the parent of this transform. /// - public static void EaseSnapToSibling(this Transform tForm, Transform to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation[] EaseSnapToSibling(this Transform tForm, Transform to, float duration) { - Wrj.Utils.MapToCurve.Ease.MatchSibling(tForm, to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Ease.MatchSibling(tForm, to, duration, false, 0, 0, 0, false, null); } /// /// Move, rotate and scale the transform to the position of another over time. /// /// Strongly recommended that the target transform shares the parent of this transform. /// - public static void EaseSnapToSibling(this GameObject go, Transform to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation[] EaseSnapToSibling(this GameObject go, Transform to, float duration) { - go.transform.EaseSnapToSibling(to, duration); + return go.transform.EaseSnapToSibling(to, duration); } /// /// Move transform in local space over time /// - public static void Move(this Transform tForm, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Move(this Transform tForm, Vector3 to, float duration) { - Wrj.Utils.MapToCurve.Linear.MoveWorld(tForm, to, duration, false, 0, 0, 0, false, false, null); + return Wrj.Utils.MapToCurve.Linear.MoveWorld(tForm, to, duration, false, 0, 0, 0, false, false, null); } /// /// Move transform in local space over time /// - public static void Move(this GameObject go, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Move(this GameObject go, Vector3 to, float duration) { - go.transform.Move(to, duration); + return go.transform.Move(to, duration); } /// /// Move transform in local space over time /// - public static void EaseMove(this Transform tForm, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseMove(this Transform tForm, Vector3 to, float duration) { - Wrj.Utils.MapToCurve.Ease.MoveWorld(tForm, to, duration, false, 0, 0, 0, false, false, null); + return Wrj.Utils.MapToCurve.Ease.MoveWorld(tForm, to, duration, false, 0, 0, 0, false, false, null); } /// /// Move transform in local space over time /// - public static void EaseMove(this GameObject go, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseMove(this GameObject go, Vector3 to, float duration) { - go.transform.EaseMove(to, duration); + return go.transform.EaseMove(to, duration); } /// /// Rotate transform over time /// - public static void LinearRotate(this Transform tForm, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation LinearRotate(this Transform tForm, Vector3 to, float duration) { - Wrj.Utils.MapToCurve.Linear.Rotate(tForm, to, duration, false, 0, 0, 0, false, true, false, null); + return Wrj.Utils.MapToCurve.Linear.Rotate(tForm, to, duration, false, 0, 0, 0, false, true, false, null); } /// /// Rotate transform over time /// - public static void Rotate(this GameObject go, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Rotate(this GameObject go, Vector3 to, float duration) { - go.transform.LinearRotate(to, duration); + return go.transform.LinearRotate(to, duration); } /// /// Rotate transform over time /// - public static void EaseRotate(this Transform tForm, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseRotate(this Transform tForm, Vector3 to, float duration) { - Wrj.Utils.MapToCurve.Ease.Rotate(tForm, to, duration, false, 0, 0, 0, false, true, false, null); + return Wrj.Utils.MapToCurve.Ease.Rotate(tForm, to, duration, false, 0, 0, 0, false, true, false, null); } /// /// Rotate transform over time /// - public static void EaseRotate(this GameObject go, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseRotate(this GameObject go, Vector3 to, float duration) { - go.transform.EaseRotate(to, duration); + return go.transform.EaseRotate(to, duration); } /// /// Change transforms scale over time /// - public static void Scale(this Transform tForm, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Scale(this Transform tForm, Vector3 to, float duration) { - Wrj.Utils.MapToCurve.Linear.Scale(tForm, to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Linear.Scale(tForm, to, duration, false, 0, 0, 0, false, null); } /// /// Change transforms scale over time using a multiplier /// - public static void Scale(this Transform tForm, float to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Scale(this Transform tForm, float to, float duration) { - Wrj.Utils.MapToCurve.Linear.Scale(tForm, tForm.localScale * to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Linear.Scale(tForm, tForm.localScale * to, duration, false, 0, 0, 0, false, null); } /// /// Change transforms scale over time /// - public static void Scale(this GameObject go, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Scale(this GameObject go, Vector3 to, float duration) { - go.transform.Scale(to, duration); + return go.transform.Scale(to, duration); } /// /// Change transforms scale over time using a multiplier /// - public static void Scale(this GameObject go, float to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Scale(this GameObject go, float to, float duration) { - go.transform.Scale(to, duration); + return go.transform.Scale(to, duration); } /// /// Change transforms scale over time /// - public static void EaseScale(this Transform tForm, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this Transform tForm, Vector3 to, float duration) { - Wrj.Utils.MapToCurve.Ease.Scale(tForm, to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Ease.Scale(tForm, to, duration, false, 0, 0, 0, false, null); } /// /// Change transforms scale over time using a multiplier /// - public static void EaseScale(this Transform tForm, float to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this Transform tForm, float to, float duration) { - Wrj.Utils.MapToCurve.Ease.Scale(tForm, tForm.localScale * to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Ease.Scale(tForm, tForm.localScale * to, duration, false, 0, 0, 0, false, null); } /// /// Change transforms scale over time /// - public static void EaseScale(this GameObject go, Vector3 to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this GameObject go, Vector3 to, float duration) { - go.transform.EaseScale(to, duration); + return go.transform.EaseScale(to, duration); } /// /// Change transforms scale over time using a multiplier /// - public static void EaseScale(this GameObject go, float to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this GameObject go, float to, float duration) { - go.transform.EaseScale(to, duration); + return go.transform.EaseScale(to, duration); } /// /// Change Color Over Time /// - public static void Color(this Transform tForm, Color to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Color(this Transform tForm, Color to, float duration) { - Wrj.Utils.MapToCurve.Linear.ChangeColor(tForm, to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Linear.ChangeColor(tForm, to, duration, false, 0, 0, 0, false, null); } /// /// Change Color Over Time /// - public static void Color(this GameObject go, Color to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Color(this GameObject go, Color to, float duration) { - go.transform.Color(to, duration); + return go.transform.Color(to, duration); } /// /// Change transparency over time /// - public static void Alpha(this Transform tForm, float to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Alpha(this Transform tForm, float to, float duration) { - Wrj.Utils.MapToCurve.Linear.FadeAlpha(tForm, to, duration, false, 0, 0, 0, false, null); + return Wrj.Utils.MapToCurve.Linear.FadeAlpha(tForm, to, duration, false, 0, 0, 0, false, null); } /// /// Change transparency over time /// - public static void Alpha(this GameObject go, float to, float duration) + public static Wrj.Utils.MapToCurve.Manipulation Alpha(this GameObject go, float to, float duration) { - go.transform.Alpha(to, duration); + return go.transform.Alpha(to, duration); } /// diff --git a/UnityScriptingUtilities.unitypackage b/UnityScriptingUtilities.unitypackage index 4824db4..088b61a 100644 Binary files a/UnityScriptingUtilities.unitypackage and b/UnityScriptingUtilities.unitypackage differ diff --git a/WrjUtils.cs b/WrjUtils.cs index e3d0dc0..c1becff 100644 --- a/WrjUtils.cs +++ b/WrjUtils.cs @@ -246,11 +246,12 @@ public class MapToCurve public static MapToCurve EaseOut = new MapToCurve(AnimationCurve.EaseInOut(-1, -1, 1, 1)); public class Manipulation - { + { public Coroutine coroutine; public Transform transform; public int iterationCount = 0; private string type; + public bool IsRunning => coroutine != null; public Manipulation(string _type, Transform _transform) { @@ -1088,7 +1089,7 @@ public Manipulation[] MatchSibling(Transform tform, Transform toTform, float dur // Called when a coroutine is completed. Executes the OnDone method if necessary, and resets default values. private void CoroutineComplete(Manipulation mcp, OnDone OnDoneMethod) { - mcp.coroutine = null; + mcp.coroutine = null; wrjInstance.CleanCoroList(); if (OnDoneMethod != null) {