コード例 #1
0
        } //END Rotate

        //---------------------------------------------//
        /// <summary>
        /// Rotates a Transform or RectTransform using Quaternions. Supply this function with the localEulerAngles for the 'endValue' and 'startValue'
        /// </summary>
        /// <typeparam name="T">Transform</typeparam>
        /// <param name="tweenThis">Accepts [Transform, RectTransform]</param>
        /// <param name="endValue">What should the localEulerAngles for the transform be by the end of this rotation?</param>
        /// <param name="length">How long tween should take</param>
        /// <param name="easeType">What easing you would like to use</param>
        /// <param name="startValue">[OPTIONAL] Value to start from. If not provided we will use the existing value from the 'tweenThis' object</param>
        /// <param name="delay">[OPTIONAL] How long we should wait before starting to tween</param>
        /// <param name="loop">[OPTIONAL] Keep the tween running via a loop indefinitely</param>
        /// <param name="onCompleteOrLoop">[OPTIONAL] A UnityEvent to call once the tween has finished or completed a single loop</param>
        /// <returns></returns>
        public static bxrTween Rotate<T>( this T tweenThis, Vector3 endValue, float length, EaseCurve.EaseType easeType, Vector3? startValue = null, float delay = 0f, bool loop = false, UnityEvent onCompleteOrLoop = null ) where T : Transform
        //---------------------------------------------//
        {

            return TweenManager.Rotate( tweenThis, endValue, length, EaseCurve.GetEaseCurve( easeType ), startValue, delay, loop, onCompleteOrLoop );

        } //END Rotate
コード例 #2
0
        /// <summary>
        ///     Removes ease value related to a given path node index.
        /// </summary>
        /// <param name="nodeTimestamp">Path node timestamp.</param>
        private void HandleDisableEaseTool(float nodeTimestamp)
        {
            var easeCurveTimestamps =
                Utilities.GetAnimationCurveTimestamps(EaseCurve);

            // Find ease index for the given timestamp.
            var easeKeyIndex =
                easeCurveTimestamps.FindIndex(x => x == nodeTimestamp);

            if (easeKeyIndex != -1)
            {
                // Remove key from ease curve.
                EaseCurve.RemoveKey(easeKeyIndex);
            }

            Asserts.AssertToolCurveInSync(
                EasedNodesNo,
                EaseCurveKeysNo,
                "ease");

            // todo remove
            //var nodesWithEaseEnabledNo = GetEasedNodeTimestamps();

            //Utilities.Assert(
            //    () => EaseCurve.length == nodesWithEaseEnabledNo.Count,
            //    String.Format(
            //        "Number of ease curve keys and number of nodes" +
            //        " with enabled ease tool differs.\n" +
            //        "Ease curve length: {0}\n" +
            //        "Nodes with enabled ease tool: {1}",
            //        EaseCurve.length,
            //        nodesWithEaseEnabledNo.Count));
        }
コード例 #3
0
        } //END Move

        //------------------------------------------------------------------//
        /// <summary>
        /// Move a Transform across local or global space
        /// </summary>
        /// <typeparam name="T">Transform</typeparam>
        /// <param name="tweenThis">Accepts [Transform, RectTransform]</param>
        /// <param name="endValue">The position you would like to move this Transform to</param>
        /// <param name="length">How long tween should take</param>
        /// <param name="easeType">What easing you would like to use</param>
        /// <param name="startValue">[OPTIONAL] Value to start from. If not provided we will use the existing value from the 'tweenThis' object</param>
        /// <param name="useLocalOrWorldSpace">[OPTIONAL] Would you like this transform to move in local or global space?</param>
        /// <param name="delay">[OPTIONAL] How long we should wait before starting to tween</param>
        /// <param name="loop">[OPTIONAL] Keep the tween running via a loop indefinitely</param>
        /// <param name="onCompleteOrLoop">[OPTIONAL] A UnityEvent to call once the tween has finished or completed a single loop</param>
        /// <returns></returns>
        public static bxrTween Move<T>( this T tweenThis, Vector3 endValue, float length, EaseCurve.EaseType easeType, Vector3? startValue = null, bxrTweenPosition.LocalOrWorldSpace useLocalOrWorldSpace = bxrTweenPosition.LocalOrWorldSpace.Local, float delay = 0f, bool loop = false, UnityEvent onCompleteOrLoop = null ) where T : Transform
        //------------------------------------------------------------------//
        {

            return TweenManager.Move( tweenThis, endValue, length, EaseCurve.GetEaseCurve( easeType ), startValue, useLocalOrWorldSpace, delay, loop, onCompleteOrLoop );

        } //END Move
