public float InOut(float time)
        {
            switch (type)
            {
            case AnimationEasingType.LinearEasing: return(time);

            case AnimationEasingType.QuadraticEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.CubicEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.QuarticEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.QuinticEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.SinusoidalEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.ExponentialEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.CircularEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.BounceEasing: return(EasingHelper.InOut(this, time));

            case AnimationEasingType.BackEasing: return(EasingHelper.BackInOut(time));

            case AnimationEasingType.ElasticEasing: return(EasingHelper.InOut(this, time));
            }
            return(time);
        }
        public float In(float time)
        {
            switch (type)
            {
            case AnimationEasingType.LinearEasing: return(time);

            case AnimationEasingType.QuadraticEasing: return(time * time);

            case AnimationEasingType.CubicEasing: return(time * time * time);

            case AnimationEasingType.QuarticEasing: return(Mathf.Pow(time, 4));

            case AnimationEasingType.QuinticEasing: return(Mathf.Pow(time, 5));

            case AnimationEasingType.SinusoidalEasing: return(Mathf.Sin((time - 1) * (Mathf.PI / 2)) + 1);

            case AnimationEasingType.ExponentialEasing: return(Mathf.Pow(2, 10 * (time - 1)));

            case AnimationEasingType.CircularEasing: return(-1 * Mathf.Sqrt(1 - time * time) + 1);

            case AnimationEasingType.BounceEasing: return(1 - Out(1 - time));

            case AnimationEasingType.BackEasing: return(EasingHelper.BackIn(time));

            case AnimationEasingType.ElasticEasing: return(ElasticIn(time));
            }
            return(time);
        }
Example #3
0
 public float In(float time) {
     switch (type) {
         case AnimationEasingType.Linear:
             return time;
         case AnimationEasingType.Quad:
             return (time * time);
         case AnimationEasingType.Cube:
             return (time * time * time);
         case AnimationEasingType.Quart:
             return Mathf.Pow(time, 4f);
         case AnimationEasingType.Quint:
             return Mathf.Pow(time, 5f);
         case AnimationEasingType.Sine:
             return Mathf.Sin((time - 1f) * (Mathf.PI / 2f)) + 1f;
         case AnimationEasingType.Expo:
             return Mathf.Pow(2f, 10f * (time - 1f));
         case AnimationEasingType.Circ:
             return (-1f * Mathf.Sqrt(1f - time * time) + 1f);
         case AnimationEasingType.Back:
             return time * time * ((s + 1f) * time - s);
         case AnimationEasingType.Bounce:
             return 1f - Out(1f - time);
         case AnimationEasingType.Elastic:
             return EasingHelper.Elastic(time, EasingType.In);
         case AnimationEasingType.Spring:
             return EasingHelper.Spring(time);
     }
     return time;
 }
Example #4
0
 public float InOut(float time) {
     switch (type) {
         case AnimationEasingType.Linear:
             return time;
         case AnimationEasingType.Quad:
         case AnimationEasingType.Cube:
         case AnimationEasingType.Quart:
         case AnimationEasingType.Quint:
         case AnimationEasingType.Sine:
         case AnimationEasingType.Expo:
         case AnimationEasingType.Circ:
         case AnimationEasingType.Bounce:
         case AnimationEasingType.Elastic:
             return EasingHelper.ElasticInOut(this, time);
         case AnimationEasingType.Back: {
             time *= 2f;
             if (time < 1f) {
                 return 0.5f * (time * time * ((s2 + 1f) * time - s2));
             } else {
                 time -= 2f;
                 return 0.5f * (time * time * ((s2 + 1f) * time + s2) + 2f);
             }
         }
         case AnimationEasingType.Spring:
             return EasingHelper.Spring(time);
     }
     return time;
 }
