Inheritance: MonoBehaviour
    IEnumerator BuildSpikes()
    {
        Vector3[] verts = GetSpikes();
        int num = verts.Length;

        Easing[] easers = new Easing[num];

        for(int i = 0; i < num; i++)
        {
            easers[i] = new Easing(Easing.EaseType.Back, originalVerts[i], verts[i], 10);
        }

        yield return null;

        while(!easers[0].finished)
        {
            Vector3[] temp = new Vector3[num];

            for(int i = 0; i < num; i++)
            {
                temp[i] = easers[i].Vector3;
            }

            mesh.vertices = temp;
            mesh.RecalculateNormals();
            yield return null;
        }
        yield return null;
    }
Example #2
0
		public static Task<bool> LayoutTo(this VisualElement view, Rectangle bounds, uint length = 250, Easing easing = null)
		{
			if (view == null)
				throw new ArgumentNullException("view");
			if (easing == null)
				easing = Easing.Linear;

			var tcs = new TaskCompletionSource<bool>();
			Rectangle start = view.Bounds;
			Func<double, Rectangle> computeBounds = progress =>
			{
				double x = start.X + (bounds.X - start.X) * progress;
				double y = start.Y + (bounds.Y - start.Y) * progress;
				double w = start.Width + (bounds.Width - start.Width) * progress;
				double h = start.Height + (bounds.Height - start.Height) * progress;

				return new Rectangle(x, y, w, h);
			};
			var weakView = new WeakReference<VisualElement>(view);
			Action<double> layout = f =>
			{
				VisualElement v;
				if (weakView.TryGetTarget(out v))
					v.Layout(computeBounds(f));
			};
			new Animation(layout, 0, 1, easing).Commit(view, "LayoutTo", 16, length, finished: (f, a) => tcs.SetResult(a));

			return tcs.Task;
		}
Example #3
0
 private void _TestComposeRange (int [] values, Easing easing)
 {
     for (double i = 0, n = 100, p = 0, j = 0; i <= n; i += 5, p = i / n, j++) {
         int value = Choreographer.PixelCompose (p, (int)n, easing);
         Assert.AreEqual (values[(int)j], value);
     }
 }
        public static Task<bool> TranslateXTo(this VisualElement view, double x, 
                                              uint length = 250, Easing easing = null) 
        { 
            easing = easing ?? Easing.Linear; 
 	        TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>();
            WeakReference<VisualElement> weakViewRef = new WeakReference<VisualElement>(view);

            Animation animation = new Animation(
                (value) => 
                    {
                        VisualElement viewRef;
                        if (weakViewRef.TryGetTarget(out viewRef))
                        {
                            viewRef.TranslationX = value;
                        }
                    },              // callback
                view.TranslationX,  // start
                x,                  // end
                easing);            // easing

            animation.Commit(
                view,               // owner
                "TranslateXTo",     // name
                16,                 // rate
                length,             // length
                null,               // easing 
                (finalValue, cancelled) => 
                        taskCompletionSource.SetResult(cancelled)); // finished
 			 
 	        return taskCompletionSource.Task; 
        } 
	// Use this for initialization
	void Awake () {

		_Easing = GameObject.FindObjectOfType<Easing> ();



	}
 public TweenCreationSettings_old( Type type, Easing easing, float from, float to, TimeSpan duration )
 {
     From = @from ;
     To = to ;
     Type = type ;
     Easing = easing ;
     Duration = duration ;
 }
	// Use this for initialization
	void Start () {
		timer = 0;
		_easing = GameObject.FindObjectOfType<Easing>();
		_camera = GameObject.FindObjectOfType<ChangeCamera> ();
		//StartCoroutine (RandomShake(_camera.CurrentCamera));
		//StartCoroutine(SlideIn(5.0f,_camera.CurrentCamera,true));
		//StartCoroutine (R_HighFromCameraToTaget(3.0f,_camera.CurrentCamera));
	}
Example #8
0
		public Animation (IAnimationDrawer drawer, uint duration, Easing easing, Blocking blocking)
		{
			this.Drawer = drawer;
			this.Duration = duration;
			this.Easing = easing;
			this.Blocking = blocking;
			this.AnimationState = AnimationState.Coming;
		}
Example #9
0
 public static LNEase Action(Easing e, LNAction act)
 {
     LNEase action = new LNEase();
     action._duration = act._duration;
     action._action = act;
     act._easing = e;
     return action;
 }
Example #10
0
		public Task<bool> ProgressTo(double value, uint length, Easing easing)
		{
			var tcs = new TaskCompletionSource<bool>();

			this.Animate("Progress", d => Progress = d, Progress, value, length: length, easing: easing, finished: (d, finished) => tcs.SetResult(finished));

			return tcs.Task;
		}
		static Task<bool> ColorAnimation(VisualElement element, string name, Func<double, Color> transform, Action<Color> callback, uint length, Easing easing)
		{
			easing = easing ?? Easing.Linear;
			var taskCompletionSource = new TaskCompletionSource<bool>();

			element.Animate<Color>(name, transform, callback, 16, length, easing, (v, c) => taskCompletionSource.SetResult(c));
			return taskCompletionSource.Task;
		}
		public static Task<bool> ColorTo(this VisualElement self, Color fromColor, Color toColor, Action<Color> callback, uint length = 250, Easing easing = null)
		{
			Func<double, Color> transform = (t) =>
				Color.FromRgba(fromColor.R + t * (toColor.R - fromColor.R),
							   fromColor.G + t * (toColor.G - fromColor.G),
							   fromColor.B + t * (toColor.B - fromColor.B),
							   fromColor.A + t * (toColor.A - fromColor.A));
			return ColorAnimation(self, "ColorTo", transform, callback, length, easing);
		}
        public static ContextOperation<TimeSpan> Animate(this IGameContext context, TimeSpan duration, float startValue, float endValue, Action<float> valueStep, CancellationToken cancellationToken = default(CancellationToken), Easing easing = null)
        {
            var info = new FloatAnimation(duration, startValue, endValue, valueStep, easing);

            if (cancellationToken != default(CancellationToken))
                cancellationToken.Register(info.Cancel);

            return context.Run(info);
        }
Example #14
0
 //Tween Constructor Not Set FromValue
 public XTween(object target, string property = null, double to = 0, double duration = 0, Easing easing = Easing.EaseNoneInOut, double delay = 0)
 {
     target_ = target;
     SetProperties(property);
     ClearFrom();
     SetTo(to);
     SetDuration(duration);
     SetEasingFunction(easing);
     SetDelay(delay);
 }
Example #15
0
	// Use this for initialization
	void Start () {

		//どれかしらにアタッチしてある場合
		easing = GameObject.FindObjectOfType<Easing> ();
		//このスクリプトがアタッチされてるオブジェクトに
		//Easing.csがアタッチされている場合
		//easing = GetComponent<Easing>();


	}
        public static ContextOperation<TimeSpan> Animate(this IGameContext context, TimeSpan duration, Reference<Color> color, Color endColor, CancellationToken cancellationToken = default(CancellationToken), Easing easing = null)
        {
            if (color == null)
                throw new ArgumentNullException("color");

            return Animate(context, duration, color.Value, endColor, c =>
            {
                color.Value = c;
            }, cancellationToken,
            easing);
        }
Example #17
0
 // Use this for initialization
 void Start()
 {
     _easing = GameObject.FindObjectOfType<Easing>();
     _fade_sprite = GetComponent<SpriteRenderer>();
     doFadeIn = true;
     doFadeOut = false;
     _fade_count = 0.0f;
     _alfa_value = 0;
     _sprite_color = Color.white;
     _fade_sprite.color = _sprite_color;
 }
        public AnimatedWidget (Widget widget, uint duration, Easing easing, Blocking blocking, bool horizontal)
        {
            this.horizontal = horizontal;
            Widget = widget;
            Duration = duration;
            Easing = easing;
            Blocking = blocking;
            AnimationState = AnimationState.Coming;

            Widget.Parent = this;
            Widget.Destroyed += OnWidgetDestroyed;
            ShowAll ();
        }
Example #19
0
	// Use this for initialization
	void Start () {

		//アルファ値を0にして、見えない状態にしておく.
		_image_alfa = 0.0f;
		_Easing = GameObject.FindObjectOfType<Easing> ();
		foreach (var image in _fade_images) {
			image.enabled = true;
			image.color = new Color (1,1,1,_image_alfa);
		}
		_text.enabled = true;
		_text.color =  new Color (1,1,1,_image_alfa);

	}
        public static ContextOperation<TimeSpan> Animate(this IGameContext context, TimeSpan duration, Color startColor, Color endColor, Action<Color> colorStep, CancellationToken cancellationToken = default(CancellationToken), Easing easing = null)
        {
            if (colorStep == null)
                throw new ArgumentNullException("colorStep");

            var info = new FloatAnimation(duration, 0, 1, value =>
            colorStep(Color.Lerp(startColor, endColor, value)), easing);

            if (cancellationToken != default(CancellationToken))
                cancellationToken.Register(info.Cancel);

            return context.Run(info);
        }