コード例 #4
0
        private void InitializeEaseCurve()
        {
            EaseCurve.AddKey(0, DefaultEaseCurveValue);
            EaseCurve.AddKey(1, DefaultEaseCurveValue);

            OnEaseCurveUpdated();
        }
コード例 #5
0
ファイル: ABSTweenPlugin.cs プロジェクト: yueding/hotween
        /// <summary>
        /// Sets the ease type (called during Init, but can also be called by Tweener to change easeType while playing).
        /// </summary>
        internal void SetEase(EaseType p_easeType)
        {
            easeType = p_easeType;
            if (easeType == EaseType.AnimationCurve)
            {
                if (tweenObj._easeAnimationCurve != null)
                {
                    easeCurve = new EaseCurve(tweenObj._easeAnimationCurve);
                    ease      = easeCurve.Evaluate;
                }
                else
                {
                    // Missing animation curve: set to normal ease
                    easeType = EaseType.EaseOutQuad;
                    easeInfo = EaseInfo.GetEaseInfo(easeType);
                    ease     = easeInfo.ease;
                }
            }
            else
            {
                easeInfo = EaseInfo.GetEaseInfo(easeType);
                ease     = easeInfo.ease;
            }

            if (_easeReversed && easeInfo.inverseEase != null)
            {
                ease = easeInfo.inverseEase;
            }
        }
コード例 #6
0
        } //END TweenFloat

        //---------------------------------------------//
        /// <summary>
        /// Change any float value by passing in the UnityEngine Object and a fieldName
        /// </summary>
        /// <typeparam name="T">UnityEngine Object</typeparam>
        /// <param name="tweenThis">The UnityEngine Object that will have it's value tweened</param>
        /// <param name="fieldName">The variable ('field') we should tween</param>
        /// <param name="endValue">Float value to tween to</param>
        /// <param name="length">How long tween should take</param>
        /// <param name="easeType">The easing you would like this tween to use</param>
        /// <param name="startValue">[OPTIONAL] Value to start from. If not provided we will use the existing value from the 'tweenThis' object</param>
        /// <param name="delay">[OPTIONAL] How long we should wait before starting to tween</param>
        /// <param name="loop">[OPTIONAL] Keep the tween running via a loop indefinitely</param>
        /// <param name="onCompleteOrLoop">[OPTIONAL] A UnityEvent to call once the tween has finished or completed a single loop</param>
        /// <returns></returns>
        public static bxrTween TweenFloat<T>( this T tweenThis, string fieldName, float endValue, float length, EaseCurve.EaseType easeType, float? startValue = null, float delay = 0f, bool loop = false, UnityEvent onCompleteOrLoop = null ) where T : UnityEngine.Object
        //---------------------------------------------//
        {

            return TweenManager.TweenFloat( tweenThis, fieldName, endValue, length, EaseCurve.GetEaseCurve( easeType ), startValue, delay, loop, onCompleteOrLoop );

        } //END TweenFloat
コード例 #7
0
        } //END AudioPitch

        //---------------------------------------------//
        /// <summary>
        /// Change the pitch value for an AudioSource
        /// </summary>
        /// <param name="tweenThis">Accepts [AudioSource]</param>
        /// <param name="endValue">What should the final pitch value be?</param>
        /// <param name="length">How long tween should take</param>
        /// <param name="easeType">The ease type you would like this tween to use</param>
        /// <param name="startValue">[OPTIONAL] Value to start from. If not provided we will use the existing value from the 'tweenThis' object</param>
        /// <param name="delay">[OPTIONAL] How long we should wait before starting to tween</param>
        /// <param name="loop">[OPTIONAL] Keep the tween running via a loop indefinitely</param>
        /// <param name="onCompleteOrLoop">[OPTIONAL] A UnityEvent to call once the tween has finished or completed a single loop</param>
        /// <returns></returns>
        public static bxrTween AudioPitch( this AudioSource tweenThis, float endValue, float length, EaseCurve.EaseType easeType, float? startValue = null, float delay = 0f, bool loop = false, UnityEvent onCompleteOrLoop = null )
        //---------------------------------------------//
        {

            return TweenManager.TweenFloat( tweenThis, "pitch", endValue, length, EaseCurve.GetEaseCurve( easeType ), startValue, delay, loop, onCompleteOrLoop );

        } //END AudioPitch
