Пример #1
0
 private void OnDestroy()
 {
     if (_instance == this)
     {
         _instance = null;
     }
 }
Пример #2
0
        /// <summary>
        /// Interpolates Rotation of the given transform to the provided Rotation
        /// </summary>
        /// <param name="transform">The Transform to manipulate</param>
        /// <param name="rotation">Rotation to interpolate to</param>
        /// <param name="duration">The amount of time in seconds the interpolation should take</param>
        /// <param name="space">Operate in world or local space</param>
        /// <param name="finished">Delegate function that is called when the interpolation is finished</param>
        /// <param name="progressMapping">A delegate function to map a value between 0 and 1 used as the progress for lerping that returns a new value between 0 and 1</param>
        /// <returns></returns>
        public static Coroutine Interpolate(this Transform transform, Quaternion rotation, float duration, Space space, Action finished, Func <float, float> progressMapping = null)
        {
            InterpolationTransform target = new InterpolationTransform();

            target.rotation = rotation;

            target.valuesToUse = 2; // 00000010

            return(CoroutineHost.StartTrackedCoroutine(InterpolateTransform(transform, target, duration, space, progressMapping, finished), transform, INTERPOLATION_COROUTINE_TAG));
        }
Пример #3
0
        /// <summary>
        /// Interpolates Positionof the given transform to the provided Position
        /// </summary>
        /// <param name="transform">The Transform to manipulate</param>
        /// <param name="position">Position to interpolate to</param>
        /// <param name="duration">The amount of time in seconds the interpolation should take</param>
        /// <param name="space">Operate in world or local space</param>
        /// <param name="progressMapping">A delegate function to map a value between 0 and 1 used as the progress for lerping that returns a new value between 0 and 1</param>
        /// <returns></returns>
        public static Coroutine Interpolate(this Transform transform, Vector3 position, float duration, Space space, Func <float, float> progressMapping = null)
        {
            InterpolationTransform target = new InterpolationTransform();

            target.position = position;

            target.valuesToUse = 1; // 00000001

            return(CoroutineHost.StartTrackedCoroutine(InterpolateTransform(transform, target, duration, space, progressMapping, null), transform, INTERPOLATION_COROUTINE_TAG));
        }
Пример #4
0
        /// <summary>
        /// Interpolates Positionof the given transform to the provided Position
        /// </summary>
        /// <param name="transform">The Transform to manipulate</param>
        /// <param name="scale">Scale to interpolate to</param>
        /// <param name="duration">The amount of time in seconds the interpolation should take</param>
        /// <param name="finished">Delegate function that is called when the interpolation is finished</param>
        /// <param name="progressMapping">A delegate function to map a value between 0 and 1 used as the progress for lerping that returns a new value between 0 and 1</param>
        /// <returns></returns>
        public static Coroutine Interpolate(this Transform transform, Vector3 scale, float duration, Action finished, Func <float, float> progressMapping = null)
        {
            InterpolationTransform target = new InterpolationTransform();

            target.scale = scale;

            target.valuesToUse = 4; // 00000100

            return(CoroutineHost.StartTrackedCoroutine(InterpolateTransform(transform, target, duration, Space.Self, progressMapping, finished), transform, INTERPOLATION_COROUTINE_TAG));
        }
Пример #5
0
        // ######################## FUNCTIONALITY ######################## //
        /// <summary>
        /// Starts the Timer (if the timer was paused, it will resume from where it was paused)
        /// </summary>
        public void Start()
        {
            if (Running)
            {
                Debug.LogWarning("Can't start Timer because it is already running!");
                return;
            }

            Running = true;
            CoroutineHost.StartTrackedCoroutine(Run(), this, "Timer");
        }
Пример #6
0
        /// <summary>
        /// Lerps the Color of the Renderer in the given Duration
        /// </summary>
        /// <param name="rend">The Renderer to set the Color to</param>
        /// <param name="target">The Color to lerp to</param>
        /// <param name="duration">Amount of seconds the lerp should take</param>
        /// <param name="progressMapping">Function for mapping the progress, takes one float argument between 0 and 1 and should return a float between 0 and 1</param>
        /// <param name="finished">Callback for when the Fading is finished</param>
        /// <returns></returns>
        public static Coroutine LerpColor(this Renderer rend, Color target, float duration, Func <float, float> progressMapping, Action finished = null)
        {
            Color[] targets = new Color[rend.materials.Length];
            for (int i = 0; i < targets.Length; ++i)
            {
                targets[i] = target;
            }

            CoroutineHost.StopTrackedCoroutine(rend, COROUTINE_TAG);
            return(CoroutineHost.StartTrackedCoroutine(FadingMethods.LerpColor(rend, targets, duration, false, finished, progressMapping), rend, COROUTINE_TAG));
        }