Example #21
0
 public void ChangeWaypoints()
 {
     if (this.m_waypointIndex < this.m_cameraPosList.Count)
     {
         object arg_91_0 = this.Player.AttachedLevel.Camera;
         float arg_91_1 = 1.5f;
         Easing arg_91_2 = new Easing(Quad.EaseInOut);
         string[] array = new string[4];
         array[0] = "X";
         string[] arg_66_0 = array;
         int arg_66_1 = 1;
         float x = this.m_cameraPosList[this.m_waypointIndex].X;
         arg_66_0[arg_66_1] = x.ToString();
         array[2] = "Y";
         string[] arg_8F_0 = array;
         int arg_8F_1 = 3;
         float y = this.m_cameraPosList[this.m_waypointIndex].Y;
         arg_8F_0[arg_8F_1] = y.ToString();
         Tween.To(arg_91_0, arg_91_1, arg_91_2, array);
         object arg_10A_0 = this.Player;
         float arg_10A_1 = 1.5f;
         Easing arg_10A_2 = new Easing(Quad.EaseInOut);
         string[] array2 = new string[4];
         array2[0] = "X";
         string[] arg_DE_0 = array2;
         int arg_DE_1 = 1;
         float x2 = this.m_cameraPosList[this.m_waypointIndex].X;
         arg_DE_0[arg_DE_1] = x2.ToString();
         array2[2] = "Y";
         string[] arg_108_0 = array2;
         int arg_108_1 = 3;
         float y2 = this.m_cameraPosList[this.m_waypointIndex].Y;
         arg_108_0[arg_108_1] = y2.ToString();
         Tween.To(arg_10A_0, arg_10A_1, arg_10A_2, array2);
         this.m_waypointIndex++;
         if (this.m_waypointIndex > this.m_cameraPosList.Count - 1)
         {
             this.m_waypointIndex = 0;
             Tween.RunFunction(0f, this.Player.AttachedLevel.ScreenManager, "DisplayScreen", new object[]
             {
                 18,
                 true,
                 typeof(List<object>)
             });
             return;
         }
         Tween.RunFunction(this.m_waypointSpeed, this, "ChangeWaypoints", new object[0]);
     }
 }
Example #22
0
		public AnimatedWidget (Widget widget, uint duration, Easing easing, Blocking blocking, bool horizontal)
		{
			Mono.TextEditor.GtkWorkarounds.FixContainerLeak (this);
			
			this.horizontal = horizontal;
			Widget = widget;
			Duration = duration;
			Easing = easing;
			Blocking = blocking;
			AnimationState = AnimationState.Coming;
			
			Widget.Parent = this;
			Widget.Destroyed += OnWidgetDestroyed;
			ShowAll ();
		}
Example #23
0
    private Easing theEasing; //easing script

	//init
	void Start () {
        //properties
        //audio
        destroyAudioPlayed = false;

        //scripts
        theSpawn = gameObject.AddComponent<Spawn>(); //add new spawning script
        theEasing = gameObject.AddComponent<Easing>(); //add new easing script

        //check that rididbody2D and collider2d exist
        //check that duration is > 0 to prevent NaN
        if (gameObject.rigidbody2D != null &&
            gameObject.collider2D != null && 
            duration > 0.0f) {

            //spawn at random origin, if indicated
            //note: spawnOffScreen only affects random spawns
            if (randSpawn == true) {
                originPos = theSpawn.randSpawnWithBufferOffScreen(edgeBuffer, spawnOffScreen);
                gameObject.rigidbody2D.transform.position = originPos;
            }
            //otherwise, assume current position is intended spawn point
            else {
                originPos = getCurrentPos();
            }

            //generate random dest pos, if indicated
            if (randDest == true) {
                destPos = getRandDestPos();
            }

            //init private properties
            numLoopSegments = 0; //set initial number of loop segments completed
            moveStartTime = Time.time; //set initial move start time

        }
        //error
        else {
            Debug.Log("[Move] Error: Missing physics component(s) or invalid duration <= 0 - object cannot be moved");
            //disable scripts
            theSpawn.enabled = false;
            theEasing.enabled = false;
            this.enabled = false;
        }
	
	} //end function
Example #24
0
    IEnumerator closeSlice()
    {
        float theAngle = (props.eA + props.bA) / 2;

        Easing easer = new Easing(
            Easing.EaseType.Linear,
            transform.localPosition,
          	Vector3.zero,
          	seperationDuration
          	);

        while(!easer.finished)
        {
            transform.localPosition = easer.Vector3;
            //h = 1.5f - easer.Float;
            yield return null;
        }
    }
        public static Task<bool> BezierPathTo(this VisualElement view, 
                                              Point pt1, Point pt2, Point pt3, 
                                              uint length = 250, 
                                              BezierTangent bezierTangent = BezierTangent.None,
                                              Easing easing = null)
        {
            easing = easing ?? Easing.Linear;
            TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>();
            WeakReference<VisualElement> weakViewRef = new WeakReference<VisualElement>(view);

            Rectangle bounds = view.Bounds;
            BezierSpline bezierSpline = new BezierSpline(bounds.Center, pt1, pt2, pt3);

            Action<double> callback = t =>
                {
                    VisualElement viewRef;
                    if (weakViewRef.TryGetTarget(out viewRef))
                    {
                        Point tangent;
                        Point point = bezierSpline.GetPointAtFractionLength(t, out tangent);
                        double x = point.X - bounds.Width / 2;
                        double y = point.Y - bounds.Height / 2;
                        viewRef.Layout(new Rectangle(new Point(x, y), bounds.Size));

                        if (bezierTangent != BezierTangent.None)
                        {
                            viewRef.Rotation = 180 * Math.Atan2(tangent.Y, tangent.X) / Math.PI;

                            if (bezierTangent == BezierTangent.Reversed)
                            {
                                viewRef.Rotation += 180;
                            }
                        }
                    }
                };

            Animation animation = new Animation(callback, 0, 1, easing);
            animation.Commit(view, "BezierPathTo", 16, length,
                finished: (value, cancelled) => taskCompletionSource.SetResult(cancelled));

            return taskCompletionSource.Task;
        }
