From 73c7072ff8bd4b54a5916e78a761500159ada570 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 26 Dec 2014 12:45:16 -0800 Subject: [PATCH] added ability to toggle standard deltaTime and unscaledDeltaTime --- Assets/TransitionKit/TransitionKit.cs | 16 +++++++++++++++- .../TransitionKit/transitions/BlurTransition.cs | 2 +- .../transitions/PixelateTransition.cs | 12 ++++++------ .../transitions/TriangleSlicesTransition.cs | 2 +- .../transitions/VerticalSlicesTransition.cs | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Assets/TransitionKit/TransitionKit.cs b/Assets/TransitionKit/TransitionKit.cs index 5df79ff..f959792 100644 --- a/Assets/TransitionKit/TransitionKit.cs +++ b/Assets/TransitionKit/TransitionKit.cs @@ -40,6 +40,20 @@ public class TransitionKit : MonoBehaviour /// public Material material; + /// + /// sets whether TransitionKit will use unscaledDeltaTime or standard deltaTime + /// + public bool useUnscaledDeltaTime = false; + + /// + /// helper property for use by all TransitionKitDelegates so they use the proper deltaTime + /// + /// The delta time. + public float deltaTime + { + get { return useUnscaledDeltaTime ? Time.unscaledDeltaTime : Time.deltaTime; } + } + /// /// holds the instance while we are transitioning @@ -246,7 +260,7 @@ public IEnumerator tickProgressPropertyInMaterial( float duration, bool reverseD var elapsed = 0f; while( elapsed < duration ) { - elapsed += Time.deltaTime; + elapsed += deltaTime; var step = Mathf.Lerp( start, end, Mathf.Pow( elapsed / duration, 2f ) ); material.SetFloat( "_Progress", step ); diff --git a/Assets/TransitionKit/transitions/BlurTransition.cs b/Assets/TransitionKit/transitions/BlurTransition.cs index 82f0492..3763681 100644 --- a/Assets/TransitionKit/transitions/BlurTransition.cs +++ b/Assets/TransitionKit/transitions/BlurTransition.cs @@ -43,7 +43,7 @@ public IEnumerator onScreenObscured( TransitionKit transitionKit ) var elapsed = 0f; while( elapsed < duration ) { - elapsed += Time.deltaTime; + elapsed += transitionKit.deltaTime; var step = Mathf.Pow( elapsed / duration, 2f ); var blurAmount = Mathf.Lerp( blurMin, blurMax, step ); diff --git a/Assets/TransitionKit/transitions/PixelateTransition.cs b/Assets/TransitionKit/transitions/PixelateTransition.cs index eeedbe5..7b330e1 100644 --- a/Assets/TransitionKit/transitions/PixelateTransition.cs +++ b/Assets/TransitionKit/transitions/PixelateTransition.cs @@ -59,7 +59,7 @@ public IEnumerator onScreenObscured( TransitionKit transitionKit ) var elapsed = 0f; while( elapsed < duration ) { - elapsed += Time.deltaTime; + elapsed += transitionKit.deltaTime; var step = Mathf.Pow( elapsed / duration, 2f ); transitionKit.material.SetFloat( "_CellSize", Mathf.Lerp( startValue, endValue, step ) ); @@ -90,22 +90,22 @@ public IEnumerator onScreenObscured( TransitionKit transitionKit ) break; } - yield return transitionKit.StartCoroutine( animateScale( transitionKit.transform, duration * 0.5f, desiredScale ) ); + yield return transitionKit.StartCoroutine( animateScale( transitionKit, duration * 0.5f, desiredScale ) ); } #endregion - public IEnumerator animateScale( Transform transform, float duration, Vector3 desiredScale ) + public IEnumerator animateScale( TransitionKit transitionKit, float duration, Vector3 desiredScale ) { - var originalScale = transform.localScale; + var originalScale = transitionKit.transform.localScale; var elapsed = 0f; while( elapsed < duration ) { - elapsed += Time.deltaTime; + elapsed += transitionKit.deltaTime; var step = Mathf.Pow( elapsed / duration, 2f ); - transform.localScale = Vector3.Lerp( originalScale, desiredScale, step ); + transitionKit.transform.localScale = Vector3.Lerp( originalScale, desiredScale, step ); yield return null; } diff --git a/Assets/TransitionKit/transitions/TriangleSlicesTransition.cs b/Assets/TransitionKit/transitions/TriangleSlicesTransition.cs index ff347cc..4bae7e8 100644 --- a/Assets/TransitionKit/transitions/TriangleSlicesTransition.cs +++ b/Assets/TransitionKit/transitions/TriangleSlicesTransition.cs @@ -142,7 +142,7 @@ public IEnumerator onScreenObscured( TransitionKit transitionKit ) while( elapsed < duration ) { - elapsed += Time.deltaTime; + elapsed += transitionKit.deltaTime; var step = Mathf.Pow( elapsed / duration, 2f ); var offset = Mathf.Lerp( 0, transitionDistance, step ); diff --git a/Assets/TransitionKit/transitions/VerticalSlicesTransition.cs b/Assets/TransitionKit/transitions/VerticalSlicesTransition.cs index 15c2bf6..9a617dd 100644 --- a/Assets/TransitionKit/transitions/VerticalSlicesTransition.cs +++ b/Assets/TransitionKit/transitions/VerticalSlicesTransition.cs @@ -135,7 +135,7 @@ public IEnumerator onScreenObscured( TransitionKit transitionKit ) while( elapsed < duration ) { - elapsed += Time.deltaTime; + elapsed += transitionKit.deltaTime; var step = Mathf.Pow( elapsed / duration, 2f ); var offset = Mathf.Lerp( 0, transitionDistance, step );