/// <summary> /// Return a function that maps the percentage of the easing function /// to the percentage between the begin and end values. This function /// is a EaseInOut function that can be transformed to EaseIn or EaseOut /// <para> /// The function returned MUST MEET 3 REQUIREMENTS: /// 1) f(0) = 0 /// 2) f(1/2) = 1/2 /// 3) f(1) = 1 /// </para> /// </summary> /// <param name="type"></param> /// <returns></returns> private static Func <double, double> GetEasingFunction(EaseFunctionType type) { Func <double, double> func = null; switch (type) { case EaseFunctionType.Linear: func = d => d; break; case EaseFunctionType.Quadratic: func = GetPowerEase(2); break; case EaseFunctionType.Cubic: func = GetPowerEase(3); break; case EaseFunctionType.Sine: func = d => (Math.Sin((d - .5) * Math.PI) + 1) / 2d; break; default: throw new NotImplementedException("Easing function not supported"); } return(func); }
public EaseFunction(EaseFunctionType type, EaseMode mode, double lengthMs, double fromValue, double toValue) { m_type = type; m_dLength = lengthMs; m_dFrom = fromValue; m_dTo = toValue; m_function = GetEasingFunction(m_type); if (mode != EaseMode.InOut) { m_function = TransformEase(m_function, (mode == EaseMode.In)); } }
public EaseFunction(EaseFunctionType type, EaseMode mode, double lengthMs, double fromValue, double toValue) { m_type = type; m_dLength = lengthMs; m_dFrom = fromValue; m_dTo = toValue; m_function = GetEasingFunction(m_type); if (mode != EaseMode.InOut) { m_function = TransformEase(m_function, (mode == EaseMode.In)); } }
public static float Calculate(this EaseFunctionType easeFunction, float t) { switch (easeFunction) { case EaseFunctionType.NoEase: return(NoEase(t)); case EaseFunctionType.EaseIn: return(EaseIn(t)); case EaseFunctionType.EaseOut: return(EaseOut(t)); case EaseFunctionType.EaseExponential: return(EaseExponential(t)); case EaseFunctionType.SmoothStep: return(SmoothStep(t)); case EaseFunctionType.SmootherStep: return(SmootherStep(t)); } return(-1); }
public IEnumerator ArmAction(Vector3 startingPos, Vector3 newPos, float maxDuration, EaseFunctionType easeFunction) { //Begin Arm Movement float elapsedTime = -0.1f; while (elapsedTime <= maxDuration) { float ratio = elapsedTime / maxDuration; float easedRatio = EaseFunction.Calculate(easeFunctionSelection, ratio); transform.localPosition = Vector3.Lerp(startingPos, newPos, easedRatio); elapsedTime += Time.deltaTime; yield return(new WaitForEndOfFrame()); } }
/// <summary> /// Return a function that maps the percentage of the easing function /// to the percentage between the begin and end values. This function /// is a EaseInOut function that can be transformed to EaseIn or EaseOut /// <para> /// The function returned MUST MEET 3 REQUIREMENTS: /// 1) f(0) = 0 /// 2) f(1/2) = 1/2 /// 3) f(1) = 1 /// </para> /// </summary> /// <param name="type"></param> /// <returns></returns> private static Func<double, double> GetEasingFunction(EaseFunctionType type) { Func<double, double> func = null; switch (type) { case EaseFunctionType.Linear: func = d => d; break; case EaseFunctionType.Quadratic: func = GetPowerEase(2); break; case EaseFunctionType.Cubic: func = GetPowerEase(3); break; case EaseFunctionType.Sine: func = d => (Math.Sin((d - .5) * Math.PI) + 1) / 2d; break; default: throw new NotImplementedException("Easing function not supported"); } return func; }