Example #26
0
		public static Task<bool> FadeTo(this VisualElement view, double opacity, uint length = 250, Easing easing = null)
		{
			if (view == null)
				throw new ArgumentNullException("view");
			if (easing == null)
				easing = Easing.Linear;

			var tcs = new TaskCompletionSource<bool>();
			var weakView = new WeakReference<VisualElement>(view);
			Action<double> fade = f =>
			{
				VisualElement v;
				if (weakView.TryGetTarget(out v))
					v.Opacity = f;
			};

			new Animation(fade, view.Opacity, opacity, easing).Commit(view, "FadeTo", 16, length, finished: (f, a) => tcs.SetResult(a));

			return tcs.Task;
		}
        public static Task<bool> TranslateYTo(this VisualElement view, double y,
                                              uint length = 250, Easing easing = null)
        {
            easing = easing ?? Easing.Linear;
            TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>();
            WeakReference<VisualElement> weakViewRef = new WeakReference<VisualElement>(view);

            Animation animation = new Animation((value) =>
                {
                    VisualElement viewRef;
                    if (weakViewRef.TryGetTarget(out viewRef))
                    {
                        viewRef.TranslationY = value;
                    }
                }, view.TranslationY, y, easing);

            animation.Commit(view, "TranslateYTo", 16, length, null,
                             (v, c) => taskCompletionSource.SetResult(c));

            return taskCompletionSource.Task;
        }
        public Tweener Using(InterpolationType interpolation, Easing easing)
        {
            object currentValueAsObject =
                LateBinder.GetValueStatic(Caller, MemberToSet);

            if (currentValueAsObject is float)
            {
                float currentValue = (float)currentValueAsObject;
                Tweener tweener = new Tweener(currentValue, ValueToSet, (float)TimeToTake,
                    interpolation, easing);

                tweener.PositionChanged = HandlePositionSet;

                TweenerManager.Self.Add(tweener);
                tweener.Start();
                return tweener;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #29
0
        public static double Compose (double percent, Easing easing)
        {
            if (percent < 0.0 || percent > 1.0) {
                throw new ArgumentOutOfRangeException ("percent", "must be between 0 and 1 inclusive");
            }

            switch (easing) {
                case Easing.QuadraticIn:
                    return percent * percent;

                case Easing.QuadraticOut:
                    return -1.0 * percent * (percent - 2.0);

                case Easing.QuadraticInOut:
                    percent *= 2.0;
                    return percent < 1.0
                        ? percent * percent * 0.5
                        : -0.5 * (--percent * (percent - 2.0) - 1.0);

                case Easing.ExponentialIn:
                    return Math.Pow (2.0, 10.0 * (percent - 1.0));

                case Easing.ExponentialOut:
                    return -Math.Pow (2.0, -10.0 * percent) + 1.0;

                case Easing.ExponentialInOut:
                    percent *= 2.0;
                    return percent < 1.0
                        ? 0.5 * Math.Pow (2.0, 10.0 * (percent - 1.0))
                        : 0.5 * (-Math.Pow (2.0, -10.0 * --percent) + 2.0);

                case Easing.Sine:
                    return Math.Sin (percent * Math.PI);

                case Easing.Linear:
                default:
                    return percent;
            }
        }
    public IEnumerator rePosition(Vector3 scale)
    {
        int arraySize = particleSystem.GetParticles(particles);

        Easing[] easers = new Easing[arraySize];

        for(int i = 0; i < arraySize; i++)
            easers[i] = new Easing(Easing.EaseType.Ease, particles[i].position, Vector3.Scale(particles[i].position, scale), 2f);

        yield return null;

        while(!easers[0].finished)
        {
            Debug.Log("here");

            for(int i = 0; i < arraySize; i++)
                particles[i].position = easers[i].Vector3;
            particleSystem.SetParticles(particles, arraySize);
            yield return null;

        }
        yield return null;
    }
        /// <summary>
        /// Coroutine for fading opacity.
        /// </summary>
        public static IEnumerator FadeCoroutine(GameObject gameObject, FadeDirection fadeDirection, float opacity, float duration, Easing easing, bool destroy, string cubicBezier)
        {
            float elapsedTime = 0;
            // get the starting material and color
            Renderer r = gameObject.GetComponent <Renderer>();
            Material m = Utils.GetUsableMaterial(r);
            Color    endColor;
            Color    startColor;

            // Is the object fading in or out?
            if (fadeDirection == FadeDirection.In)
            {
                // get the color instance with the right alpha value
                endColor   = Utils.GetUsableColor(r.material);
                startColor = new Color(endColor.r, endColor.g, endColor.b, opacity);
            }
            else
            {
                // Reverse if it's fading out
                startColor = Utils.GetUsableColor(r.material);
                endColor   = new Color(startColor.r, startColor.g, startColor.b, opacity);
            }

            // Skip ahead if this is meant to be an immediate transition.
            if (duration < 0.0001f)
            {
                m.SetColor("_Color", endColor);
            }
            else
            {
                while (elapsedTime < duration)
                {
                    float t = elapsedTime / duration;
                    // shift 't' based on the easing function
                    t            = Utils.GetT(t, easing, cubicBezier);
                    elapsedTime += Time.deltaTime;
                    Color currentColor = Color.Lerp(startColor, endColor, t);
                    m.SetColor("_Color", currentColor);
                    yield return(null);
                }
                m.SetColor("_Color", endColor);
            }

            // Destroy if specified
            if (destroy)
            {
                GameObject.Destroy(gameObject);
            }
        }
Example #32
0
 public void TestEasingStartsAtZero(Easing easing) => Assert.That(Interpolation.ApplyEasing(easing, 0), Is.EqualTo(0).Within(Precision.DOUBLE_EPSILON));
Example #33
0
 /// <summary>
 /// Sets <see cref="OsuSpriteText.Text"/> to a new value after a duration.
 /// </summary>
 /// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
 public static TransformSequence <T> TransformTextTo <T>(this T spriteText, string newText, double duration = 0, Easing easing = Easing.None)
     where T : OsuSpriteText
 => spriteText.TransformTo(nameof(OsuSpriteText.Text), newText, duration, easing);
Example #34
0
        public PopAnimationGroup()
        {
            IsDarkOverlayEnabled = false;
            IsShadowEnabled      = false;

            uint   duration = 400;
            Easing easing   = Easing.CubicOut;

            In = new PopAnimation()
            {
                OpacityEasing         = easing,
                TranslationYEasing    = easing,
                ScaleEasing           = easing,
                Duration              = duration,
                OpacityInit           = 0,
                OpacityStart          = 0,
                OpacityEnd            = 1,
                OpacityStartTime      = 0.5,
                OpacityEndTime        = 1,
                TranslationYInit      = 100,
                TranslationYStart     = 100,
                TranslationYEnd       = 0,
                TranslationYStartTime = 0.5,
                TranslationYEndTime   = 1,
            };

            BackIn = new PopAnimation()
            {
                OpacityEasing      = easing,
                TranslationYEasing = easing,
                ScaleEasing        = easing,
                Duration           = duration,
                OpacityInit        = 0,
                OpacityStart       = 0,
                OpacityEnd         = 1,
                OpacityStartTime   = 0.5,
                OpacityEndTime     = 1,
                ScaleInit          = 0.95,
                ScaleStart         = 0.95,
                ScaleEnd           = 1,
                ScaleStartTime     = 0.5,
                ScaleEndTime       = 1,
            };

            Out = new PopAnimation()
            {
                OpacityEasing      = easing,
                TranslationYEasing = easing,
                ScaleEasing        = easing,
                Duration           = duration,
                OpacityInit        = 1,
                OpacityStart       = 1,
                OpacityEnd         = 0,
                OpacityStartTime   = 0,
                OpacityEndTime     = 0.5,
            };

            BackOut = new PopAnimation()
            {
                OpacityEasing      = easing,
                TranslationYEasing = easing,
                ScaleEasing        = easing,
                Duration           = duration,
                OpacityInit        = 1,
                OpacityStart       = 1,
                OpacityEnd         = 0,
                OpacityStartTime   = 0,
                OpacityEndTime     = 0.5,
            };

            ModalIn = new PopAnimation()
            {
                ScaleEasing = easing,
                Duration    = 200,
                ScaleStart  = 0.9,
                ScaleEnd    = 1,
            };

            ModalOut = new PopAnimation()
            {
                OpacityEasing = easing,
                Duration      = 200,
                OpacityEnd    = 0,
            };
        }
 /// <summary>
 ///     Create a new instance of <see cref="AnalogKeyboardButton" /> with a custom easing.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="easing"></param>
 public AnalogKeyboardButton(KeyboardKey key, Easing easing)
 {
     Key    = key;
     Easing = easing;
 }
Example #36
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            e.Surface.Canvas.Clear();

            m_deviceScale = (float)(e.Info.Width / Width);

            SKPaint paint = new SKPaint()
            {
                Color = IndicatorForeground.ToSKColor(),
                Style = SKPaintStyle.Fill,
            };

            Easing ease = Easing.SinOut;

            using (SKPath path = new SKPath())
            {
                double startAngle = 0;
                double endAngle   = 0;

                if (m_animationProcess >= 0 && m_animationProcess <= 0.5)
                {
                    endAngle   = ease.Ease(m_animationProcess * 2) * 270;
                    startAngle = -10;
                }
                if (m_animationProcess > 0.5 && m_animationProcess <= 1)
                {
                    endAngle   = ease.Ease(1) * 270;
                    startAngle = ease.Ease((m_animationProcess - 0.5) * 2) * 250;
                }
                else if (m_animationProcess > 1 && m_animationProcess <= 1.5)
                {
                    endAngle   = 270;
                    startAngle = 250;
                }
                else if (m_animationProcess > 1.5 && m_animationProcess <= 2)
                {
                    endAngle   = 270 + (ease.Ease((m_animationProcess - 1.5) * 2) * 270);
                    startAngle = 250;
                }
                else if (m_animationProcess > 2 && m_animationProcess <= 2.5)
                {
                    endAngle   = 270 + 270;
                    startAngle = 250 + (ease.Ease((m_animationProcess - 2) * 2) * 270);
                }
                else if (m_animationProcess > 2.5 && m_animationProcess <= 3)
                {
                    endAngle   = 270 + 270;
                    startAngle = 250 + 270;
                }
                else if (m_animationProcess > 3 && m_animationProcess <= 3.5)
                {
                    endAngle   = 270 + 270 + (ease.Ease((m_animationProcess - 3) * 2) * 270);
                    startAngle = 250 + 270;
                }
                else if (m_animationProcess > 3.5 && m_animationProcess <= 4)
                {
                    endAngle   = 270 + 270 + 270;
                    startAngle = 250 + 270 + (ease.Ease((m_animationProcess - 3.5) * 2) * 270);
                }
                else if (m_animationProcess > 4 && m_animationProcess <= 4.5)
                {
                    endAngle   = 270 + 270 + 270;
                    startAngle = 250 + 270 + 270;
                }
                else if (m_animationProcess > 4.5 && m_animationProcess <= 5)
                {
                    endAngle   = 270 + 270 + 270 + (ease.Ease((m_animationProcess - 4.5) * 2) * 270);
                    startAngle = 250 + 270 + 270;
                }
                else if (m_animationProcess > 5 && m_animationProcess <= 5.5)
                {
                    endAngle   = 270 + 270 + 270 + 270;
                    startAngle = 250 + 270 + 270 + (ease.Ease((m_animationProcess - 5) * 2) * 270);
                }
                else if (m_animationProcess > 5.5 && m_animationProcess <= 6)
                {
                    endAngle   = 270 + 270 + 270 + 270;
                    startAngle = 250 + 270 + 270 + 270;
                }

                startAngle += (m_animationProcess / 2) * 360;
                endAngle   += (m_animationProcess / 2) * 360;

                float yOffset = (float)((Width - IndicatorSize.Width) / 2) * m_deviceScale;
                float xOffset = (float)((Height - IndicatorSize.Height) / 2) * m_deviceScale;

                float  skIndicatorThickness = (float)IndicatorThickness * m_deviceScale;
                SKSize skIndicatorSize      = new SKSize((float)IndicatorSize.Width * m_deviceScale, (float)IndicatorSize.Height * m_deviceScale);

                SKRect indicatorOuterBounds = new SKRect();
                indicatorOuterBounds.Location = new SKPoint(xOffset, yOffset);
                indicatorOuterBounds.Size     = new SKSize(skIndicatorSize.Width, skIndicatorSize.Height);

                SKRect indicatorInternalBounds = new SKRect();
                indicatorInternalBounds.Location = new SKPoint(xOffset + skIndicatorThickness, yOffset + skIndicatorThickness);
                indicatorInternalBounds.Size     = new SKSize((float)Math.Max(1, skIndicatorSize.Width - (skIndicatorThickness * 2)),
                                                              (float)Math.Max(1, skIndicatorSize.Height - (skIndicatorThickness * 2)));

                path.ArcTo(indicatorOuterBounds, (float)startAngle, (float)(endAngle - startAngle), false);
                path.ArcTo(indicatorInternalBounds, (float)endAngle, (float)-(endAngle - startAngle), false);

                e.Surface.Canvas.DrawPath(path, paint);
            }
        }
    // Update is called every frame, if the MonoBehaviour is enabled.
    void Update()
    {
        switch (state)
        {
        case CBState.toHand:
            float u  = (Time.time - timeStart) / timeDuration;
            float uC = Easing.Ease(u, MOVE_EASING);

            if (u < 0)
            {
                transform.localPosition = bezierPts[0];
                transform.rotation      = bezierRots[0];
                return;
            }
            else if (u >= 1)
            {
                uC = 1;
                if (state == CBState.toHand)
                {
                    state = CBState.hand;
                }
                if (state == CBState.toTarget)
                {
                    state = CBState.toTarget;
                }
                if (state == CBState.to)
                {
                    state = CBState.idle;
                }
                transform.localPosition = bezierPts[bezierPts.Count - 1];
                transform.rotation      = bezierRots[bezierPts.Count - 1];
                timeStart = 0;

                if (reportToFinish != null)
                {
                    reportToFinish.SendMessage("CBCallback2", this);
                    reportToFinish = null;
                }
                else if (callbackPlayer != null)
                {
                    callbackPlayer.CBCallback2(this);
                    callbackPlayer = null;
                }
            }

            else
            {
                Vector3 pos = Utils.Bezier(uC, bezierPts);
                transform.localPosition = pos;
                Quaternion rotQ = Utils.Bezier(uC, bezierRots);
                transform.rotation = rotQ;

                if (u > .5f && spriteRenderers[0].sortingOrder != eventualSortOrder)
                {
                    SetSortOrder(eventualSortOrder);
                }
                if (u > .75f && spriteRenderers[0].sortingLayerName != eventualSortLayer)
                {
                    SetSortingLayerName(eventualSortLayer);
                }
            }
            break;

        case CBState.toTarget:
        case CBState.to:
            u  = (Time.time - timeStart) / timeDuration;
            uC = Easing.Ease(u, MOVE_EASING);

            if (u < 0)
            {
                transform.localPosition = bezierPts[0];
                transform.rotation      = bezierRots[0];
                return;
            }
            else if (u >= 1)
            {
                uC = 1;
                if (state == CBState.toHand)
                {
                    state = CBState.hand;
                }
                if (state == CBState.toTarget)
                {
                    state = CBState.toTarget;
                }
                if (state == CBState.to)
                {
                    state = CBState.idle;
                }
                transform.localPosition = bezierPts[bezierPts.Count - 1];
                transform.rotation      = bezierRots[bezierPts.Count - 1];
                timeStart = 0;

                if (reportToFinish != null)
                {
                    reportToFinish.SendMessage("CBCallback", this);
                    reportToFinish = null;
                }
                else if (callbackPlayer != null)
                {
                    callbackPlayer.CBCallback(this);
                    callbackPlayer = null;
                }
            }
            else
            {
                Vector3 pos = Utils.Bezier(uC, bezierPts);
                transform.localPosition = pos;
                Quaternion rotQ = Utils.Bezier(uC, bezierRots);
                transform.rotation = rotQ;

                if (u > .5f && spriteRenderers[0].sortingOrder != eventualSortOrder)
                {
                    SetSortOrder(eventualSortOrder);
                }
                if (u > .75f && spriteRenderers[0].sortingLayerName != eventualSortLayer)
                {
                    SetSortingLayerName(eventualSortLayer);
                }
            }
            break;
        }
    }
Example #38
0
 public TransformSequence <T> TransformTo <TValue>(string propertyOrFieldName, TValue newValue, double duration = 0, Easing easing = Easing.None) =>
 Append(o => o.TransformTo(propertyOrFieldName, newValue, duration, easing));
Example #39
0
        private IEnumerator CollisionWithTornadoRoutine(TornadoGameObject tornado)
        {
            MyGame.ThisInstance.Camera.shakeDuration = 3000;

            _stork.InputEnabled        = false;
            _stork.IsMoveEnabled       = false;
            _stork.IsCollisionDisabled = true;

            _stork.SetSpeed(0);

            //Turn stork
            var turnStorkRoutine = CoroutineManager.StartCoroutine(TurnStorkInTornadoRoutine(), this);

            //Snap to tornado
            int       snapTimer    = 0;
            const int snapDuration = 200;

            var snapStartPos = _stork.Pos;

            SoundManager.Instance.PlayFx(9);

            while (snapTimer < snapDuration)
            {
                float xPos = (tornado.Pos.x - snapStartPos.x) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, snapTimer, 0, 1, snapDuration);
                float yPos = (tornado.Pos.y - snapStartPos.y) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, snapTimer, 0, 1, snapDuration);

                _stork.SetXY(snapStartPos.x + xPos, snapStartPos.y + yPos);

                snapTimer += Time.deltaTime;

                yield return(null);
            }

            //Keep stork in tornado
            int       stuckTimer    = 0;
            const int stuckDuration = 2000;

            while (stuckTimer < stuckDuration)
            {
                _stork.SetXY(tornado.x, tornado.y);

                stuckTimer += Time.deltaTime;
                yield return(null);
            }

            //Thrown Stork

            SoundManager.Instance.PlayFx(6);

            float throwAngle = 0;

            if (tornado.ThrowAngleMin == tornado.ThrowAngleMax)
            {
                throwAngle = tornado.ThrowAngleMin;
            }
            else
            {
                throwAngle = MRandom.Range((float)tornado.ThrowAngleMin, (float)tornado.ThrowAngleMax);
            }

            throwAngle = throwAngle.DegToRad();

            var throwDirection = new Vector2()
            {
                x = Mathf.Cos(throwAngle),
                y = Mathf.Sin(throwAngle)
            };

            var throwStartPos = tornado.Pos;
            var throwPos      = throwStartPos + throwDirection * tornado.ThrowDistance;

            int thrownTimer    = 0;
            int thrownDuration = 1000;

            float startScale = _stork.scale;

            Console.WriteLine($"{this}: throwAngle: {throwAngle.RadToDegree()}");

            while (thrownTimer < thrownDuration)
            {
                float xPos = (throwPos.x - throwStartPos.x) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, thrownTimer, 0, 1, thrownDuration);
                float yPos = (throwPos.y - throwStartPos.y) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, thrownTimer, 0, 1, thrownDuration);

                _stork.SetXY(throwStartPos.x + xPos, throwStartPos.y + yPos);

                float scale;
                if (thrownTimer < thrownDuration * 0.5f)
                {
                    scale = startScale + Easing.Ease(Easing.Equation.QuadEaseOut, thrownTimer, 0, 1, thrownDuration * 0.5f);
                }
                else
                {
                    scale = startScale + 1 - Easing.Ease(Easing.Equation.QuadEaseIn, thrownTimer - thrownDuration * 0.5f, 0, 1, thrownDuration * 0.5f);
                }

                _stork.SetScaleXY(scale, scale);

                thrownTimer += Time.deltaTime;
                yield return(null);
            }

            _stork.SetScaleXY(startScale, startScale);

            _inCollisionWithTornado = false;
            _lastTornadoCollided    = null;

            _stork.InputEnabled        = true;
            _stork.IsMoveEnabled       = true;
            _stork.IsCollisionDisabled = false;
        }