Пример #7
0
        // ######################## UNITY EVENT FUNCTIONS ######################## //
        void Awake()
        {
            if (_instance == null)
            {
                _instance = this;
            }
            else if (Instance != this)
            {
                Destroy(this);

                Debug.LogWarning("Tried to Instantiate second instance of Coroutine Host. Additional Instance was destroyed.");
            }
        }
Пример #8
0
        /// <summary>
        /// Interpolates Position, Rotation and Scale of the given transform to the provided Transform
        /// </summary>
        /// <param name="transform">The Transform to manipulate</param>
        /// <param name="targetTransform">The Transform to interpolate to</param>
        /// <param name="duration">The amount of time in seconds the interpolation should take</param>
        /// <param name="space">Operate in world or local space</param>
        /// <param name="finished">Delegate function that is called when the interpolation is finished</param>
        /// <param name="progressMapping">A delegate function to map a value between 0 and 1 used as the progress for lerping that returns a new value between 0 and 1</param>
        /// <returns></returns>
        public static Coroutine Interpolate(this Transform transform, Transform targetTransform, float duration, Space space, Action finished, Func <float, float> progressMapping = null)
        {
            InterpolationTransform target = new InterpolationTransform();

            if (space == Space.Self)
            {
                target.position = targetTransform.localPosition;
                target.rotation = targetTransform.localRotation;
            }
            else
            {
                target.position = targetTransform.position;
                target.rotation = targetTransform.rotation;
            }

            target.scale = targetTransform.localScale;

            target.valuesToUse = 7; // 00000111

            return(CoroutineHost.StartTrackedCoroutine(InterpolateTransform(transform, target, duration, space, progressMapping, finished), transform, INTERPOLATION_COROUTINE_TAG));
        }
Пример #9
0
 /// <summary>
 /// Stops the provided Interpolation on the Transform
 /// </summary>
 /// <param name="transform"></param>
 /// <param name="routine"></param>
 public static void StopInterpolation(this Transform transform, Coroutine routine)
 {
     CoroutineHost.StopTrackedCoroutine(routine, INTERPOLATION_COROUTINE_TAG);
 }
Пример #10
0
 /// <summary>
 /// Lerps the Color of the Sprite in the given Duration
 /// </summary>
 /// <param name="sprite">The Sprite to set the Color to</param>
 /// <param name="target">The Color to lerp to</param>
 /// <param name="duration">Amount of seconds the lerp should take</param>
 /// <param name="progressMapping">Function for mapping the progress, takes one float argument between 0 and 1 and should return a float between 0 and 1</param>
 /// <param name="finished">Callback for when the Fading is finished</param>
 /// <returns></returns>
 public static Coroutine LerpColor(this SpriteRenderer sprite, Color target, float duration, Func <float, float> progressMapping, Action finished = null)
 {
     CoroutineHost.StopTrackedCoroutine(sprite, COROUTINE_TAG);
     return(CoroutineHost.StartTrackedCoroutine(FadingMethods.LerpColor(sprite, target, duration, false, finished, progressMapping), sprite, COROUTINE_TAG));
 }
 /// <summary>
 /// Lerps one Vector3 to another
 /// </summary>
 /// <param name="vector">The Vector that should be lerped</param>
 /// <param name="target">The target Vector</param>
 /// <param name="duration">Duration of the lerp in seconds</param>
 /// <param name="returnAction">Function to get the new Vector</param>
 /// <param name="finished">Callback for when the Lerping is finished</param>
 /// <returns></returns>
 public static Coroutine Lerp(this Vector3 vector, Vector3 target, float duration, Action <Vector3> returnAction, Action finished = null)
 {
     return(CoroutineHost.StartTrackedCoroutine(LerpVector(vector, target, duration, returnAction, finished, null), vector, LERP_VECTOR_COROUTINE_TAG));
 }
Пример #12
0
 public static void StopAllColorLerps()
 {
     CoroutineHost.StopAllTrackedCoroutines(COROUTINE_TAG);
 }
Пример #13
0
 /// <summary>
 /// Stops the provided Color Lerp
 /// </summary>
 /// <param name="routine"></param>
 public static void StopColorLerp(Coroutine routine)
 {
     CoroutineHost.StopTrackedCoroutine(routine, COROUTINE_TAG);
 }
