Example #1
0
    void OnGUI()
    {
        DemoGUIHelpers.setupGUIButtons();


        GUILayout.Label("Click anywhere to move the cube via a SmoothedVector3");
        GUILayout.Space(30);
        GUILayout.Label("Click the buttons below the slider to use\na SmoothedFloat to change the slider value");

        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Set To Value to 10"))
        {
            _smoothedFloat.setToValue(10f);
        }


        if (GUILayout.Button("Set To Value to -10"))
        {
            _smoothedFloat.setToValue(-10f);
        }

        GUILayout.EndHorizontal();

        GUILayout.HorizontalSlider(_smoothedFloat.value, -10f, 10f, GUILayout.Width(250));


        DemoGUIHelpers.easeTypesGUI();
    }
Example #2
0
    void OnGUI()
    {
        DemoGUIHelpers.setupGUIButtons();
        _duration = DemoGUIHelpers.durationSlider(_duration, 5f);
        DemoGUIHelpers.easeTypesGUI();


        GUILayout.Label("The splines used in this scene are on the\n*DummySpline GameObjects so you can\nhave a look at them.");
        GUILayout.Label("Just select the GameObject and the gizmos\nwill be drawn in the scene view.");
        GUILayout.Space(20);

        if (GUILayout.Button("Figure Eight Spline Tween (relative)"))
        {
            Spline spline;
            if (LoadFromScriptableObject)
            {
                spline = new Spline("figureEight");
            }
            else
            {
                spline = new Spline(FigureEightSplineSettings.Nodes);
            }

            spline.closePath(); // we have to let the spline know it should close itself if using EaseTypes that go negative like Elastic to avoid clamping

            new SplineTween(quad, spline, _duration)
            .setIsRelative()
            .start();
        }


        if (GUILayout.Button("Figure Eight Spline Tween (absolute)"))
        {
            Spline spline;
            if (LoadFromScriptableObject)
            {
                spline = new Spline("figureEight");
            }
            else
            {
                spline = new Spline(FigureEightSplineSettings.Nodes);
            }

            spline.closePath();

            new SplineTween(quad, spline, _duration)
            .start();
        }


        if (GUILayout.Button("Circle Position Tween (relative with PingPong)"))
        {
            Spline spline;
            if (LoadFromScriptableObject)
            {
                spline = new Spline("circle");
            }
            else
            {
                spline = new Spline(CircleSplineSettings.Nodes);
            }
            spline.closePath();

            new SplineTween(quad, spline, _duration)
            .setIsRelative()
            .setLoops(LoopType.PingPong)
            .start();
        }


        if (GUILayout.Button("DemoRoute Tween (relative with PingPong)"))
        {
            Spline spline;
            if (LoadFromScriptableObject)
            {
                spline = new Spline("demoRoute");
            }
            else
            {
                spline = new Spline(DemoRouteSplineSettings.Nodes);
            }
            spline.closePath();

            new SplineTween(quad, spline, _duration)
            .setIsRelative()
            .setLoops(LoopType.PingPong)
            .start();
        }


        if (GUILayout.Button("Runtime Spline (relative with PingPong)"))
        {
            var nodes  = new Vector3[] { new Vector3(0, 0), new Vector3(0, 0), new Vector3(4f, 4f, 4f), new Vector3(-4f, 5f, 6f), new Vector3(-2f, 2f, 0f), new Vector3(0f, 0f) };
            var spline = new Spline(nodes);
            spline.closePath();

            // setup the tween
            new SplineTween(quad, spline, _duration)
            .setIsRelative()
            .setLoops(LoopType.PingPong)
            .start();
        }
    }