Example #40
0
    private void transition(int step)
    {
        // TODO: remap step from 0-steps into 0-1
        float linearStep = (float)step / (steps - 1);
        float e = Easing.Ease(linearStep, acceleration, easingType);
        float newX = 0f, newY = 0f;

        switch (direction)
        {
        case Direction.Up:
            newX = startPos.x; newY = startPos.y + e;
            // don't exceed the final position
            if (newY > finalPos.y)
            {
                newY = finalPos.y;
            }
            break;

        case Direction.Down:
            newX = startPos.x; newY = startPos.y - e;
            // don't exceed the final position
            if (newY < finalPos.y)
            {
                newY = finalPos.y;
            }
            break;

        case Direction.Left:
            newX = startPos.x - e; newY = startPos.y;
            // don't exceed the final position
            if (newX < finalPos.x)
            {
                newX = finalPos.x;
            }
            break;

        case Direction.Right:
            newX = startPos.x + e; newY = startPos.y;
            // don't exceed the final position
            if (newX > finalPos.x)
            {
                newX = finalPos.x;
            }
            break;
        }

        switch (elem)
        {
        case Element.TRANSFORM: {
            Vector3 pos = transform.localPosition;
            pos.x = newX;
            pos.y = newY;
            transform.localPosition = pos;
            break;
        }

            /*case Element.GUI_TEXT: {
             *      Vector2 pOffset = guiText.pixelOffset;
             *      pOffset.x = newX;
             *      pOffset.y = newY;
             *      guiText.pixelOffset = pOffset;
             *      break; }
             * case Element.GUI_TEXTURE: {
             *      Rect pInset = guiTexture.pixelInset;
             *      pInset.x = newX;
             *      pInset.y = newY;
             *      guiTexture.pixelInset = pInset;
             *      break; }*/
        }
    }
        /// <summary>
        /// Coroutine for tweening material or color-only properties.
        /// </summary>
        public static IEnumerator TweenMaterialCoroutine(GameObject gameObject, Material startMaterial, Material endMaterial, float duration, Easing easing, string cubicBezier)
        {
            float elapsedTime = 0;
            // get the starting material and color
            Renderer r = gameObject.GetComponent <Renderer>();
            // this is the material we'll tween
            Material m = Utils.GetUsableMaterial(r);

            // If start material is null, assume we're tweening FROM the current material
            if (startMaterial == null)
            {
                startMaterial = Utils.GetUsableMaterial(r);
            }

            // If end material is null, assume we're tweening TO the current material
            if (endMaterial == null)
            {
                // Debug.Log ("EndMaterial is null");
                endMaterial = Utils.GetUsableMaterial(r);
            }

            // Skip ahead if this is meant to be an immediate transition.
            if (duration < 0.0001f)
            {
                m.CopyPropertiesFromMaterial(endMaterial);
            }
            else
            {
                startMaterial = Utils.GetUsableMaterial(startMaterial);
                endMaterial   = Utils.GetUsableMaterial(endMaterial);
                while (elapsedTime < duration)
                {
                    float t = elapsedTime / duration;
                    // shift 't' based on the easing function
                    t            = Utils.GetT(t, easing, cubicBezier);
                    elapsedTime += Time.deltaTime;
                    m.Lerp(startMaterial, endMaterial, t);
                    yield return(null);
                }
                m.CopyPropertiesFromMaterial(endMaterial);
            }
        }
        /// <summary>
        /// Coroutine for tweening scale.
        /// </summary>
        public static IEnumerator TweenScaleCoroutine(GameObject gameObject, Vector3 targetScale, float duration, Easing easing, bool destroy, bool isRelative, string cubicBezier)
        {
            float   elapsedTime = 0;
            Vector3 startScale  = gameObject.transform.localScale;
            Vector3 endScale;

            if (isRelative)
            {
                // the supplied Vector3 is relative to the original scale
                endScale = new Vector3(startScale.x * targetScale.x, startScale.y * targetScale.y, startScale.z * targetScale.z);
            }
            else
            {
                endScale = targetScale;
            }

            if (duration < 0.0001f)
            {
                gameObject.transform.localScale = endScale;
            }
            else
            {
                while (elapsedTime < duration)
                {
                    float t = elapsedTime / duration;
                    // shift 't' based on the easing function
                    t            = Utils.GetT(t, easing, cubicBezier);
                    elapsedTime += Time.deltaTime;
                    // set the scale
                    Vector3 interpolatedScale = Vector3.Lerp(startScale, endScale, t);
                    gameObject.transform.localScale = interpolatedScale;
                    yield return(null);
                }
                gameObject.transform.localScale = endScale;
            }

            // Destroy if specified.
            if (destroy)
            {
                GameObject.Destroy(gameObject);
            }
        }
        private void SwapPlayers()
        {
            // Pause the previously playing video
            // This is useful for systems that will struggle to play 2 videos at once
            if (_pausePreviousOnTransition)
            {
                CurrentPlayer.Pause();
            }

            // Tell listeners that the playlist item has changed
            Events.Invoke(this, MediaPlayerEvent.EventType.PlaylistItemChanged, ErrorCode.None);

            // Start the transition
            if (_currentTransition != Transition.None)
            {
                // Create a new transition texture if required
                Texture currentTexture = GetCurrentTexture();
                Texture nextTexture    = GetNextTexture();
                if (currentTexture != null && nextTexture != null)
                {
                    int maxWidth  = Mathf.Max(nextTexture.width, currentTexture.width);
                    int maxHeight = Mathf.Max(nextTexture.height, currentTexture.height);
                    if (_rt != null)
                    {
                        if (_rt.width != maxWidth || _rt.height != maxHeight)
                        {
                            RenderTexture.ReleaseTemporary(_rt = null);
                        }
                    }
                    if (_rt == null)
                    {
                        _rt = RenderTexture.GetTemporary(maxWidth, maxHeight, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 1);
                    }
                    Graphics.Blit(currentTexture, _rt);

                    _material.SetTexture(_propFromTex, currentTexture);

                    _easeFunc        = Easing.GetFunction(_currentTransitionEasing);
                    _transitionTimer = 0f;
                }
                else
                {
                    _transitionTimer = _currentTransitionDuration;

                    if (_autoCloseVideo)
                    {
                        CurrentPlayer.CloseVideo();
                    }
                }
            }

            // Swap the videos
            if (NextPlayer == _playerA)
            {
                _nextPlayer = _playerB;
            }
            else
            {
                _nextPlayer = _playerA;
            }

            // Swap the items
            _currentItem = _nextItem;
            _nextItem    = null;
        }
