/// <summary> /// Turns the content on using a coroutine to animate the transition. /// </summary> virtual protected IEnumerator TurnOnAsync(bool animated) { this.State = ContentState.TurnOn; Layout(); Vector3 initialPosition; initialPosition = this.OffPosition; Vector3 targetPosition; targetPosition = this.OnPosition; float duration; duration = this.AnimationDuration; float elapsed; elapsed = 0f; float t; t = 0; this.gameObject.SetActive(true); if (animated && duration > 0) { while (elapsed < duration) { elapsed += Time.deltaTime; t = Mathf.Clamp(elapsed / duration, 0f, 1f); this.Button.Transform.localPosition = Cubic.EaseOut(initialPosition, targetPosition, t); yield return(null); } } this.Button.enabled = true; this.Button.Transform.localPosition = targetPosition; this.State = ContentState.On; yield break; }
internal static float Ease(Type ease, float t, float duration) { switch (ease) { case Type.Linear: return(Linear.EaseNone(t, duration)); case Type.BackIn: return(Back.EaseIn(t, duration)); case Type.BackOut: return(Back.EaseOut(t, duration)); case Type.BackInOut: return(Back.EaseInOut(t, duration)); case Type.BounceIn: return(Bounce.EaseIn(t, duration)); case Type.BounceOut: return(Bounce.EaseOut(t, duration)); case Type.BounceInOut: return(Bounce.EaseInOut(t, duration)); case Type.CircIn: return(Circular.EaseIn(t, duration)); case Type.CircOut: return(Circular.EaseOut(t, duration)); case Type.CircInOut: return(Circular.EaseInOut(t, duration)); case Type.CubicIn: return(Cubic.EaseIn(t, duration)); case Type.CubicOut: return(Cubic.EaseOut(t, duration)); case Type.CubicInOut: return(Cubic.EaseInOut(t, duration)); case Type.ElasticIn: return(Elastic.EaseIn(t, duration)); case Type.ElasticOut: return(Elastic.EaseOut(t, duration)); case Type.ElasticInOut: return(Elastic.EaseInOut(t, duration)); case Type.Punch: return(Elastic.Punch(t, duration)); case Type.ExpoIn: return(Exponential.EaseIn(t, duration)); case Type.ExpoOut: return(Exponential.EaseOut(t, duration)); case Type.ExpoInOut: return(Exponential.EaseInOut(t, duration)); case Type.QuadIn: return(Quadratic.EaseIn(t, duration)); case Type.QuadOut: return(Quadratic.EaseOut(t, duration)); case Type.QuadInOut: return(Quadratic.EaseInOut(t, duration)); case Type.QuartIn: return(Quartic.EaseIn(t, duration)); case Type.QuartOut: return(Quartic.EaseOut(t, duration)); case Type.QuartInOut: return(Quartic.EaseInOut(t, duration)); case Type.QuintIn: return(Quintic.EaseIn(t, duration)); case Type.QuintOut: return(Quintic.EaseOut(t, duration)); case Type.QuintInOut: return(Quintic.EaseInOut(t, duration)); case Type.SineIn: return(Sinusoidal.EaseIn(t, duration)); case Type.SineOut: return(Sinusoidal.EaseOut(t, duration)); case Type.SineInOut: return(Sinusoidal.EaseInOut(t, duration)); default: return(Linear.EaseNone(t, duration)); } }