コード例 #8
0
        } //END Color

        //---------------------------------------------//
        /// <summary>
        /// Change the color for the passed in Renderer or Material
        /// </summary>
        /// <typeparam name="T">Renderer/Object</typeparam>
        /// <param name="tweenThis">Accepts [Renderer, Image, RawImage, SpriteRenderer, Text, Material, CanvasGroup]</param>
        /// <param name="endValue">Color to tween to</param>
        /// <param name="length">How long tween should take</param>
        /// <param name="easeType">What ease type you would like this tween to use</param>
        /// <param name="startValue">[OPTIONAL] Value to start from. If not provided we will use the existing value from the 'tweenThis' object</param>
        /// <param name="delay">[OPTIONAL] How long we should wait before starting to tween</param>
        /// <param name="loop">[OPTIONAL] Keep the tween running via a loop indefinitely</param>
        /// <param name="onCompleteOrLoop">[OPTIONAL] A UnityEvent to call once the tween has finished or completed a single loop</param>
        /// <returns></returns>
        public static bxrTween Color<T>( this T tweenThis, Color endValue, float length, EaseCurve.EaseType easeType, Color? startValue = null, float delay = 0f, bool loop = false, UnityEvent onCompleteOrLoop = null )
        //---------------------------------------------//
        {

            return TweenManager.Color( tweenThis, endValue, length, EaseCurve.GetEaseCurve( easeType ), startValue, delay, loop, onCompleteOrLoop );

        } //END Color
コード例 #9
0
        public void RemoveKeyFromEaseCurve(float timestamp)
        {
            var index = Utilities.GetIndexAtTimestamp(EaseCurve, timestamp);

            EaseCurve.RemoveKey(index);

            OnEaseCurveUpdated();
        }
コード例 #10
0
        /// <summary>
        ///     Add a new key to ease curve. Value will be read from existing
        ///     curve.
        /// </summary>
        /// <param name="time"></param>
        public void AddKeyToEaseCurve(float time)
        {
            var valueAtTime = EaseCurve.Evaluate(time);

            EaseCurve.AddKey(time, valueAtTime);

            OnEaseCurveUpdated();
        }
コード例 #11
0
ファイル: ABSTweenPlugin.cs プロジェクト: yueding/hotween
 /// <summary>
 /// Creates a new instance of this plugin with the given options.
 /// </summary>
 /// <param name="p_endVal">
 /// The <see cref="object"/> value to tween to.
 /// </param>
 /// <param name="p_easeAnimCurve">
 /// The <see cref="AnimationCurve"/> to use for easing.
 /// </param>
 /// <param name="p_isRelative">
 /// If <c>true</c>, the given end value is considered relative instead than absolute.
 /// </param>
 protected ABSTweenPlugin(object p_endVal, AnimationCurve p_easeAnimCurve, bool p_isRelative)
 {
     isRelative = p_isRelative;
     _endVal    = p_endVal;
     easeType   = EaseType.AnimationCurve;
     easeCurve  = new EaseCurve(p_easeAnimCurve);
     easeInfo   = null;
     ease       = easeCurve.Evaluate;
 }
コード例 #12
0
        public void UpdateEaseValue(int keyIndex, float newValue)
        {
            var keyframeCopy = EaseCurve.keys[keyIndex];

            // Update keyframe value.
            keyframeCopy.value = newValue;

            // Replace old key with updated one.
            EaseCurve.RemoveKey(keyIndex);
            EaseCurve.AddKey(keyframeCopy);

            OnEaseCurveUpdated();
        }
コード例 #13
0
		/// <summary>
		/// Creates a new instance of this plugin with the given options.
		/// </summary>
		/// <param name="p_endVal">
		/// The <see cref="object"/> value to tween to.
		/// </param>
		/// <param name="p_easeAnimCurve">
		/// The <see cref="AnimationCurve"/> to use for easing.
		/// </param>
		/// <param name="p_isRelative">
		/// If <c>true</c>, the given end value is considered relative instead than absolute.
		/// </param>
		protected ABSTweenPlugin (object p_endVal, AnimationCurve p_easeAnimCurve, bool p_isRelative)
		{
				isRelative = p_isRelative;
				_endVal = p_endVal;
				easeType = EaseType.AnimationCurve;
				easeCurve = new EaseCurve (p_easeAnimCurve);
				easeInfo = null;
				ease = easeCurve.Evaluate;
		}
コード例 #14
0
 public float GetEaseValueAtTime(float timestamp)
 {
     return(EaseCurve.Evaluate(timestamp));
 }