Example #44
0
 /// <summary>
 /// Sew this displacement to others.
 /// </summary>
 /// <param name="displacements">The displacements to sew</param>
 /// <param name="sewType"></param>
 /// <param name="numPointsFromEdgeToMove"></param>
 /// <param name="easingFunction"></param>
 public void SewTo(IEnumerable <Displacement> displacements, DisplacementSewType sewType,
                   int numPointsFromEdgeToMove, Easing easingFunction)
 {
 }
Example #45
0
        public void Random_All_Rand()
        {
            var actual = Easing.Random();

            CollectionAssert.Contains(Easing.All, actual);
        }
        static Task AnimatedMove(IAnimatable animatable, EvasObject target, ERect dest, Easing easing = null, uint length = 120)
        {
            var tcs = new TaskCompletionSource <bool>();

            var dx = target.Geometry.X - dest.X;
            var dy = target.Geometry.Y - dest.Y;

            new Animation((progress) =>
            {
                ERect toMove    = dest;
                toMove.X       += (int)(dx * (1 - progress));
                toMove.Y       += (int)(dy * (1 - progress));
                target.Geometry = toMove;
            }).Commit(animatable, "Move", rate: 60, length: length, easing: easing, finished: (p, e) =>
            {
                tcs.SetResult(true);
            });
            return(tcs.Task);
        }