Example #3
0
    void OnGUI()
    {
        DemoGUIHelpers.setupGUIButtons();
        _duration = DemoGUIHelpers.durationSlider(_duration);


        if (_springTween == null)
        {
            if (GUILayout.Button("Custom Property Tween (wackyDoodleWidth)"))
            {
                PropertyTweens.floatPropertyTo(this, "wackyDoodleWidth", 1f, 6f, _duration)
                .setLoops(LoopType.PingPong)
                .start();
            }


            if (GUILayout.Button("Position via Property Tween"))
            {
                PropertyTweens.vector3PropertyTo(cube, "position", cube.position, new Vector3(5f, 5f, 5f), _duration)
                .setLoops(LoopType.PingPong)
                .start();
            }



            if (GUILayout.Button("Tween Party (color, position, scale and rotation)"))
            {
                var party = new TweenParty(_duration);
                party.addTween(cube.GetComponent <Renderer>().material.ZKcolorTo(Color.black))
                .addTween(cube.ZKpositionTo(new Vector3(7f, 4f)))
                .addTween(cube.ZKlocalScaleTo(new Vector3(1f, 4f)))
                .addTween(cube.ZKrotationTo(Quaternion.AngleAxis(180f, Vector3.one)))
                .setLoops(LoopType.PingPong)
                .start();
            }


            if (GUILayout.Button("Tween Chain (same props as the party)"))
            {
                var chain = new TweenChain();
                chain.appendTween(cube.GetComponent <Renderer>().material.ZKcolorTo(Color.black, _duration).setLoops(LoopType.PingPong))
                .appendTween(cube.ZKpositionTo(new Vector3(7f, 4f), _duration).setLoops(LoopType.PingPong))
                .appendTween(cube.ZKlocalScaleTo(new Vector3(1f, 4f), _duration).setLoops(LoopType.PingPong))
                .appendTween(cube.ZKrotationTo(Quaternion.AngleAxis(180f, Vector3.one), _duration).setLoops(LoopType.PingPong))
                .start();
            }


            if (GUILayout.Button("Chaining Tweens Directly (same props as the party)"))
            {
                cube.GetComponent <Renderer>().material.ZKcolorTo(Color.black).setLoops(LoopType.PingPong)
                .setNextTween
                (
                    cube.ZKpositionTo(new Vector3(7f, 4f)).setLoops(LoopType.PingPong).setNextTween
                    (
                        cube.ZKlocalScaleTo(new Vector3(1f, 4f)).setLoops(LoopType.PingPong).setNextTween
                        (
                            cube.ZKrotationTo(Quaternion.AngleAxis(180f, Vector3.one)).setLoops(LoopType.PingPong)
                        )
                    )
                )
                .start();
            }


            if (GUILayout.Button("Start Spring Position"))
            {
                _springTween = new TransformSpringTween(cube, TransformTargetType.Position, cube.position);
            }


            if (GUILayout.Button("Start Spring Scale"))
            {
                _springTween = new TransformSpringTween(cube, TransformTargetType.LocalScale, cube.localScale);
            }
        }
        else
        {
            GUILayout.Label("While the spring tween is active the cube will spring to\n" +
                            "whichever location you click or scale x/y to that location\n" +
                            "if you chose a scale spring. The sliders below let you tweak\n" +
                            "the spring contants.\n\n" +
                            "For the scale tween, try clicking places on a horizontal or vertical\n" +
                            "axis to get a feel for how it works.");

            springSliders();

            if (GUILayout.Button("Stop Spring"))
            {
                _springTween.stop();
                _springTween    = null;
                cube.position   = new Vector3(-1f, -2f);
                cube.localScale = Vector3.one;
            }
        }


        DemoGUIHelpers.easeTypesGUI();
    }
