Exemplo n.º 1
0
        private Func <float, float> Out(TweenMethod method)
        {
            // Reverse input and output.
            return(s =>
            {
                Func <float, float> methodFunc = In(method);

                return 1f - methodFunc(1 - s);
            });
        }
Exemplo n.º 2
0
        private Func <float, float> OutIn(TweenMethod method)
        {
            return(s =>
            {
                Func <float, float> methodFuncIn = In(method);
                Func <float, float> methodFuncOut = Out(method);

                if (s < 0.5f)
                {
                    return 1 + methodFuncOut(2 * s - 1) * 0.5f;
                }
                return methodFuncIn(2 * s) * 0.5f;
            });
        }
Exemplo n.º 3
0
 public static Func <float, float> In(TweenMethod method)
 {
     return(method switch
     {
         TweenMethod.Linear => (Func <float, float>)Linear,
         TweenMethod.Quad => Quad,
         TweenMethod.Cubic => Cubic,
         TweenMethod.Quart => Quart,
         TweenMethod.Quint => Quint,
         TweenMethod.Sine => Sine,
         TweenMethod.Expo => Expo,
         TweenMethod.Circ => Circ,
         TweenMethod.Back => Back,
         TweenMethod.Bounce => Bounce,
         _ => Linear
     });
Exemplo n.º 4
0
        internal Tween(float duration, ref object objectTarget, ref object objectTween, TweenType type, TweenMethod method, Action after = null)
        {
            _duration     = duration;
            _objectTarget = objectTarget;
            _objectTween  = objectTween;
            _type         = type;
            _method       = method;
            _after        = after;

            _crossover = new Dictionary <string, float>();

            MemberInfo[] tweenMembers  = _objectTween.GetType().GetMembers();
            MemberInfo[] targetMembers = _objectTarget.GetType().GetMembers();

            // Find matches.
            foreach (MemberInfo tweenMember in tweenMembers)
            {
                // Filter everything that isn't a field or property.
                if (tweenMember.MemberType != MemberTypes.Field && tweenMember.MemberType != MemberTypes.Property)
                {
                    continue;
                }
                Type tweenMemberType = TypeOfMember(tweenMember);

                // Filter not double convertible types.
                if (tweenMemberType != typeof(float) && tweenMemberType != typeof(double) && tweenMemberType != typeof(decimal))
                {
                    continue;
                }

                // Check if name and type match. Add it and calculate the delta.
                if ((from targetMember in targetMembers where tweenMember.Name == targetMember.Name select TypeOfMember(targetMember)).Any(targetMemberType => tweenMemberType == targetMemberType))
                {
                    _crossover.Add(tweenMember.Name, (GetFloatValueFromObjectMember(_objectTween, tweenMember.Name) - GetFloatValueFromObjectMember(_objectTarget, tweenMember.Name)) * 1);
                }
            }

            // Get the type/method combination function.
            _func = (Func <float, float>)GetType().GetMethod(type.ToString(), BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(this, new object[] { method });
        }
Exemplo n.º 5
0
        private void PlayTween(Vector3 scaleVec, TweenMethod type, Action <AbstractGoTween> onComplete = null)
        {
            GoTween tween;

            if (type == TweenMethod.PositionFrom)
            {
                tween           = transform.scaleFrom(duration, scaleVec);
                tween.easeCurve = easeFrom;
            }
            else
            {
                tween           = transform.scaleTo(duration, scaleVec);
                tween.easeCurve = easeTo;
            }

            tween.easeType = GoEaseType.AnimationCurve;

            if (onComplete != null)
            {
                tween.setOnCompleteHandler(onComplete);
            }
        }
Exemplo n.º 6
0
        private void PlayTween(float xOffset, float yOffset, TweenMethod type, Action <AbstractGoTween> onComplete = null)
        {
            GoTween tween;
            var     vec = transform.localToWorldMatrix.MultiplyVector(new Vector3(xOffset, yOffset, 0));

            if (type == TweenMethod.PositionFrom)
            {
                tween           = transform.positionFrom(duration, vec, true);
                tween.easeCurve = easeFrom;
            }
            else
            {
                tween           = transform.positionTo(duration, vec, true);
                tween.easeCurve = easeTo;
            }

            tween.easeType = GoEaseType.AnimationCurve;

            if (onComplete != null)
            {
                tween.setOnCompleteHandler(onComplete);
            }
        }
Exemplo n.º 7
0
        /// <summary> 添加插值器到物体上 </summary>
        public static TweenInterpolator Create(
            GameObject gameObject,
            bool isPlaying                  = true,
            float delay                     = 0.0f,
            float duration                  = 1.0f,
            float speed                     = 1.0f,
            TweenMethod method              = TweenMethod.Linear,
            WrapMode wrapMode               = WrapMode.Once,
            TimeLine timeLine               = TimeLine.Normal,
            Action <float> onUpdate         = null,
            UnityAction onArriveAtEnding    = null,
            UnityAction onArriveAtBeginning = null)
        {
            TweenInterpolator interpolator = gameObject.AddComponent <TweenInterpolator>();

            interpolator.isPlaying = isPlaying;
            interpolator.delay     = delay;
            interpolator.duration  = duration;
            interpolator.speed     = speed;
            interpolator.method    = method;
            interpolator.wrapMode  = wrapMode;
            interpolator.timeLine  = timeLine;
            if (onUpdate != null)
            {
                interpolator.onTween += onUpdate;
            }
            if (onArriveAtEnding != null)
            {
                interpolator.onArriveAtEnding.AddListener(onArriveAtEnding);
            }
            if (onArriveAtBeginning != null)
            {
                interpolator.onArriveAtBeginning.AddListener(onArriveAtBeginning);
            }
            return(interpolator);
        }
Exemplo n.º 8
0
 /// <summary> 添加插值器到物体上 </summary>
 public static TweenInterpolator Create(
     GameObject gameObject,
     bool isPlaying = true,
     float delay = 0.0f,
     float duration = 1.0f,
     float speed = 1.0f,
     TweenMethod method = TweenMethod.Linear,
     WrapMode wrapMode = WrapMode.Once,
     TimeLine timeLine = TimeLine.Normal,
     Action<float> onUpdate = null,
     UnityAction onArriveAtEnding = null,
     UnityAction onArriveAtBeginning = null)
 {
     TweenInterpolator interpolator = gameObject.AddComponent<TweenInterpolator>();
     interpolator.isPlaying = isPlaying;
     interpolator.delay = delay;
     interpolator.duration = duration;
     interpolator.speed = speed;
     interpolator.method = method;
     interpolator.wrapMode = wrapMode;
     interpolator.timeLine = timeLine;
     if (onUpdate != null) interpolator.onTween += onUpdate;
     if (onArriveAtEnding != null) interpolator.onArriveAtEnding.AddListener(onArriveAtEnding);
     if (onArriveAtBeginning != null) interpolator.onArriveAtBeginning.AddListener(onArriveAtBeginning);
     return interpolator;
 }
Exemplo n.º 9
0
 private Func <float, float> In(TweenMethod method)
 {
     // Call the method function straight.
     return((Func <float, float>)Delegate.CreateDelegate(typeof(Func <float, float>), this,
                                                         GetType().GetMethod(method.ToString(), BindingFlags.NonPublic | BindingFlags.Instance) ?? throw new Exception($"Tween method [{method}] was not found.")));
 }
Exemplo n.º 10
0
        public static float GetTweenValue(TweenMethod tweenType, float startValue, float endValue, float val)
        {
            switch (tweenType)
            {
            case TweenMethod.linear:
                return(_Linear(startValue, endValue, val));

            case TweenMethod.spring:
                return(_Spring(startValue, endValue, val));

            case TweenMethod.EaseInQuad:
                return(_EaseInQuad(startValue, endValue, val));

            case TweenMethod.EaseOutQuad:
                return(_EaseOutQuad(startValue, endValue, val));

            case TweenMethod.EaseInOutQuad:
                return(_EaseInOutQuad(startValue, endValue, val));

            case TweenMethod.EaseInCubic:
                return(_EaseInCubic(startValue, endValue, val));

            case TweenMethod.EaseOutCubic:
                return(_EaseOutCubic(startValue, endValue, val));

            case TweenMethod.EaseInOutCubic:
                return(_EaseInOutCubic(startValue, endValue, val));

            case TweenMethod.EaseInQuart:
                return(_EaseInQuart(startValue, endValue, val));

            case TweenMethod.EaseOutQuart:
                return(_EaseOutQuart(startValue, endValue, val));

            case TweenMethod.EaseInOutQuart:
                return(_EaseInOutQuart(startValue, endValue, val));

            case TweenMethod.EaseInQuint:
                return(_EaseInQuint(startValue, endValue, val));

            case TweenMethod.EaseOutQuint:
                return(_EaseOutQuint(startValue, endValue, val));

            case TweenMethod.EaseInOutQuint:
                return(_EaseInOutQuint(startValue, endValue, val));

            case TweenMethod.EaseInSine:
                return(_EaseInSine(startValue, endValue, val));

            case TweenMethod.EaseOutSine:
                return(_EaseOutSine(startValue, endValue, val));

            case TweenMethod.EaseInOutSine:
                return(_EaseInOutSine(startValue, endValue, val));

            case TweenMethod.EaseInExpo:
                return(_EaseInExpo(startValue, endValue, val));

            case TweenMethod.EaseOutExpo:
                return(_EaseOutExpo(startValue, endValue, val));

            case TweenMethod.EaseInOutExpo:
                return(_EaseInOutExpo(startValue, endValue, val));

            case TweenMethod.EaseInCirc:
                return(_EaseInCirc(startValue, endValue, val));

            case TweenMethod.EaseOutCirc:
                return(_EaseOutCirc(startValue, endValue, val));

            case TweenMethod.EaseInOutCirc:
                return(_EaseInOutCirc(startValue, endValue, val));

            case TweenMethod.EaseInBounce:
                return(_EaseInBounce(startValue, endValue, val));

            case TweenMethod.EaseOutBounce:
                return(_EaseOutBounce(startValue, endValue, val));

            case TweenMethod.EaseInOutBounce:
                return(_EaseInOutBounce(startValue, endValue, val));

            case TweenMethod.EaseInBack:
                return(_EaseInBack(startValue, endValue, val));

            case TweenMethod.EaseOutBack:
                return(_EaseOutBack(startValue, endValue, val));

            case TweenMethod.EaseInOutBack:
                return(_EaseInOutBack(startValue, endValue, val));

            case TweenMethod.EaseInElastic:
                return(_EaseInElastic(startValue, endValue, val));

            case TweenMethod.EaseOutElastic:
                return(_EaseOutElastic(startValue, endValue, val));

            case TweenMethod.EaseInOutElastic:
                return(_EaseInOutElastic(startValue, endValue, val));

            default:
                return(endValue);
            }
        }