Example #47
0
 public Tweener(float from, float to, float duration, InterpolationType type, Easing easing)
 {
     Start(from, to, duration, GetInterpolationFunction(type, easing));
     // Start sets Running to true, so let's set it to false
     Running = false;
 }
    void UpdateBlock(LiveBlock block)
    {
//		const float damping = 100;

        if (!block.isClosed)
        {
            double closeTime = MusicPlayer.LiveTime - block.createTime;
            if (closeTime > closeDuration)
            {
                block.isClosed = true;
                ParticleFxPool.Emit(closeParticleFxPreset, block.transform.position, block.transform.rotation);
                FlashFxPool.Flash(closeFlashFxConfig, block.transform.position);

                block.leftShellTrans.localPosition  = Vector3.zero;
                block.rightShellTrans.localPosition = Vector3.zero;
            }
            else
            {
                block.leftShellTrans.localPosition  = new Vector3(0, 0, Easing.Ease(closeEasingType, closeEasingPhase, shellStart, -shellStart, closeTime, closeDuration));
                block.rightShellTrans.localPosition = new Vector3(0, 0, Easing.Ease(closeEasingType, closeEasingPhase, -shellStart, shellStart, closeTime, closeDuration));
            }
        }

        if (MusicPlayer.LiveTime <= block.startTime)            // Not yet
        {
            var offset = block.startTime - MusicPlayer.LiveTime;
            var x      = Easing.Ease(bufferEasingTypeX, bufferEasingPhaseX, block.x, bufferX * block.startX, offset, bufferInterval);
            var y      = Easing.Ease(bufferEasingTypeY, bufferEasingPhaseY, block.y, bufferY * block.startY, offset, bufferInterval);
            var z      = Easing.Ease(bufferEasingTypeZ, bufferEasingPhaseZ, 0, bufferZ, offset, bufferInterval);
//			block.transform.localPosition = Vector3.Lerp(block.transform.localPosition, new Vector3(x, y, z), UnityEngine.Time.deltaTime * damping);
            block.transform.localPosition = new Vector3(x, y, z);
        }
        else if (MusicPlayer.LiveTime - block.startTime < cacheInterval && MusicPlayer.LiveTime - block.startTime < TimeBad)              // Over due
        {
            var offset = MusicPlayer.LiveTime - block.startTime;
            var x      = Easing.Ease(cacheEasingTypeX, cacheEasingPhaseX, block.x, cacheX * block.x, offset, cacheInterval);
            var y      = Easing.Ease(cacheEasingTypeY, cacheEasingPhaseY, block.y, cacheY * block.y, offset, cacheInterval);
            var z      = Easing.Ease(cacheEasingTypeZ, cacheEasingPhaseZ, 0, cacheZ, offset, cacheInterval);
//			block.transform.localPosition = Vector3.Lerp(block.transform.localPosition, new Vector3(x, y, z), UnityEngine.Time.deltaTime * damping);
            block.transform.localPosition = new Vector3(x, y, z);
        }
        else              // Miss
        {
            AudioFxPool.Play(badAudioConfigs[Random.Range(0, badAudioConfigs.Length)], block.transform.position);
            FlashFxPool.Flash(badFlashFxConfig, block.transform.position);

            uiScoreText.material    = badMaterial;
            uiComboText.material    = badMaterial;
            uiIncText.text          = "";
            uiComboText.text        = "x 0 x";
            uiComboTextTween.isDead = false;
            uiComboTextTween.time   = 0;

            block.shouldDie         = true;
            block.shouldDieSilently = true;
            combo = 0;

            miss += 1;
        }

        if (block.isClosed && MusicPlayer.LiveTime - block.startTime < cacheInterval) // Detect collision
        {
            if (block.side == Side.Left)                                              // Left hand
            {
                if (Vector3.Dot(leftTip.velocity, -block.transform.up) > block.minDyingSpeed)
                {
                    DetectCollision(leftTip, block);
                }
            }
            else                  // Right hand
            {
                if (Vector3.Dot(rightTip.velocity, -block.transform.up) > block.minDyingSpeed)
                {
                    DetectCollision(rightTip, block);
                }
            }
        }
    }
Example #49
0
    void Update()
    {
        switch (state)   // f
        {
        case CBState.toHand:
        case CBState.toTarget:
        case CBState.to:
            float u  = (Time.time - timeStart) / timeDuration;    // g
            float uC = Easing.Ease(u, MOVE_EASING);

            if (u < 0)       // h
            {
                transform.localPosition = bezierPts[0];
                transform.rotation      = bezierRots[0];
                return;
            }
            else if (u >= 1)         // i
            {
                uC = 1;
                // Move from the to... state to the proper next state

                if (state == CBState.toHand)
                {
                    state = CBState.hand;
                }
                if (state == CBState.toTarget)
                {
                    state = CBState.target;
                }
                if (state == CBState.toDrawpile)
                {
                    state = CBState.drawpile;
                }
                if (state == CBState.to)
                {
                    state = CBState.idle;
                }

                // Move to the final position
                transform.localPosition = bezierPts[bezierPts.Count - 1];
                transform.rotation      = bezierRots[bezierPts.Count - 1];

                // Reset timeStart to 0 so it gets overwritten next time
                timeStart = 0;

                if (reportFinishTo != null)       // j
                {
                    reportFinishTo.SendMessage("CBCallback", this);
                    reportFinishTo = null;
                }
                else if (callbackPlayer != null)         // c
                // If there's a callback Player
                // Call CBCallback directly on the Player
                {
                    callbackPlayer.CBCallback(this);
                    callbackPlayer = null;
                }
                else         // If there is nothing to callback
                // Just let it stay still.
                {
                }
            }
            else         // Normal interpolation behavior (0 <= u < 1) // k
            {
                Vector3 pos = Utils.Bezier(uC, bezierPts);
                transform.localPosition = pos;
                Quaternion rotQ = Utils.Bezier(uC, bezierRots);
                transform.rotation = rotQ;

                if (u > 0.5f)       // a
                {
                    SpriteRenderer sRend = spriteRenderers[0];
                    if (sRend.sortingOrder != eventualSortOrder)
                    {
                        // Jump to the proper sort order
                        SetSortOrder(eventualSortOrder);
                    }
                    if (sRend.sortingLayerName != eventualSortLayer)
                    {
                        // Jump to the proper sort layer
                        SetSortingLayerName(eventualSortLayer);
                    }
                }
            }
            break;
        }
    }