Example #4
0
    void OnGUI()
    {
        DemoGUIHelpers.setupGUIButtons();


        if (_springTween == null)
        {
            _duration = DemoGUIHelpers.durationSlider(_duration);


            if (GUILayout.Button("Custom Property Tween (wackyDoodleWidth)"))
            {
                PropertyTweens.floatPropertyTo(this, "wackyDoodleWidth", 6f, _duration)
                .setFrom(1f)
                .setLoops(LoopType.PingPong)
                .start();
            }


            if (GUILayout.Button("Position via Property Tween"))
            {
                PropertyTweens.vector3PropertyTo(cube, "position", new Vector3(5f, 5f, 5f), _duration)
                .setLoops(LoopType.PingPong)
                .start();
            }



            if (GUILayout.Button("Tween Party (color, position, scale and rotation)"))
            {
                var party = new TweenParty(_duration);
                party.addTween(cube.GetComponent <Renderer>().material.ZKcolorTo(Color.black))
                .addTween(cube.ZKpositionTo(new Vector3(7f, 4f)))
                .addTween(cube.ZKlocalScaleTo(new Vector3(1f, 4f)))
                .addTween(cube.ZKrotationTo(Quaternion.AngleAxis(180f, Vector3.one)))
                .setLoops(LoopType.PingPong)
                .start();
            }


            if (GUILayout.Button("Tween Chain (same props as the party)"))
            {
                var chain = new TweenChain();
                chain.appendTween(cube.GetComponent <Renderer>().material.ZKcolorTo(Color.black, _duration).setLoops(LoopType.PingPong))
                .appendTween(cube.ZKpositionTo(new Vector3(7f, 4f), _duration).setLoops(LoopType.PingPong))
                .appendTween(cube.ZKlocalScaleTo(new Vector3(1f, 4f), _duration).setLoops(LoopType.PingPong))
                .appendTween(cube.ZKrotationTo(Quaternion.AngleAxis(180f, Vector3.one), _duration).setLoops(LoopType.PingPong))
                .start();
            }


            if (GUILayout.Button("Chaining Tweens Directly (same props as the party)"))
            {
                cube.GetComponent <Renderer>().material.ZKcolorTo(Color.black, _duration).setLoops(LoopType.PingPong)
                .setNextTween
                (
                    cube.ZKpositionTo(new Vector3(7f, 4f), _duration).setLoops(LoopType.PingPong).setNextTween
                    (
                        cube.ZKlocalScaleTo(new Vector3(1f, 4f), _duration).setLoops(LoopType.PingPong).setNextTween
                        (
                            cube.ZKrotationTo(Quaternion.AngleAxis(180f, Vector3.one), _duration).setLoops(LoopType.PingPong)
                        )
                    )
                )
                .start();
            }


            GUILayout.Space(10);
            if (GUILayout.Button("Start Spring Position"))
            {
                _springTween = new TransformSpringTween(cube, TransformTargetType.Position, cube.position);
            }


            if (GUILayout.Button("Start Spring Position (overdamped)"))
            {
                _springTween = new TransformSpringTween(cube, TransformTargetType.Position, cube.position);
                _springTween.dampingRatio     = 1.5f;
                _springTween.angularFrequency = 20f;
            }


            if (GUILayout.Button("Start Spring Scale"))
            {
                _springTween = new TransformSpringTween(cube, TransformTargetType.LocalScale, cube.localScale);
            }
            GUILayout.Space(10);


            if (GUILayout.Button("Run Action Every 1s After 2s Delay"))
            {
                ActionTask.every(2f, 1f, this, task =>
                {
                    // by using the context we get away with not allocating when passing this Action around!
                    (task.context as ZestKitOtherGoodies).methodCalledForDemonstrationPurposes();
                });
            }


            if (GUILayout.Button("ActionTask Interoperability"))
            {
                Debug.Log("The Story: An ActionTask with a 2s delay will be created with a continueWith ActionTask appended to it that will tick every 0.3s for 2s. The original ActionTask will have a waitFor called that is an ActionTask with a 1s delay. Follow?");
                Debug.Log("--- current time: " + Time.time);

                ActionTask.afterDelay(2f, this, task =>
                {
                    Debug.Log("--- root task ticked: " + Time.time);
                }).continueWith
                (
                    ActionTask.create(this, task =>
                {
                    Debug.Log("+++ continueWith task elapsed time: " + task.elapsedTime);
                    if (task.elapsedTime > 2f)
                    {
                        task.stop();
                    }
                })
                    .setDelay(1f)
                    .setRepeats(0.3f)
                ).waitFor
                (
                    ActionTask.afterDelay(1f, this, task =>
                {
                    Debug.Log("--- waitFor ticked: " + Time.time);
                })
                );
            }

            DemoGUIHelpers.easeTypesGUI();
        }
        else
        {
            GUILayout.Label("While the spring tween is active the cube will spring to\n" +
                            "whichever location you click or scale x/y to that location\n" +
                            "if you chose a scale spring. The sliders below let you tweak\n" +
                            "the spring contants.\n\n" +
                            "For the scale tween, try clicking places on a horizontal or vertical\n" +
                            "axis to get a feel for how it works.");

            springSliders();

            var prefix        = _springTween.targetType == TransformTargetType.Position ? "Spring position to:" : "Spring scale to:";
            var mousePosWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var labelText     = string.Format("{0}\nx: {1:F1}\ny: {2:F1}", prefix, mousePosWorld.x, mousePosWorld.y);
            GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y - 50f, 130f, 50f), labelText);


            if (GUILayout.Button("Stop Spring"))
            {
                _springTween.stop();
                _springTween    = null;
                cube.position   = new Vector3(-1f, -2f);
                cube.localScale = Vector3.one;
            }
        }
    }
