Пример #1
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();
    }
Пример #2
0
 public static ITween <Vector3> tween(this object self, string memberName, Vector3 to, float duration)
 {
     return(PropertyTweens.vector3PropertyTo(self, memberName, to, duration));
 }
Пример #3
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;
            }
        }
    }