Example #50
0
        public static TweeningFunction GetInterpolationFunction(InterpolationType type, Easing easing)
        {
            switch (type)
            {
            case InterpolationType.Back:
                switch (easing)
                {
                case Easing.In:
                    return(Back.EaseIn);

                case Easing.Out:
                    return(Back.EaseOut);

                case Easing.InOut:
                    return(Back.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Bounce:
                switch (easing)
                {
                case Easing.In:
                    return(Bounce.EaseIn);

                case Easing.Out:
                    return(Bounce.EaseOut);

                case Easing.InOut:
                    return(Bounce.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Circular:
                switch (easing)
                {
                case Easing.In:
                    return(Circular.EaseIn);

                case Easing.Out:
                    return(Circular.EaseOut);

                case Easing.InOut:
                    return(Circular.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Cubic:
                switch (easing)
                {
                case Easing.In:
                    return(Cubic.EaseIn);

                case Easing.Out:
                    return(Cubic.EaseOut);

                case Easing.InOut:
                    return(Cubic.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Elastic:
                switch (easing)
                {
                case Easing.In:
                    return(Elastic.EaseIn);

                case Easing.Out:
                    return(Elastic.EaseOut);

                case Easing.InOut:
                    return(Elastic.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Exponential:
                switch (easing)
                {
                case Easing.In:
                    return(Exponential.EaseIn);

                case Easing.Out:
                    return(Exponential.EaseOut);

                case Easing.InOut:
                    return(Exponential.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Linear:
                switch (easing)
                {
                case Easing.In:
                    return(Linear.EaseIn);

                case Easing.Out:
                    return(Linear.EaseOut);

                case Easing.InOut:
                    return(Linear.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Quadratic:
                switch (easing)
                {
                case Easing.In:
                    return(Quadratic.EaseIn);

                case Easing.Out:
                    return(Quadratic.EaseOut);

                case Easing.InOut:
                    return(Quadratic.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Quartic:
                switch (easing)
                {
                case Easing.In:
                    return(Quartic.EaseIn);

                case Easing.Out:
                    return(Quartic.EaseOut);

                case Easing.InOut:
                    return(Quartic.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Quintic:
                switch (easing)
                {
                case Easing.In:
                    return(Quintic.EaseIn);

                case Easing.Out:
                    return(Quintic.EaseOut);

                case Easing.InOut:
                    return(Quintic.EaseInOut);

                default:
                    throw new Exception();
                }

            case InterpolationType.Sinusoidal:
                switch (easing)
                {
                case Easing.In:
                    return(Sinusoidal.EaseIn);

                case Easing.Out:
                    return(Sinusoidal.EaseOut);

                case Easing.InOut:
                    return(Sinusoidal.EaseInOut);

                default:
                    throw new Exception();
                }

            default:
                throw new Exception();
            }
        }
Example #51
0
        public Tweener Tween(string member, float value, float time, InterpolationType interpolation, Easing easing)
        {
            MemberToSet = member;

            object currentValueAsObject =
                LateBinder.GetValueStatic(Caller, member);

            if (currentValueAsObject is float)
            {
                float   currentValue = (float)currentValueAsObject;
                Tweener tweener      = new Tweener(currentValue, value, time,
                                                   interpolation, easing);

                tweener.PositionChanged = HandlePositionSet;

                tweener.Owner = Caller;

                TweenerManager.Self.Add(tweener);
                tweener.Start();
                return(tweener);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            bool valuesChanged = false;

            if (Angle < 1 || Angle > 100000)
            {
                Angle         = Math.Min(100000, Math.Max(1, Angle));
                valuesChanged = true;
            }

            if (RotationDistance < 0 || RotationDistance > 100000)
            {
                RotationDistance = Math.Min(100000, Math.Max(0, RotationDistance));
                valuesChanged    = true;
            }

            if (RotationSlices < 3 || RotationSlices > 300)
            {
                RotationSlices = Math.Min(300, Math.Max(3, RotationSlices));
                valuesChanged  = true;
            }

            if (EndHeightPercent < 1 || EndHeightPercent > 100)
            {
                EndHeightPercent = Math.Min(100, Math.Max(1, EndHeightPercent));
                valuesChanged    = true;
            }

            if (StartHeightPercent < 0 || StartHeightPercent > EndHeightPercent - 1)
            {
                StartHeightPercent = Math.Min(EndHeightPercent - 1, Math.Max(0, StartHeightPercent));
                valuesChanged      = true;
            }

            if (OverrideRadius < .01)
            {
                OverrideRadius = Math.Max(this.GetAxisAlignedBoundingBox().XSize, this.GetAxisAlignedBoundingBox().YSize);
                valuesChanged  = true;
            }

            var rebuildLocks = this.RebuilLockAll();

            return(ApplicationController.Instance.Tasks.Execute(
                       "Twist".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var sourceAabb = this.SourceContainer.GetAxisAlignedBoundingBox();

                var bottom = sourceAabb.MinXYZ.Z;
                var top = sourceAabb.ZSize * EndHeightPercent / 100.0;
                var size = sourceAabb.ZSize;
                if (Advanced)
                {
                    bottom += sourceAabb.ZSize * StartHeightPercent / 100.0;
                    size = top - bottom;
                }

                double numberOfCuts = RotationSlices;

                double cutSize = size / numberOfCuts;
                var cuts = new List <double>();
                for (int i = 0; i < numberOfCuts + 1; i++)
                {
                    var ratio = i / numberOfCuts;
                    if (Advanced)
                    {
                        var goal = ratio;
                        var current = .5;
                        var next = .25;
                        // look for an x value that equals the goal
                        for (int j = 0; j < 64; j++)
                        {
                            var xAtY = Easing.Specify(EasingType, EasingOption, current);
                            if (xAtY < goal)
                            {
                                current += next;
                            }
                            else if (xAtY > goal)
                            {
                                current -= next;
                            }

                            next *= .5;
                        }

                        ratio = current;
                    }

                    cuts.Add(bottom - cutSize + (size * ratio));
                }

                // get the rotation from the center of the circumscribed circle of the convex hull
                var enclosingCircle = SourceContainer.GetSmallestEnclosingCircleAlongZ();
                var rotationCenter = enclosingCircle.Center + RotationOffset;

                var twistedChildren = new List <IObject3D>();

                var status = new ProgressStatus();

                foreach (var sourceItem in SourceContainer.VisibleMeshes())
                {
                    var originalMesh = sourceItem.Mesh;
                    status.Status = "Copy Mesh".Localize();
                    reporter.Report(status);
                    var transformedMesh = originalMesh.Copy(CancellationToken.None);
                    var itemMatrix = sourceItem.WorldMatrix(SourceContainer);

                    // transform into this space
                    transformedMesh.Transform(itemMatrix);

                    status.Status = "Split Mesh".Localize();
                    reporter.Report(status);

                    // split the mesh along the z axis
                    transformedMesh.SplitOnPlanes(Vector3.UnitZ, cuts, cutSize / 8);

                    for (int i = 0; i < transformedMesh.Vertices.Count; i++)
                    {
                        var position = transformedMesh.Vertices[i];

                        var ratio = (position.Z - bottom) / size;

                        if (Advanced)
                        {
                            if (position.Z < bottom)
                            {
                                ratio = 0;
                            }
                            else if (position.Z > top)
                            {
                                ratio = 1;
                            }
                            else
                            {
                                ratio = (position.Z - bottom) / size;
                                ratio = Easing.Specify(EasingType, EasingOption, ratio);
                            }
                        }

                        var angleToRotate = ratio * Angle / 360.0 * MathHelper.Tau;
                        if (RotationType == RotationTypes.Distance)
                        {
                            IRadiusProvider radiusProvider = RadiusProvider;

                            // start off with assuming we want to set the radius
                            var radius = this.OverrideRadius;
                            if (radiusProvider != null && !this.EditRadius)
                            {
                                // have a radius provider and not wanting to edit
                                radius = radiusProvider.Radius;
                            }
                            else if (!this.EditRadius)
                            {
                                // not wanting to edit
                                radius = enclosingCircle.Radius;
                            }

                            if (this.PreferedRadius != radius)
                            {
                                this.PreferedRadius = radius;
                                this.OverrideRadius = radius;
                                UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
                            }

                            angleToRotate = ratio * (RotationDistance / radius);
                        }

                        if (!TwistCw)
                        {
                            angleToRotate = -angleToRotate;
                        }

                        var positionXy = new Vector2(position) - rotationCenter;
                        positionXy.Rotate(angleToRotate);
                        positionXy += rotationCenter;
                        transformedMesh.Vertices[i] = new Vector3Float(positionXy.X, positionXy.Y, position.Z);
                    }

                    // transform back into item local space
                    transformedMesh.Transform(itemMatrix.Inverted);

                    //transformedMesh.MergeVertices(.1);
                    transformedMesh.CalculateNormals();

                    var twistedChild = new Object3D()
                    {
                        Mesh = transformedMesh
                    };
                    twistedChild.CopyWorldProperties(sourceItem, SourceContainer, Object3DPropertyFlags.All, false);
                    twistedChild.Visible = true;

                    twistedChildren.Add(twistedChild);
                }

                RemoveAllButSource();
                this.SourceContainer.Visible = false;

                this.Children.Modify((list) =>
                {
                    list.AddRange(twistedChildren);
                });

                rebuildLocks.Dispose();

                if (valuesChanged)
                {
                    Invalidate(InvalidateType.DisplayValues);
                }

                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));

                return Task.CompletedTask;
            }));
        }
Example #53
0
 /// <summary>
 /// Sets <see cref="OsuSpriteText.Text"/> to a new value after a duration.
 /// </summary>
 /// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
 public static TransformSequence <T> TransformTextTo <T>(this TransformSequence <T> t, string newText, double duration = 0, Easing easing = Easing.None)
     where T : OsuSpriteText
 => t.Append(o => o.TransformTextTo(newText, duration, easing));
Example #54
0
 protected virtual Task RunAnimation(string animationName, string propertyName, double from, double to, uint duration, Easing easing) => View.Animate(animationName, propertyName, from, to, duration, easing);
Example #55
0
 public void TestEasingEndsAtOne(Easing easing) => Assert.That(Interpolation.ApplyEasing(easing, 1), Is.EqualTo(1).Within(Precision.DOUBLE_EPSILON));
Example #56
0
    // Update is called once per frame

    void Update()
    {
        // If this is not moving, just return

        if (state == eFSState.idle)
        {
            return;
        }



        // Get u from the current time and duration

        // u ranges from 0 to 1 (usually)

        float u = (Time.time - timeStart) / timeDuration;

        // Use Easing class from Utils to curve the u value

        float uC = Easing.Ease(u, easingCurve);

        if (u < 0)
        {
            // If u<0, then we shouldn't move yet.

            state = eFSState.pre;

            txt.enabled = false; // Hide the score initially
        }
        else
        {
            if (u >= 1)
            {
                // If u>=1, we're done moving

                uC = 1; // Set uC=1 so we don't overshoot

                state = eFSState.post;

                if (reportFinishTo != null)
                {
                    //If there's a callback GameObject

                    // Use SendMessage to call the FSCallback method

                    //  with this as the parameter.

                    reportFinishTo.SendMessage("FSCallback", this);

                    // Now that the message has been sent,

                    //  Destroy this gameObject

                    Destroy(gameObject);
                }
                else
                {
                    // If there is nothing to callback

                    // ...then don't destroy this. Just let it stay still.

                    state = eFSState.idle;
                }
            }
            else
            {
                // 0<=u<1, which means that this is active and moving

                state = eFSState.active;

                txt.enabled = true; // Show the score once more
            }

            // Use Bézier curve to move this to the right point

            Vector2 pos = Utils.Bezier(uC, bezierPts);

            // RectTransform anchors can be used to position UI objects relative

            //  to total size of the screen

            rectTrans.anchorMin = rectTrans.anchorMax = pos;

            if (fontSizes != null && fontSizes.Count > 0)
            {
                // If fontSizes has values in it

                // ...then adjust the fontSize of this GUIText

                int size = Mathf.RoundToInt(Utils.Bezier(uC, fontSizes));

                GetComponent <Text>().fontSize = size;
            }
        }
    }
 public IncompatibleTransitionObservable(IObservable <double> progress, Easing easing, IBrush?from, IBrush?to) : base(progress, easing)
 {
     _from = from;
     _to   = to;
 }
Example #58
0
        public IEnumerator DropPizzaRoutine(Vector2 dropPoint, int delay = 400)
        {
            if (delay > 0)
            {
                yield return(new WaitForMilliSeconds(delay));
            }

            Console.WriteLine($"{this}: droppoint: {dropPoint}");

            //Get pizza game object
            var pizza = _level.GetPizzaFromPool();

            if (pizza == null)
            {
                yield break;
            }

            _level.SetChildIndex(pizza, _level.GetChildren(false).Count);
            pizza.visible = true;
            pizza.SetScaleXY(1, 1);
            var pizzaPos = _stork.Pos; // + _stork.Forward * 35;

            pizza.SetXY(pizzaPos.x, pizzaPos.y);

            var fromX = pizzaPos.x;
            var fromY = pizzaPos.y;

            var toX = dropPoint.x;
            var toY = dropPoint.y;

            int time     = 0;
            int duration = 1800;

            pizza.SetScaleXY(1, 1);

            var fromScaleX = pizza.scaleX;
            var fromScaleY = pizza.scaleY;

            int scaleTime = 0;

            bool hasChangedDepthFlag = false;

            while (time < duration)
            {
                pizza.x = Easing.Ease(Easing.Equation.Linear, time, fromX, toX - fromX, duration);
                pizza.y = Easing.Ease(Easing.Equation.Linear, time, fromY, toY - fromY, duration);

                float scaleX = 0;
                float scaleY = 0;

                if (scaleTime < 400)
                {
                    scaleX = Easing.Ease(Easing.Equation.CubicEaseOut, scaleTime, fromScaleX, 1.5f - fromScaleX,
                                         400);
                    scaleY = Easing.Ease(Easing.Equation.CubicEaseOut, scaleTime, fromScaleY, 1.5f - fromScaleY,
                                         400);
                }
                else
                {
                    scaleX = Easing.Ease(Easing.Equation.CubicEaseIn, scaleTime - 400, 1.5f, 0f - 1.5f, duration - 400);
                    scaleY = Easing.Ease(Easing.Equation.CubicEaseIn, scaleTime - 400, 1.5f, 0f - 1.5f, duration - 400);

                    if (!hasChangedDepthFlag && scaleX < 1)
                    {
                        hasChangedDepthFlag = true;
                        pizza.parent.SetChildIndex(pizza, _lastMarker.Index + 1);
                    }
                }

                pizza.SetScaleXY(scaleX, scaleY);

                time      += Time.deltaTime;
                scaleTime += Time.deltaTime;
                yield return(null);
            }

            ParticleManager.Instance.PlaySmallSmoke(_level, toX, toY, 1500, _lastMarker.Index + 1);
        }
        /// <summary>
        /// Coroutine for tweening rotation.
        /// </summary>
        public static IEnumerator TweenRotationCoroutine(GameObject gameObject, Quaternion targetRotation, float duration, Easing easing, bool destroy, bool isRelative, string cubicBezier)
        {
            float elapsedTime = 0;
            // are we moving in absolute terms
            // or relative to current position
            Quaternion startRotation = gameObject.transform.localRotation;
            Quaternion endRotation;

            if (isRelative)
            {
                // the supplied Quaternion is relative to the original position
                endRotation = startRotation * targetRotation;
            }
            else
            {
                endRotation = targetRotation;
            }

            if (duration < 0.0001f)
            {
                gameObject.transform.localRotation = endRotation;
            }
            else
            {
                while (elapsedTime < duration)
                {
                    float t = elapsedTime / duration;
                    // shift 't' based on the easing function
                    t            = Utils.GetT(t, easing, cubicBezier);
                    elapsedTime += Time.deltaTime;
                    // set the rotation
                    Quaternion interpolatedRotation = Quaternion.Slerp(startRotation, endRotation, t);
                    gameObject.transform.localRotation = interpolatedRotation;
                    yield return(null);
                }
                gameObject.transform.localRotation = endRotation;
            }

            // Destroy if specified
            if (destroy)
            {
                GameObject.Destroy(gameObject);
            }
        }
Example #60
0
        public override IEnumerator Execute(GameObject target, IAction[] actions, int index)
        {
            animpanel = canvasPanel.GetComponent <RectTransform>();

            AnimInPosition = new Vector3(0, 0, 0);

            animStartPosition = animpanel.localPosition;

            AnimOutPositionTop    = new Vector3(0, Screen.height, 0);
            AnimOutPositionBottom = new Vector3(0, -Screen.height, 0);
            AnimOutPositionLeft   = new Vector3(-Screen.width, 0, 0);
            AnimOutPositionRight  = new Vector3(Screen.width, 0, 0);

            float vMoveSpeed = AnimateDuration.GetValue(target);

            if (vMoveSpeed < 0.2f)
            {
                vMoveSpeed = 0.2f;
            }

            float initTime = Time.time;


            switch (this.alignment)
            {
            case ALIGN.Top:
                while (Time.time - initTime < vMoveSpeed)
                {
                    if (animpanel == null)
                    {
                        break;
                    }
                    float t         = (Time.time - initTime) / vMoveSpeed;
                    float easeValue = Easing.GetEase(easing, 0.0f, 1.0f, t);



                    animpanel.localPosition = Vector3.Lerp(
                        animStartPosition,
                        AnimInPosition,
                        easeValue
                        );


                    yield return(null);
                }

                break;

            case ALIGN.Bottom:
                while (Time.time - initTime < vMoveSpeed)
                {
                    if (animpanel == null)
                    {
                        break;
                    }
                    float t         = (Time.time - initTime) / vMoveSpeed;
                    float easeValue = Easing.GetEase(easing, 0.0f, 1.0f, t);

                    animpanel.localPosition = Vector3.Lerp(
                        animStartPosition,
                        AnimInPosition,
                        easeValue
                        );

                    yield return(null);
                }
                break;

            case ALIGN.Left:

                while (Time.time - initTime < vMoveSpeed)
                {
                    if (animpanel == null)
                    {
                        break;
                    }
                    float t         = (Time.time - initTime) / vMoveSpeed;
                    float easeValue = Easing.GetEase(easing, 0.0f, 1.0f, t);

                    animpanel.localPosition = Vector3.Lerp(
                        AnimOutPositionLeft,
                        AnimInPosition,
                        easeValue
                        );

                    yield return(null);
                }

                break;

            case ALIGN.Right:
                while (Time.time - initTime < vMoveSpeed)
                {
                    if (animpanel == null)
                    {
                        break;
                    }
                    float t         = (Time.time - initTime) / vMoveSpeed;
                    float easeValue = Easing.GetEase(easing, 0.0f, 1.0f, t);

                    animpanel.localPosition = Vector3.Lerp(
                        animStartPosition,
                        AnimInPosition,
                        easeValue
                        );

                    yield return(null);
                }

                break;
            }



            yield return(0);
        }