Example #5
0
    private IEnumerator MoveShakeStrength(ShakeData shakeData, Action onShakeCompleted = null)
    {
        float durationOffset       = UnityEngine.Random.Range(-shakeData.randomDurationOffset, shakeData.randomDurationOffset);
        float targetStrengthOffset = UnityEngine.Random.Range(-shakeData.randomTargetStrengthOffset, shakeData.randomTargetStrengthOffset);

        float duration       = shakeData.duration + durationOffset;
        float targetStrength = shakeData.targetStrength + targetStrengthOffset;
        float startStrength  = shakeStrength;

        float time = 0;

        while (time < duration)
        {
            float absoluteValue      = time / duration;
            float easedAbsoluteValue = EasingHelper.EaseInSine(absoluteValue);

            float strengthProgess      = targetStrength - startStrength;
            float easedStrengthProgess = strengthProgess * easedAbsoluteValue;

            shakeStrength = startStrength + easedStrengthProgess;

            time += Time.deltaTime;
            yield return(new WaitForEndOfFrame());
        }

        shakeStrength = targetStrength;

        if (onShakeCompleted != null)
        {
            onShakeCompleted();
        }
    }
Example #6
0
    private IEnumerator EasedLerpPosition(Vector2 start, Vector2 destination, EasingType easingType = EasingType.EaseLinear, Action onFinishMoveAlongPath = null)
    {
        float time = 0.0f;

        float fromToOnPathDistance = Vector3.Distance(start, destination);

        float duration = fromToOnPathDistance / speed;

        while (time < duration)
        {
            float progress      = time / duration;
            float easedProgress = EasingHelper.Ease(easingType, progress);

            time += Time.deltaTime;

            transform.position = Vector2.Lerp(start, destination, easedProgress);

            yield return(new WaitForEndOfFrame());
        }

        yield return(new WaitForEndOfFrame());

        if (onFinishMoveAlongPath != null)
        {
            onFinishMoveAlongPath();
        }
    }
        public float Out(float time)
        {
            switch (type)
            {
            case AnimationEasingType.LinearEasing: return(time);

            case AnimationEasingType.QuadraticEasing: return(time * (time - 2) * -1);

            case AnimationEasingType.CubicEasing: return(Mathf.Pow(time - 1, 3) + 1);

            case AnimationEasingType.QuarticEasing: return((Mathf.Pow(time - 1, 4) - 1) * -1);

            case AnimationEasingType.QuinticEasing: return(Mathf.Pow(time - 1, 5) + 1);

            case AnimationEasingType.SinusoidalEasing: return(Mathf.Sin(time * (Mathf.PI / 2)));

            case AnimationEasingType.ExponentialEasing: return(-1 * Mathf.Pow(2, -10 * time) + 1);

            case AnimationEasingType.CircularEasing: return(Mathf.Sqrt(1 - Mathf.Pow(time - 1, 2)));

            case AnimationEasingType.BounceEasing: return(EasingHelper.BounceOut(time));

            case AnimationEasingType.BackEasing: return(EasingHelper.BackOut(time));

            case AnimationEasingType.ElasticEasing: return(ElasticOut(time));
            }
            return(time);
        }
Example #8
0
    public static float Ease(double linearStep, float acceleration, EasingType type)
    {
        float easedStep = acceleration > 0 ? EaseIn(linearStep, type) :
                          acceleration < 0 ? EaseOut(linearStep, type) :
                          (float)linearStep;

        return(EasingHelper.Lerp(linearStep, easedStep, Math.Abs(acceleration)));
    }
Example #9
0
 protected override Task BeginAnimation()
 {
     if (Target == null)
     {
         throw new NullReferenceException("Null Target property.");
     }
     return(Target.FadeTo(Opacity, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing)));
 }
Example #10
0
        protected override void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
                                     , CanvasSpriteBatch spriteBatch
#endif
                                     )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = ActiveParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = ActiveParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                float normalizedLifetime = particle.TimeSinceStart / 4;
                if (normalizedLifetime > 1)
                {
                    normalizedLifetime = 1;
                }

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                float alpha = (float)EasingHelper.QuinticEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, normalizedLifetime);
                var   x     = particle.ScaleX;
                var   y     = particle.ScaleY;
                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                if (isImmersive)
                {
                    alpha *= 0.8f;
                    x     *= 1.2f;
                    y     *= 1.2f;
                }