Example #5
0
    void OnGUI()
    {
        DemoGUIHelpers.setupGUIButtons();
        _duration = DemoGUIHelpers.durationSlider(_duration);


        if (GUILayout.Button("Position Tween with 2 PingPong Loops"))
        {
            cube.ZKpositionTo(new Vector3(9f, 5f), _duration)
            .setLoops(LoopType.PingPong, 2)
            .setLoopCompletionHandler(tw => Debug.Log("Loop complete"))
            .setCompletionHandler(tw => Debug.Log("Tween complete"))
            .start();
        }


        if (GUILayout.Button("Relative Position Tween"))
        {
            cube.ZKpositionTo(new Vector3(1f, 0f), _duration)
            .setIsRelative()
            .start();
        }


        if (GUILayout.Button("AnimationCurve for Easing Scale"))
        {
            cube.ZKlocalScaleTo(new Vector3(3f, 3f, 3f), _duration)
            .setAnimationCurve(curve)
            .start();
        }


        if (GUILayout.Button("Scale back to 1"))
        {
            cube.ZKlocalScaleTo(new Vector3(1f, 1f, 1f), _duration)
            .start();
        }


        if (GUILayout.Button("Punch Scale to 3"))
        {
            cube.ZKlocalScaleTo(new Vector3(3f, 3f, 3f), _duration)
            .setEaseType(EaseType.Punch)
            .start();
        }


        if (GUILayout.Button("Rotation to 270, 0, 0"))
        {
            cube.ZKlocalEulersTo(new Vector3(270f, 0f), _duration)
            .start();
        }


        if (GUILayout.Button("Rotation to 310, 90 -> localScale"))
        {
            cube.ZKlocalEulersTo(new Vector3(310f, 90f), _duration)
            .setNextTween(cube.ZKlocalScaleTo(new Vector3(2f, 4f, 2f)).setLoops(LoopType.PingPong))
            .start();
        }


        if (GUILayout.Button("Rotation by 0, 720, 360 (relative tween)"))
        {
            cube.ZKlocalEulersTo(new Vector3(0f, 720f, 360f), _duration)
            .setIsRelative()
            .start();
        }


        if (GUILayout.Button("Material Color to Yellow with PingPong Loop"))
        {
            cube.GetComponent <Renderer>().material.ZKcolorTo(Color.yellow, _duration)
            .setLoops(LoopType.PingPong)
            .start();
        }


        if (GUILayout.Button("RectTransform Panel Position Tween"))
        {
            panel.ZKanchoredPositionTo(new Vector2(-Screen.width * 0.5f, Screen.height * 0.5f), _duration)
            .setLoops(LoopType.PingPong)
            .start();
        }


        if (GUILayout.Button("RectTransform Button Position (relative tweens)"))
        {
            var leftButton  = panel.GetChild(0) as RectTransform;
            var rightButton = panel.GetChild(1) as RectTransform;

            leftButton.ZKanchoredPositionTo(new Vector2(0f, panel.rect.height * 0.6f), _duration)
            .setIsRelative()
            .setLoops(LoopType.PingPong)
            .start();

            rightButton.ZKanchoredPositionTo(new Vector2(0f, panel.rect.height * 0.6f), _duration)
            .setIsRelative()
            .setLoops(LoopType.PingPong)
            .setDelay(_duration * 0.5f)
            .start();
        }


        if (GUILayout.Button("Camera Shake"))
        {
            new CameraShakeTween(Camera.main).start();
        }

        DemoGUIHelpers.easeTypesGUI();
    }