コード例 #15
0
		/// <summary>
		/// Sets the ease type (called during Init, but can also be called by Tweener to change easeType while playing).
		/// </summary>
		internal void SetEase (EaseType p_easeType)
		{
				easeType = p_easeType;
				if (easeType == EaseType.AnimationCurve) {
						if (tweenObj._easeAnimationCurve != null) {
								easeCurve = new EaseCurve (tweenObj._easeAnimationCurve);
								ease = easeCurve.Evaluate;
						} else {
								// Missing animation curve: set to normal ease
								easeType = EaseType.EaseOutQuad;
								easeInfo = EaseInfo.GetEaseInfo (easeType);
								ease = easeInfo.ease;
						}
				} else {
						easeInfo = EaseInfo.GetEaseInfo (easeType);
						ease = easeInfo.ease;
				}

				if (_easeReversed && easeInfo.inverseEase != null) {
						ease = easeInfo.inverseEase;
				}
		}
コード例 #16
0
        } //END ImageFill

        //---------------------------------------------//
        /// <summary>
        /// Change the fill value for an Image object
        /// </summary>
        /// <param name="tweenThis">Accepts [Image]</param>
        /// <param name="endValue">What should the final fill value be?</param>
        /// <param name="length">How long tween should take</param>
        /// <param name="easeType">What ease you would like this tween to use</param>
        /// <param name="startValue">[OPTIONAL] Value to start from. If not provided we will use the existing value from the 'tweenThis' object</param>
        /// <param name="delay">[OPTIONAL] How long we should wait before starting to tween</param>
        /// <param name="loop">[OPTIONAL] Keep the tween running via a loop indefinitely</param>
        /// <param name="onCompleteOrLoop">[OPTIONAL] A UnityEvent to call once the tween has finished or completed a single loop</param>
        /// <returns></returns>
        public static bxrTween ImageFill( this Image tweenThis, float endValue, float length, EaseCurve.EaseType easeType, float? startValue = null, float delay = 0f, bool loop = false, UnityEvent onCompleteOrLoop = null )
        //---------------------------------------------//
        {

            return TweenManager.TweenFloat( tweenThis, "fillAmount", endValue, length, EaseCurve.GetEaseCurve( easeType ), startValue, delay, loop, onCompleteOrLoop );

        } //END ImageFill