#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(smokeSurfaces[particle.Key], particle.Position, new Vector4(1, 1, 1, alpha), bitmapCenter,
                                     particle.Rotation, new Vector2(x, y), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) *
                                    Matrix3x2.CreateScale(x, y, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(smokeSurfaces[particle.Key], 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
        protected override Task ResetAnimation()
        {
            if (Target == null)
            {
                throw new NullReferenceException("Null Target property.");
            }

            return(Target.RelScaleTo(Scale, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing)));
        }
Example #12
0
 public void Update()
 {
     if (surfaceLoaded)
     {
         if (nowFrame < inFrames)
         {
             var progress = nowFrame / (float)inFrames;
             progress   = (float)EasingHelper.QuinticEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, progress);
             position.X = (float)(xOffset * (progress - 0.5)) / 2;
             position.Y = (float)(yOffset * (progress - 0.5)) / 2;
             opcity     = 0.8f * progress;
         }
         nowFrame++;
         rotation = 0.000174532922222222f * nowFrame;
     }
 }
        protected override async void Invoke(VisualElement sender)
        {
            if (TargetProperty == null)
            {
                throw new NullReferenceException("Null Target property.");
            }

            if (Delay > 0)
                await Task.Delay(Delay);

            SetDefaultFrom((double)sender.GetValue(TargetProperty));

            sender.Animate($"AnimateInt{TargetProperty.PropertyName}", new Animation((progress) =>
            {
                sender.SetValue(TargetProperty, AnimationHelper.GetIntValue((int)From, (int)To, progress));
            }),
            length: Duration,
            easing: EasingHelper.GetEasing(Easing));
        }
Example #14
0
 public float Out(float time) {
     switch (type) {
         case AnimationEasingType.Linear:
             return time;
         case AnimationEasingType.Quad:
             return (time * (time - 2f) * -1f);
         case AnimationEasingType.Cube:
             return (Mathf.Pow(time - 1f, 3f) + 1f);
         case AnimationEasingType.Quart:
             return (Mathf.Pow(time - 1f, 4f) - 1f) * -1f;
         case AnimationEasingType.Quint:
             return (Mathf.Pow(time - 1f, 5f) + 1f);
         case AnimationEasingType.Sine:
             return Mathf.Sin(time * (Mathf.PI / 2f));
         case AnimationEasingType.Expo:
             return (-1f * Mathf.Pow(2f, -10f * time) + 1f);
         case AnimationEasingType.Circ:
             return Mathf.Sqrt(1f - Mathf.Pow(time - 1f, 2f));
         case AnimationEasingType.Back:
             time = time - 1f;
             return (time * time * ((s + 1f) * time + s) + 1f);
         case AnimationEasingType.Bounce: {
             if (time < (1f / 2.75f)) {
                 return (7.5625f * time * time);
             } else if (time < (2f / 2.75f)) {
                 time -= (1.5f / 2.75f);
                 return (7.5625f * time * time + 0.75f);
             } else if (time < (2.5f / 2.75f)) {
                 time -= (2.25f / 2.75f);
                 return (7.5625f * time * time + 0.9375f);
             } else {
                 time -= (2.625f / 2.75f);
                 return (7.5625f * time * time + 0.984375f);
             }
         }
         case AnimationEasingType.Elastic:
             return EasingHelper.Elastic(time, EasingType.Out);
         case AnimationEasingType.Spring:
             return EasingHelper.Spring(time);
     }
     return time;
 }
Example #15
0
        public void update(Vector2 size)
        {
            if (tempSurface != null && canDraw)
            {
                scale.X  = (float)(size.X / bound.Width > size.Y / bound.Height ? size.X / bound.Width : size.Y / bound.Height);
                scale.Y  = scale.X;
                position = size / 2;
                if (isImmersive)
                {
                    nowFrame++;
                    if (nowFrame <= inFrames)
                    {
                        opacity = (float)EasingHelper.QuinticEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, (double)nowFrame / inFrames);
                    }
                }
                else if (nowFrame != 0)
                {
                    nowFrame -= 1;
                    opacity   = (float)EasingHelper.QuinticEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, (double)nowFrame / inFrames);
                    if (nowFrame == 0)
                    {
                        canDraw = false;
                    }
                }

                if (enableBlur)
                {
                    blurFrame++;
                    if (blurFrame <= inFrames)
                    {
                        blur.BlurAmount = blurAmount * (float)EasingHelper.CircleEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, (double)blurFrame / inFrames);
                    }
                }
                else if (blurFrame != 0)
                {
                    blurFrame--;
                    blur.BlurAmount = blurAmount * (float)EasingHelper.CircleEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseIn, (double)blurFrame / inFrames);
                }
            }
        }
