public void smoothBlend(float targetOpacity, float blendDuration, EasingFunction easingFunction) { changingOpacity = true; this.targetOpacity = targetOpacity; this.blendDuration = blendDuration; this.currentTime = 0.0f; startOpacity = workingAlpha; easeFunc = EasingFunctions.GetEasingFunction(easingFunction); }
protected TweenBase(SceneTime time, EasingType type, float duration, float startValue, float finishValue, Action finishCallback) { Assert.NotNull(time); _time = time; _startTime = time.CurrentFloat; _current = 0; _duration = duration; _finishTime = _duration + _startTime; _function = EasingFunctions.Get(type); _state = TweenState.Working; _startValue = startValue; _finishValue = finishValue; _finishCallback = finishCallback; }
/// <summary> /// Constructor. /// </summary> /// <param name="target">Object on which a property is to be animated.</param> /// <param name="property">Property which is to be animated.</param> /// <param name="initialValue">Initial value of the property.</param> /// <param name="finalValue">Final value of the property.</param> /// <param name="duration">Duration of the animation (in milliseconds).</param> /// <param name="easingFunction">Function used to ease the animation.</param> /// <param name="removeOnCompletion"> /// Whether the animation should be removed from the animation manager upon completion. /// </param> public PropertyAnimation(object target, string property, T initialValue, T finalValue, int duration, EasingFunctionDelegate easingFunction = null, bool removeOnCompletion = false) { mTarget = target; mPropertyName = property; mInitialValue = initialValue; mFinalValue = finalValue; mPlaying = false; mPaused = false; mPosition = 0.0f; mEasedPosition = 0.0f; mDuration = duration; mEasingFunction = easingFunction != null ? easingFunction : EasingFunctions.EaseInOutCubic; mRemoveOnCompletion = removeOnCompletion; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public RuntimeAnimator(View target, float duration, float startOffset, bool autoReset, bool autoReverse, float reverseSpeed, bool notifyPropertyChangedWhileAnimating, EasingFunctionDelegate easingFunction, ValueConverter valueInterpolator, DependencyProperty property, string fromState, string toState) { Duration = duration; StartOffset = startOffset; AutoReset = autoReset; AutoReverse = autoReverse; ReverseSpeed = reverseSpeed; NotifyPropertyChangedWhileAnimating = notifyPropertyChangedWhileAnimating; ValueInterpolator = valueInterpolator; NotifyPropertyChanged = () => property.NotifyPropertyChanged(target); Property = property; FromState = fromState; ToState = toState; Target = new WeakReference <View>(target); EasingFunction = easingFunction; }
public void update(Clock clock) { if (changingOpacity) { currentTime += clock.DeltaSeconds; if (currentTime > blendDuration) { currentTime = blendDuration; workingAlpha = targetOpacity; easeFunc = null; changingOpacity = false; } else { workingAlpha = easeFunc(startOpacity, targetOpacity - startOpacity, currentTime, blendDuration); } } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public Animator(View target, float duration, float startOffset, bool autoReset, bool autoReverse, float reverseSpeed, bool notifyPropertyChangedWhileAnimating, EasingFunctionDelegate easingFunction, Func <T, T, float, T> valueInterpolator, Action <T> valueSetter, Func <T> fromGetter, Func <T> toGetter, Action notifyPropertyChanged, DependencyProperty property) { Duration = duration; StartOffset = startOffset; AutoReset = autoReset; AutoReverse = autoReverse; ReverseSpeed = reverseSpeed; NotifyPropertyChangedWhileAnimating = notifyPropertyChangedWhileAnimating; ValueInterpolator = valueInterpolator; ValueSetter = valueSetter; FromGetter = fromGetter; ToGetter = toGetter; NotifyPropertyChanged = notifyPropertyChanged; Property = property; Target = new WeakReference <View>(target); EasingFunction = easingFunction; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public Animator(View target) { Target = new WeakReference <View>(target); EasingFunction = EasingFunctions.Linear; }
public static IEnumerator MultiTranslateCoroutine(MonoBehaviour component, int nTranslation, EasingFunctionDelegate easingFunction) { for (int i = 0; i < nTranslation; i++) { yield return(component.StartCoroutine( AnimationTools.TranslateCoroutine( component, component.transform.position + Random.insideUnitSphere * 4, .5f, easingFunction ) )); } }
public static IEnumerator TranslateCoroutine(MonoBehaviour component, Vector3 targetPosition, float duration, EasingFunctionDelegate easingFunction) { float elapsedTime = 0; Vector3 startPosition = component.transform.position; while (elapsedTime < duration) { float k = elapsedTime / duration; // [0, 1] k = easingFunction != null?easingFunction(k) : k; component.transform.position = Vector3.Lerp(startPosition, targetPosition, k); elapsedTime += Time.deltaTime; yield return(null); } component.transform.localScale = targetPosition; }
// Update is called once per frame //void Update() //{ // DebugTools.Log("Update", gameObject, m_DisplayFrameCount, m_DisplayTime); //} //private void FixedUpdate() //{ // DebugTools.Log("FixedUpdate", gameObject, m_DisplayFrameCount, m_DisplayTime); //} //private void LateUpdate() //{ // DebugTools.Log("LateUpdate", gameObject, m_DisplayFrameCount, m_DisplayTime); //} //private void OnDestroy() //{ // DebugTools.Log("OnDestroy", gameObject, m_DisplayFrameCount, m_DisplayTime); //} #endregion IEnumerator TranslationCoroutine(float delay, Transform transf, Vector3 startPos, Vector3 endPos, EasingFunctionDelegate easingFunction) { float elapsedTime = 0; DebugTools.Log("TranslationCoroutine START", null, m_DisplayFrameCount, m_DisplayTime); //yield return new WaitForSeconds(delay); while (elapsedTime < delay) { DebugTools.Log("TranslationCoroutine UPDATE", null, m_DisplayFrameCount, m_DisplayTime); float k = elapsedTime / delay; transf.position = Vector3.Lerp(startPos, endPos, easingFunction(0, 1, k)); elapsedTime += Time.deltaTime; yield return(null); } transf.position = endPos; DebugTools.Log("TranslationCoroutine END", null, m_DisplayFrameCount, m_DisplayTime); }
/// <summary> /// Constructor. /// </summary> /// <param name="target">Object on which a property is to be animated.</param> /// <param name="property">Property which is to be animated.</param> /// <param name="initialValue">Initial value of the property.</param> /// <param name="finalValue">Final value of the property.</param> /// <param name="duration">Duration of the animation (in seconds).</param> /// <param name="easingFunction">Function used to ease the animation.</param> /// <param name="removeOnCompletion"> /// Whether the animation should be removed from the animation manager upon completion. /// </param> public DoublePropertyAnimation(object target, string property, double initialValue, double finalValue, int duration, EasingFunctionDelegate easingFunction = null, bool removeOnCompletion = false) : base(target, property, initialValue, finalValue, duration, easingFunction, removeOnCompletion) { this.InterpolationFunction = InterpolationFunctions.DoubleLerp; }
IEnumerator TranslateFromAToBCoroutine(Vector3 startPos, Vector3 endPos, float duration, EasingFunctionDelegate easingFunctionDelegaten, Action startAction = null, Action endAction = null) { if (startAction != null) { startAction(); } float elapsedTime = 0; while (elapsedTime < duration) { float k = elapsedTime / duration; //MyTools.Log(k.ToString()); //transform.position = Vector3.Lerp(startPos,endPos,k); transform.position = Vector3.Lerp(startPos, endPos, Kryz.Tweening.EasingFunctions.InOutBounce(k)); elapsedTime += Time.deltaTime; yield return(null); } transform.position = endPos; //StartCoroutine(TranslateFromAToBCoroutine(transform.position, transform.position+Random.onUnitSphere*4, 2.5f)); if (endAction != null) { endAction(); } }