コード例 #17
0
    public float Ease(float from, float change, float duration, EaseCurve curve, EaseType type, float step)
    {
        float normTime = step / duration;

        switch (curve)
        {
            #region sine
        case EaseCurve.Sine:
            switch (type)
            {
            case EaseType.In:
                return(change * (1 - Mathf.Cos(normTime * (Mathf.PI / 2))) + from);

            case EaseType.Out:
                return(change * Mathf.Sin(normTime * (Mathf.PI / 2)) + from);

            case EaseType.Both:
                return(change * 0.5f * (1 - Mathf.Cos(Mathf.PI * normTime)) + from);

            default:
                break;
            }
            break;

            #endregion sine
        case EaseCurve.Quad:
            switch (type)
            {
            case EaseType.In:

            case EaseType.Out:

            case EaseType.Both:

            default:
                break;
            }
            break;

            #region cubic
        case EaseCurve.Cubic:
            switch (type)
            {
            case EaseType.In:
                return(change * Mathf.Pow(normTime, 3) + from);

            case EaseType.Out:
                return(change * (Mathf.Pow(normTime - 1, 3) + 1) + from);

            case EaseType.Both:
                step /= duration * 0.5f;

                if (step < 1)
                {
                    return((change * 0.5f) * Mathf.Pow(step, 3) + from);
                }

                return((change * 0.5f) * (Mathf.Pow(step - 2, 3) + 2) + from);

            default:
                break;
            }
            break;

            #endregion cubic
        case EaseCurve.Quart:
            switch (type)
            {
            case EaseType.In:

            case EaseType.Out:

            case EaseType.Both:

            default:
                break;
            }
            break;

        case EaseCurve.Quint:
            switch (type)
            {
            case EaseType.In:

            case EaseType.Out:

            case EaseType.Both:

            default:
                break;
            }
            break;

        case EaseCurve.Expo:
            switch (type)
            {
            case EaseType.In:

            case EaseType.Out:

            case EaseType.Both:

            default:
                break;
            }
            break;

        case EaseCurve.Circ:
            switch (type)
            {
            case EaseType.In:

            case EaseType.Out:

            case EaseType.Both:

            default:
                break;
            }
            break;

            #region back
        case EaseCurve.Back:
            switch (type)
            {
            case EaseType.In:
                return(change * (normTime) * normTime * ((s + 1) * normTime - s) + from);

            case EaseType.Out:
                step = (step / duration) - 1;
                return(change * ((step) * step * ((s + 1) * step + s) + 1) + from);

            case EaseType.Both:
                float s2 = s;
                step /= duration;
                step *= 2;

                if ((step) < 1)
                {
                    s2 *= (1.525f);
                    return(change * 0.5f * (step * step * ((s2 + 1) * step - s2)) + from);
                }

                step -= 2;
                s2   *= 1.525f;
                return(change * 0.5f * ((step) * step * ((s2 + 1) * step + s2) + 2) + from);

            default:
                break;
            }
            break;

            #endregion back
            #region elastic
        case EaseCurve.Elastic:
            float p = 0;
            float a = change;

            switch (type)
            {
            case EaseType.In:
                if (step == 0 || a == 0)
                {
                    return(from);
                }

                if (normTime == 1)
                {
                    return(from + change);
                }

                if (p == 0)
                {
                    p = duration * 0.3f;
                }

                if (a < Mathf.Abs(change))
                {
                    a = change;
                    s = p * 0.25f;
                }
                else
                {
                    s = p / (2 * Mathf.PI) * Mathf.Asin(change / a);
                }

                return(-(a * Mathf.Pow(2, 10 * (--normTime)) * Mathf.Sin((normTime * duration - s) * (2 * Mathf.PI) / p)) + from);


            case EaseType.Out:
                float step2     = step;
                float from2     = from;
                float change2   = change;
                float duration2 = duration;

                if (step2 == 0 || change2 == 0)
                {
                    return(from2);
                }
                step2 /= duration2;
                if (step2 == 1)
                {
                    return(from2 + change);
                }
                if (p < 0.5f)
                {
                    p = duration2 * 0.3f;
                }
                if (change2 < Mathf.Abs(change))
                {
                    change2 = change;
                    s       = p * 0.25f;
                }
                else
                {
                    s = p / (2 * Mathf.PI) * Mathf.Asin(change / change2);
                }
                return(change2 * Mathf.Pow(2, -10 * step2) * Mathf.Sin((step2 * duration2 - s) * (2 * Mathf.PI) / p) + change + from2);


            case EaseType.Both:
                if (step == 0 || a == 0)
                {
                    return(from);
                }
                step /= (duration * 0.5f);
                if (step == 2)
                {
                    return(from + change);
                }
                if (p < 0.5f)
                {
                    p = duration * (0.3f * 1.5f);
                }
                if (a < Mathf.Abs(change))
                {
                    a = change;
                    s = p * 0.25f;
                }
                else
                {
                    s = p / (2 * Mathf.PI) * Mathf.Asin(change / a);
                }
                if (step < 1)
                {
                    return(-0.5f * (a * Mathf.Pow(2, 10 * (--step)) * Mathf.Sin((step * duration - s) * (2 * Mathf.PI) / p)) + from);
                }
                return(a * Mathf.Pow(2, -10 * (--step)) * Mathf.Sin((step * duration - s) * (2 * Mathf.PI) / p) * 0.5f + change + from);

            default:
                break;
            }
            break;

            #endregion elastic
            #region bounce
        case EaseCurve.Bounce:
            switch (type)
            {
            case EaseType.In:
                return(change - Ease(0, change, duration, EaseCurve.Bounce, EaseType.Out, duration - step) + from);

            case EaseType.Out:
                step /= duration;

                if (step < (1 / 2.75f))
                {
                    return(change * (7.5625f * step * step) + from);
                }
                else
                if (step < (2 / 2.75f))
                {
                    step -= (1.5f / 2.75f);
                    return(change * (7.5625f * step * step + 0.75f) + from);
                }
                else
                if (step < (2.5f / 2.75f))
                {
                    step -= (2.25f / 2.75f);
                    return(change * (7.5625f * step * step + 0.9375f) + from);
                }
                else
                {
                    step -= (2.625f / 2.75f);
                    return(change * (7.5625f * step * step + 0.984375f) + from);
                }

            case EaseType.Both:
                if (step < duration * 0.5f)
                {
                    return(Ease(0, change, duration, EaseCurve.Bounce, EaseType.In, step * 2) * 0.5f + from);
                }

                return(Ease(0, change, duration, EaseCurve.Bounce, EaseType.Out, step * 2 - duration) * 0.5f + change * 0.5f + from);

            default:
                break;
            }
            break;

            #endregion bounce
        default:
            break;
        }

        return(0);
    }