Example #16
0
 public EasingFunc(float duration, EEasingMethod method = EEasingMethod.Sine, EEasingType type = EEasingType.In)
 {
     m_Method = EasingHelper.Get(method, type);
     Duration = duration;
 }
Example #17
0
        override protected void CreateChildren()
        {
            base.CreateChildren();

            #region List 1

            List list1 = new List
            {
                PercentWidth  = 100,
                PercentHeight = 100,
                MinWidth      = 200,
                MinHeight     = 100,
                Height        = 200,
                DataProvider  = new ArrayList(EasingHelper.GetEasingList()),
                SelectedItem  = "Bounce"
            };
            AddContentChild(list1);

            #endregion

            #region List 2

            List list2 = new List
            {
                PercentWidth  = 100,
                PercentHeight = 100,
                MinHeight     = 100,
                Height        = 200,
                DataProvider  = new ArrayList(
                    Application.isWebPlayer
                                         ? ResolutionHelper.GetResolutionList()
                                         : ResolutionHelper.GetDummyResolutionList())
            };
            AddContentChild(list2);

            #endregion

            #region Drow down list

            DropDownList dropDownList = new DropDownList
            {
                PercentWidth = 100,
                MinWidth     = 200,
                DataProvider = new ArrayList(
                    Application.isWebPlayer
                                         ? ResolutionHelper.GetResolutionList()
                                         : ResolutionHelper.GetDummyResolutionList())
            };
            AddContentChild(dropDownList);

            dropDownList = new DropDownList
            {
                PercentWidth = 100,
                MinWidth     = 200,
                DataProvider = new ArrayList(new System.Collections.Generic.List <object>
                {
                    new ListItem(1, "Zagreb"),
                    new ListItem(2, "Osijek"),
                    new ListItem(3, "Rijeka"),
                    new ListItem(4, "Split"),
                    new ListItem(5, "Ljubljana"),
                    new ListItem(6, "Wiena"),
                    new ListItem(7, "Munich"),
                    new ListItem(8, "Berlin")
                })
            };
            AddContentChild(dropDownList);

            List list3 = new List
            {
                PercentWidth = 100,
                MinHeight    = 100,
                Height       = 200,
                DataProvider = new ArrayList(EasingHelper.GetEasingInOutList()),
                SelectedItem = "EaseIn"
            };
            AddContentChild(list3);

            #endregion

            #region Button

            Button btn = new Button
            {
                Text      = "Show alert",
                SkinClass = typeof(ImageButtonSkin),
                Icon      = Resources.Load <Texture>("Icons/tab-comment")
                            //StyleDeclaration = new StyleDeclaration(RectButtonSkin.Instance, "button"),
            };

            btn.Click += delegate
            {
                Alert.Show("Hi!", "This is the alert", AlertButtonFlag.Ok);
            };
            ControlBarGroup.AddChild(btn);

            #endregion
        }
Example #18
0
 public void LerpTest()
 {
     Assert.Equal(0.5, EasingHelper.Lerp(0, 1, 0.5));
     Assert.Equal(0.25, EasingHelper.Lerp(0, 1, 0.25));
     Assert.Equal(0.75, EasingHelper.Lerp(0, 1, 0.75));
 }
Example #19
0
 public void QubicTest()
 {
     Assert.Equal(1, EasingHelper.Cubic(1));
     Assert.Equal(0.5, EasingHelper.Cubic(0.5));
     Assert.Equal(0, EasingHelper.Cubic(0));
 }
Example #20
0
 public void EaseInTest()
 {
     Assert.Equal(1, EasingHelper.EaseIn(1));
     Assert.Equal(0, EasingHelper.EaseIn(0));
 }
Example #21
0
 public void EaseOutTest()
 {
     Assert.Equal(1, EasingHelper.EaseOut(1));
     Assert.Equal(0, EasingHelper.EaseOut(0));
 }
Example #22
0
 private double GetElasticFactor(double percent)
 {
     return(ElasticFactor * (1 - EasingHelper.QuinticEase(EasingMode.EaseOut, percent)));
 }