Пример #14
0
 /// <summary>
 /// Lerps the color to the target
 /// </summary>
 /// <param name="color">The start color</param>
 /// <param name="target">The target color</param>
 /// <param name="duration">Duration of the lerp in seconds</param>
 /// <param name="returnAction">Function to get the new color</param>
 /// <param name="progressMapping">Function for mapping the progress, takes one float argument between 0 and 1 and should return a float between 0 and 1</param>
 /// <param name="finished">Callback for when the Lerping is finished</param>
 /// <returns></returns>
 public static Coroutine Interpolate(this Color color, Color target, float duration, Action <Color> returnAction, Func <float, float> progressMapping, Action finished = null)
 {
     return(CoroutineHost.StartTrackedCoroutine(LerpColor(color, target, duration, returnAction, finished, progressMapping), color, COROUTINE_TAG));
 }
Пример #15
0
 /// <summary>
 /// Lerps the Color of the Material in the given Duration
 /// </summary>
 /// <param name="material">The Material to set the Color to</param>
 /// <param name="target">The Color to lerp to</param>
 /// <param name="duration">Amount of seconds the lerp should take</param>
 /// <param name="progressMapping">Function for mapping the progress, takes one float argument between 0 and 1 and should return a float between 0 and 1</param>
 /// <param name="finished">Callback for when the Fading is finished</param>
 /// <returns></returns>
 public static Coroutine LerpColor(this Material material, Color target, float duration, Func <float, float> progressMapping, Action finished = null)
 {
     CoroutineHost.StopTrackedCoroutine(material, COROUTINE_TAG);
     return(CoroutineHost.StartTrackedCoroutine(FadingMethods.LerpColor(material, target, duration, finished, progressMapping), material, COROUTINE_TAG));
 }
 public static void StopAllVectorLerps()
 {
     CoroutineHost.StopAllTrackedCoroutines(LERP_VECTOR_COROUTINE_TAG);
 }
Пример #17
0
 /// <summary>
 /// Stops all Interpolations on the Transform
 /// </summary>
 /// <param name="transform"></param>
 public static void StopAllInterpolations(this Transform transform)
 {
     CoroutineHost.StopAllTrackedCoroutines(transform, INTERPOLATION_COROUTINE_TAG);
 }
 /// <summary>
 /// Lerps one Vector4 to another
 /// </summary>
 /// <param name="vector">The Vector that should be lerped</param>
 /// <param name="target">The target Vector</param>
 /// <param name="duration">Duration of the lerp in seconds</param>
 /// <param name="returnAction">Function to get the new Vector</param>
 /// <param name="finished">Callback for when the Lerping is finished</param>
 /// <param name="progressMapping">Function for mapping the progress, takes one float argument between 0 and 1 and should return a float between 0 and 1</param>
 /// <returns></returns>
 public static Coroutine Lerp(this Vector4 vector, Vector4 target, float duration, Action <Vector4> returnAction, Func <float, float> progressMapping, Action finished = null)
 {
     return(CoroutineHost.StartTrackedCoroutine(LerpVector(vector, target, duration, returnAction, finished, progressMapping), vector, LERP_VECTOR_COROUTINE_TAG));
 }
Пример #19
0
 public static void StopAllInterpolations()
 {
     CoroutineHost.StopAllTrackedCoroutines(INTERPOLATION_COROUTINE_TAG);
 }
Пример #20
0
 // ######################## UTILITIES ######################## //
 /// <summary>
 /// stops the timer
 /// </summary>
 private void StopTimer()
 {
     CoroutineHost.StopTrackedCoroutine(this, "Timer");
     Running = false;
 }
Пример #21
0
 /// <summary>
 /// Lerps the Color of the Graphic in the given Duration
 /// </summary>
 /// <param name="graphic">The Graphic to set the Color to</param>
 /// <param name="target">The Color to lerp to</param>
 /// <param name="duration">Amount of seconds the lerp should take</param>
 /// <param name="finished">Callback for when the Fading is finished</param>
 /// <returns></returns>
 public static Coroutine LerpColor(this Graphic graphic, Color target, float duration, Action finished = null)
 {
     CoroutineHost.StopTrackedCoroutine(graphic, COROUTINE_TAG);
     return(CoroutineHost.StartTrackedCoroutine(FadingMethods.LerpColor(graphic, target, duration, false, finished, null), graphic, COROUTINE_TAG));
 }