delayedCall() public static méthode

public static delayedCall ( GameObject gameObject, float delayTime, Action callback ) : LTDescr,
gameObject GameObject
delayTime float
callback Action
Résultat LTDescr,
Exemple #1
0
        private void Start()
        {
            //          Time.timeScale = 0.25f;

            LeanTest.timeout  = 46f;
            LeanTest.expected = 62;

            LeanTween.init(1300);

            // add a listener
            LeanTween.addListener(cube1, 0, eventGameObjectCalled);

            LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING");

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING");

            LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() =>
            {
                LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME");
            });

            // dispatch event that is received
            LeanTween.dispatchEvent(0);
            LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED");

            // do not remove listener
            LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false,
                            "EVENT GAMEOBJECT NOT REMOVED");
            // remove listener
            LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED");

            // add a listener
            LeanTween.addListener(1, eventGeneralCalled);

            // dispatch event that is received
            LeanTween.dispatchEvent(1);
            LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED");

            // remove listener
            LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED");

            lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id;
            LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f);

            LeanTween.reset();

            // Queue up a bunch of tweens, cancel some of them but expect the remainder to finish
            var cubes    = new GameObject[99];
            var tweenIds = new int[cubes.Length];

            for (var i = 0; i < cubes.Length; i++)
            {
                var c = cubeNamed("cancel" + i);
                tweenIds[i] = LeanTween.moveX(c, 100f, 1f).id;
                cubes[i]    = c;
            }

            var onCompleteCount = 0;

            LeanTween.delayedCall(cubes[0], 0.2f, () =>
            {
                for (var i = 0; i < cubes.Length; i++)
                {
                    if (i % 3 == 0)
                    {
                        LeanTween.cancel(cubes[i]);
                    }
                    else if (i % 3 == 1)
                    {
                        LeanTween.cancel(tweenIds[i]);
                    }
                    else if (i % 3 == 2)
                    {
                        var descr = LeanTween.descr(tweenIds[i]);
                        //                      Debug.Log("descr:"+descr);
                        descr.setOnComplete(() =>
                        {
                            onCompleteCount++;
                            //                          Debug.Log("onCompleteCount:"+onCompleteCount);
                            if (onCompleteCount >= 33)
                            {
                                LeanTest.expect(true, "CANCELS DO NOT EFFECT FINISHING");
                            }
                        });
                    }
                }
            });

            Vector3[] splineArr =
            {
                new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f),
                new Vector3(30f, 0f, 0f)
            };
            var cr = new LTSpline(splineArr);

            cr.place(cube4.transform, 0.5f);
            LeanTest.expect(Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f,
                            "SPLINE POSITIONING AT HALFWAY",
                            "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)");
            LeanTween.color(cube4, Color.green, 0.01f);

            //          Debug.Log("Point 2:"+cr.ratioAtPoint(splineArr[2]));

            // OnStart Speed Test for ignoreTimeScale vs normal timeScale

            var cubeDest    = cubeNamed("cubeDest");
            var cubeDestEnd = new Vector3(100f, 20f, 0f);

            LeanTween.move(cubeDest, cubeDestEnd, 0.7f);

            var cubeToTrans = cubeNamed("cubeToTrans");

            LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() =>
            {
                LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS");
            });

            var cubeDestroy = cubeNamed("cubeDestroy");

            LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true);
            LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() =>
            {
                LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED");
            });

            var cubeSpline = cubeNamed("cubeSpline");

            LeanTween
            .moveSpline(cubeSpline,
                        new[]
            {
                new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f),
                new Vector3(1f, 0f, 1f)
            }, 0.1f).setOnComplete(() =>
            {
                LeanTest.expect(
                    Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f,
                    "SPLINE WITH TWO POINTS SUCCEEDS");
            });

            // This test works when it is positioned last in the test queue (probably worth fixing when you have time)
            var jumpCube = cubeNamed("jumpTime");

            jumpCube.transform.position    = new Vector3(100f, 0f, 0f);
            jumpCube.transform.localScale *= 100f;
            var jumpTimeId = LeanTween.moveX(jumpCube, 200f, 1f).id;

            LeanTween.delayedCall(gameObject, 0.2f, () =>
            {
                var d       = LeanTween.descr(jumpTimeId);
                var beforeX = jumpCube.transform.position.x;
                d.setTime(0.5f);
                LeanTween.delayedCall(0.0f, () => { }).setOnStart(() =>
                {
                    var diffAmt =
                        1f; // This variable is dependent on a good frame-rate because it evalutes at the next Update
                    beforeX += Time.deltaTime * 100f * 2f;
                    LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < diffAmt,
                                    "CHANGING TIME DOESN'T JUMP AHEAD",
                                    "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX) + " beforeX:" + beforeX +
                                    " now:" + jumpCube.transform.position.x + " dt:" + Time.deltaTime);
                });
            });

            // Tween with time of zero is needs to be set to it's final value
            var zeroCube = cubeNamed("zeroCube");

            LeanTween.moveX(zeroCube, 10f, 0f).setOnComplete(() =>
            {
                LeanTest.expect(zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY",
                                "final x:" + zeroCube.transform.position.x);
            });

            // Scale, and OnStart
            var cubeScale = cubeNamed("cubeScale");

            LeanTween.scale(cubeScale, new Vector3(5f, 5f, 5f), 0.01f)
            .setOnStart(() => { LeanTest.expect(true, "ON START WAS CALLED"); }).setOnComplete(() =>
            {
                LeanTest.expect(cubeScale.transform.localScale.z == 5f, "SCALE",
                                "expected scale z:" + 5f + " returned:" + cubeScale.transform.localScale.z);
            });

            // Rotate
            var cubeRotate = cubeNamed("cubeRotate");

            LeanTween.rotate(cubeRotate, new Vector3(0f, 180f, 0f), 0.02f).setOnComplete(() =>
            {
                LeanTest.expect(cubeRotate.transform.eulerAngles.y == 180f, "ROTATE",
                                "expected rotate y:" + 180f + " returned:" + cubeRotate.transform.eulerAngles.y);
            });

            // RotateAround
            var cubeRotateA = cubeNamed("cubeRotateA");

            LeanTween.rotateAround(cubeRotateA, Vector3.forward, 90f, 0.3f).setOnComplete(() =>
            {
                LeanTest.expect(cubeRotateA.transform.eulerAngles.z == 90f, "ROTATE AROUND",
                                "expected rotate z:" + 90f + " returned:" + cubeRotateA.transform.eulerAngles.z);
            });

            // RotateAround 360
            var cubeRotateB = cubeNamed("cubeRotateB");

            cubeRotateB.transform.position = new Vector3(200f, 10f, 8f);
            LeanTween.rotateAround(cubeRotateB, Vector3.forward, 360f, 0.3f).setPoint(new Vector3(5f, 3f, 2f))
            .setOnComplete(() =>
            {
                LeanTest.expect(
                    cubeRotateB.transform.position.ToString() == new Vector3(200f, 10f, 8f).ToString(),
                    "ROTATE AROUND 360",
                    "expected rotate pos:" + new Vector3(200f, 10f, 8f) + " returned:" +
                    cubeRotateB.transform.position);
            });

            // Alpha, onUpdate with passing value, onComplete value
            LeanTween.alpha(cubeAlpha1, 0.5f, 0.1f).setOnUpdate(val => { LeanTest.expect(val != 0f, "ON UPDATE VAL"); })
            .setOnCompleteParam("Hi!").setOnComplete(completeObj =>
            {
                LeanTest.expect((string)completeObj == "Hi!", "ONCOMPLETE OBJECT");
                LeanTest.expect(cubeAlpha1.GetComponent <Renderer>().material.color.a == 0.5f, "ALPHA");
            });
            // Color
            var onStartTime = -1f;

            LeanTween.color(cubeAlpha2, Color.cyan, 0.3f).setOnComplete(() =>
            {
                LeanTest.expect(cubeAlpha2.GetComponent <Renderer>().material.color == Color.cyan, "COLOR");
                LeanTest.expect(onStartTime >= 0f && onStartTime < Time.time, "ON START",
                                "onStartTime:" + onStartTime + " time:" + Time.time);
            }).setOnStart(() => { onStartTime = Time.time; });
            // moveLocalY (make sure uses y values)
            var beforePos = cubeAlpha1.transform.position;

            LeanTween.moveY(cubeAlpha1, 3f, 0.2f).setOnComplete(() =>
            {
                LeanTest.expect(
                    cubeAlpha1.transform.position.x == beforePos.x &&
                    cubeAlpha1.transform.position.z == beforePos.z, "MOVE Y");
            });

            var beforePos2 = cubeAlpha2.transform.localPosition;

            LeanTween.moveLocalZ(cubeAlpha2, 12f, 0.2f).setOnComplete(() =>
            {
                LeanTest.expect(
                    cubeAlpha2.transform.localPosition.x == beforePos2.x &&
                    cubeAlpha2.transform.localPosition.y == beforePos2.y, "MOVE LOCAL Z",
                    "ax:" + cubeAlpha2.transform.localPosition.x + " bx:" + beforePos.x + " ay:" +
                    cubeAlpha2.transform.localPosition.y + " by:" + beforePos2.y);
            });

            var audioClip =
                LeanAudio.createAudio(new AnimationCurve(new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f)),
                                      new AnimationCurve(new Keyframe(0f, 0.001f, 0f, 0f), new Keyframe(1f, 0.001f, 0f, 0f)),
                                      LeanAudio.options());

            LeanTween.delayedSound(gameObject, audioClip, new Vector3(0f, 0f, 0f), 0.1f).setDelay(0.2f)
            .setOnComplete(() => { LeanTest.expect(Time.time > 0, "DELAYED SOUND"); });

            // Easing Methods
            var totalEasingCheck        = 0;
            var totalEasingCheckSuccess = 0;

            for (var j = 0; j < 2; j++)
            {
                var isCheckingFrom       = j == 1;
                var totalTweenTypeLength = (int)LeanTweenType.easeShake;
                for (var i = (int)LeanTweenType.notUsed; i < totalTweenTypeLength; i++)
                {
                    var easeType = (LeanTweenType)i;
                    var cube     = cubeNamed("cube" + easeType);
                    var descr    = LeanTween.moveLocalX(cube, 5, 0.1f).setOnComplete(obj =>
                    {
                        var cubeIn = obj as GameObject;
                        totalEasingCheck++;
                        if (cubeIn.transform.position.x == 5f)
                        {
                            totalEasingCheckSuccess++;
                        }
                        if (totalEasingCheck == 2 * totalTweenTypeLength)
                        {
                            LeanTest.expect(totalEasingCheck == totalEasingCheckSuccess, "EASING TYPES");
                        }
                    }).setOnCompleteParam(cube);

                    if (isCheckingFrom)
                    {
                        descr.setFrom(-5f);
                    }
                }
            }

            // value2
            var value2UpdateCalled = false;

            LeanTween.value(gameObject, new Vector2(0, 0), new Vector2(256, 96), 0.1f).setOnUpdate((Vector2 value) =>
            {
                value2UpdateCalled = true;
            });
            LeanTween.delayedCall(0.2f, () => { LeanTest.expect(value2UpdateCalled, "VALUE2 UPDATE"); });

            // check descr
            //          LTDescr descr2 = LeanTween.descr( descrId );
            //          LeanTest.expect(descr2 == null,"DESCRIPTION STARTS AS NULL");

            StartCoroutine(timeBasedTesting());
        }
        // Builds the tween structure with all the appropriate values.
        // Cancels all previous tweens to keep a clean tween list.
        // The overallDelay variable is used to set a delay
        // to the entire group.
        // <param name="overallDelay">Overall delay.</param>
        public string buildAllTweens(bool generateCode, GameObject overrideGameObject = null)
        {
            if (generateCode)
            {
                codeBuild = new System.Text.StringBuilder(1024);
                tabs      = "";
                if (repeat)
                {
                    tabs += "\t";
                }
            }
            else
            {
                LeanTween.cancel(gameObject);
            }

            string preTabs       = tabs;
            float  lastTweenTime = 0.0f;
            int    i             = 0;

            foreach (LeanTweenGroup group in groupList)
            {
                bool wrapCode = (group.repeat && group.itemList.Count > 0) || group.delay > 0f;
                if (generateCode)
                {
                    if (i != 0)
                    {
                        codeBuild.Append("\n");
                    }
                    codeBuild.Append(tabs + "// " + group.name + " Group\n");
                }
                if (generateCode && wrapCode)
                {
                    codeBuild.Append(tabs + "LeanTween.delayedCall(gameObject, " + group.endTime + "f, ()=>{\n");
                    tabs += "\t";
                }

                if (generateCode)
                {
                    group.setGenerateCode();
                }
                group.repeatIter         = 0;
                group.overrideGameObject = overrideGameObject;
                buildGroup(group);

                tabs = preTabs;
                if (generateCode && wrapCode)
                {
                    if (group.delay > 0f)
                    {
                        codeBuild.Append(".setDelay(" + group.delay + "f)");
                    }
                    codeBuild.Append(tabs + "}).setOnCompleteOnStart(true)");
                    if (group.repeat)
                    {
                        codeBuild.Append(".setRepeat(" + (group.repeatCount < 0 ? -1 : group.repeatCount - 1) + ")");
                    }
                    codeBuild.Append(";\n");
                }

                if (group.endTime > lastTweenTime)
                {
                    lastTweenTime = group.endTime;
                }
                i++;
            }

            if (repeat)
            {
                if (generateCode)
                {
                    codeBuild.Insert(0, "LeanTween.delayedCall(gameObject, " + lastTweenTime + "f, ()=>{\n");
                    codeBuild.Append("}).setRepeat(" + repeatIter + ").setOnCompleteOnStart(true);\n");
                }
                else
                {
                    repeatIter = 0;
                    LeanTween.delayedCall(gameObject, lastTweenTime, buildAllTweensAgain);
                }
            }
            if (generateCode)
            {
                return(codeBuild.ToString());
            }
            else
            {
                return(null);
            }
        }
 public static LTDescr LTDelayedCall(this Transform self, float delayTime, Action <object> callback)
 {
     return(LeanTween.delayedCall(self.get_gameObject(), delayTime, callback));
 }
Exemple #4
0
 public void Desactivate()
 {
     LeanTween.alphaCanvas(GetComponent <CanvasGroup>(), 0, 0.1F);
     LeanTween.delayedCall(gameObject, 0.15F, () => gameObject.SetActive(false));
 }
Exemple #5
0
 private void ResetKillTimer()
 {
     LeanTween.cancel(killId);
     killId = LeanTween.delayedCall(MaxLifeTime, () => BlowUp()).id;
 }
Exemple #6
0
        void Start()
        {
            LeanTest.timeout  = 46f;
            LeanTest.expected = 36;

            LeanTween.init(15 + 1200);
            // add a listener
            LeanTween.addListener(cube1, 0, eventGameObjectCalled);

            LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING");

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING");

            LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() => {
                LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME");
            });

            // dispatch event that is received
            LeanTween.dispatchEvent(0);
            LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED");

            // do not remove listener
            LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false, "EVENT GAMEOBJECT NOT REMOVED");
            // remove listener
            LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED");

            // add a listener
            LeanTween.addListener(1, eventGeneralCalled);

            // dispatch event that is received
            LeanTween.dispatchEvent(1);
            LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED");

            // remove listener
            LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED");

            lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id;
            LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f);

            LeanTween.reset();

            Vector3[] splineArr = new Vector3[] { new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f), new Vector3(30f, 0f, 0f) };
            LTSpline  cr        = new LTSpline(splineArr);

            cr.place(cube4.transform, 0.5f);
            LeanTest.expect((Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)");
            LeanTween.color(cube4, Color.green, 0.01f);

            Debug.Log("Point 2:" + cr.ratioAtPoint(splineArr[2]));

            // OnStart Speed Test for ignoreTimeScale vs normal timeScale
            GameObject cube = Instantiate(boxNoCollider) as GameObject;

            cube.name = "normalTimeScale";
            // float timeElapsedNormal = Time.time;
            LeanTween.moveX(cube, 12f, 1f).setIgnoreTimeScale(false).setOnComplete(() => {
                timeElapsedNormalTimeScale = Time.time;
            });

            LTDescr[] descr = LeanTween.descriptions(cube);
            LeanTest.expect(descr.Length >= 0 && descr[0].to.x == 12f, "WE CAN RETRIEVE A DESCRIPTION");

            cube      = Instantiate(boxNoCollider) as GameObject;
            cube.name = "ignoreTimeScale";
            LeanTween.moveX(cube, 5f, 1f).setIgnoreTimeScale(true).setOnComplete(() => {
                timeElapsedIgnoreTimeScale = Time.time;
            });

            GameObject cubeDest = Instantiate(boxNoCollider) as GameObject;

            cubeDest.name = "cubeDest";
            Vector3 cubeDestEnd = new Vector3(100f, 20f, 0f);

            LeanTween.move(cubeDest, cubeDestEnd, 0.7f);
            GameObject cubeToTrans = Instantiate(boxNoCollider) as GameObject;

            cubeToTrans.name = "cubeToTrans";

            LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() => {
                LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS");
            });

            GameObject cubeDestroy = Instantiate(boxNoCollider) as GameObject;

            cubeDestroy.name = "cubeDestroy";
            LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true);
            LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() => {
                LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED");
            });

            GameObject cubeSpline = Instantiate(boxNoCollider) as GameObject;

            cubeSpline.name = "cubeSpline";
            LeanTween.moveSpline(cubeSpline, new Vector3[] { new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 1f) }, 0.1f).setOnComplete(() => {
                LeanTest.expect(Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS");
            });

            // This test works when it is positioned last in the test queue (probably worth fixing when you have time)
            GameObject jumpCube = Instantiate(boxNoCollider) as GameObject;

            jumpCube.name = "jumpTime";
            int jumpTimeId = LeanTween.moveX(jumpCube, 1f, 1f).id;

            LeanTween.delayedCall(jumpCube, 0.2f, () => {
                LTDescr d     = LeanTween.descr(jumpTimeId);
                float beforeX = jumpCube.transform.position.x;
                d.setTime(0.5f);
                LeanTween.delayedCall(0.01f, () => { }).setOnStart(() => {
                    LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < 0.01f, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX));
                });
            });

            // Tween with time of zero is needs to be set to it's final value
            GameObject zeroCube = Instantiate(boxNoCollider) as GameObject;

            zeroCube.name = "zeroCube";
            LeanTween.moveX(zeroCube, 10f, 0f).setOnComplete(() => {
                LeanTest.expect(zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY", "final x:" + zeroCube.transform.position.x);
            });

            StartCoroutine(timeBasedTesting());
        }
Exemple #7
0
        public static void Play(string clip, float delay)
        {
            var g = instance.GetGroup(clip);

            LeanTween.delayedCall(delay, g.Play);
        }
 public void Play()
 {
     SoundBase.Instance.GetComponent <AudioSource> ().PlayOneShot(SoundBase.Instance.click);
     LeanTween.delayedCall(1, () => SceneManager.LoadScene("game"));
 }
Exemple #9
0
//	void SpawnCoins(){
//		GameObject root = new GameObject("coinRoot");
//		root.transform.position = shop.bank.bankPosRaw;
//		root.transform.SetParent (transform.root);
//		int count = Mathf.FloorToInt(profile.price / 500);
//		for (int i = 0; i < count; i++) {
//			GameObject go = Overlay.instance.CreateUIObj(coin, shop.bank.bankPosRaw);
//			go.transform.position = shop.bank.bankPosRaw + (Vector3) Random.insideUnitCircle * 20;
//			go.transform.SetParent(root.transform);
//		}
//
//
//		Vector3 pos = priceTag.transform.position;
//		Debug.Log("Moving to "+ pos);
//
//		float t = .5f;
//		LeanTween.move(root, pos, t).setEase(LeanTweenType.easeInCubic);
//		Destroy(root, t + 0.01f);
//	}

    void SpawnCoins(bool re = true)
    {
        if (shop.bank.coinExplodeSound != null)
        {
            LeanAudio.play(shop.bank.coinExplodeSound);
        }

        GameObject root = new GameObject("coinRoot");


        root.transform.position = shop.bank.bankPosRaw;
        root.transform.SetParent(transform.root);

        int   count     = Mathf.FloorToInt(Mathf.Sqrt(profile.price) / 3);
        float maxRadius = 190f;
        float midPoint  = 150f;

        if ((float)Screen.width / Screen.height < 0.5f)
        {
            maxRadius *= 2;
            midPoint  *= 2;
        }
        float t = .6f;

        for (int i = 0; i < count; i++)
        {
            Vector3 pek = InsideSemicircle().normalized *Random.Range(40f, maxRadius);
            //Debug.Log (pek);
            GameObject o = Overlay.instance.CreateUIObj(coin, shop.bank.bankPosRaw);
            o.name += i;

            o.transform.SetParent(root.transform);



            Vector3 pos = priceTag.transform.position;

            float scaleFactor = 0.55f;

            if (SystemInfo.deviceModel.Contains("iPad"))
            {
                scaleFactor = 1.1f;
            }

            LeanTween.scale(o, Vector3.one * scaleFactor, t / 3).setEase(LeanTweenType.easeOutCubic);
            LeanTween.move(o, shop.bank.bankPosRaw + Vector3.down * midPoint + pek, t / 2 + Random.Range(-0.1f, 0.1f)).setEase(LeanTweenType.easeOutCubic).setOnComplete(
                () => {
                LeanTween.move(o, pos, t).setEase(LeanTweenType.easeInCubic);
                LeanTween.scale(o, Vector3.one * 0.2f, t).setEase(LeanTweenType.easeInCubic).setOnComplete(() => {
                    o.SetActive(false);
                });
            }
                );
        }
        //Adjust for iphoneX
        if ((float)Screen.width / Screen.height < 0.5f)
        {
            root.transform.localScale = Vector3.one * 3.33f;
        }
        Destroy(root, t * 1.5f + 0.1f);
        LeanTween.delayedCall(t * 1.5f + 0.1f, () => {
            isAnimating         = false;
            profile.isPurchased = true;
            shop.Save();
            UpdateStatus();
            LeanAudio.play(shop.bank.checkinSound);
            scaleTween = LeanTween.scale(gameObject, Vector3.one * 1.1f, 0.08f).setEase(LeanTweenType.easeOutCubic).setOnComplete(() => {
                scaleTween = LeanTween.scale(gameObject, Vector3.one, 0.15f).setEase(LeanTweenType.easeInOutCubic);
            });
        });
    }
Exemple #10
0
    void Update()
    {
        if (status == Status.Disabled)
        {
            return;
        }
        if (status != Status.Firing)
        {
            weapon.HaltFire();
        }
        switch (status)
        {
        case Status.Hidden:
            if (retargetCurrentTime >= retargetTime)
            {
                if (CanSeePlayer())
                {
                    Deploy();
                }
                retargetCurrentTime -= retargetTime;
            }
            else
            {
                retargetCurrentTime += Time.deltaTime;
            }
            break;

        case Status.Deployed:
            if (retargetCurrentTime >= retargetTime)
            {
                if (CanSeePlayer())
                {
                    status = Status.Firing;
                }
                retargetCurrentTime -= retargetTime;
            }
            else
            {
                retargetCurrentTime += Time.deltaTime;
            }
            break;

        case Status.Firing:
            weapon.transform.LookAt(PlayerController.Instance.Position(), Vector3.up);
            weapon.Fire();
            if (retargetCurrentTime >= retargetTime)
            {
                if (!CanSeePlayer())
                {
                    status = Status.Deployed;
                }
                retargetCurrentTime -= retargetTime;
            }
            else
            {
                retargetCurrentTime += Time.deltaTime;
            }
            break;

        case Status.Shielding:
            if (shieldingId == -1)    //shield.IsOn() && !shield.IsEngaging())
            {
                shieldingId = LeanTween.delayedCall(1f, () => StopShielding()).id;
            }
            break;
        }
    }
Exemple #11
0
 public virtual void MoveAndRotateToPositionWithDelay(Vector3[] path, Vector3 eulerAngles, float delay = 0f, float time = 1.5f)
 {
     LeanTween.delayedCall(delay, () => { MoveAndRotateToPosition(path, eulerAngles, time); });
 }
Exemple #12
0
    public void fadeimage(int image)

    {
        background.CrossFadeColor(new Color(1, 1, 1, 0), time, false, true);
        LeanTween.delayedCall(gameObject, 1.0f, updateimage).setOnCompleteParam(image);
    }
Exemple #13
0
 private void Awake()
 {
     LeanTween.delayedCall(gameObject, 5.0f, () => {
         Destroy(gameObject);
     });
 }
Exemple #14
0
        void Start()
        {
//			Time.timeScale = 0.25f;

            LeanTest.timeout  = 46f;
            LeanTest.expected = 55;

            LeanTween.init(15 + 1200);
            // add a listener
            LeanTween.addListener(cube1, 0, eventGameObjectCalled);

            LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING");

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING");

            LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() => {
                LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME");
            });

            // dispatch event that is received
            LeanTween.dispatchEvent(0);
            LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED");

            // do not remove listener
            LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false, "EVENT GAMEOBJECT NOT REMOVED");
            // remove listener
            LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED");

            // add a listener
            LeanTween.addListener(1, eventGeneralCalled);

            // dispatch event that is received
            LeanTween.dispatchEvent(1);
            LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED");

            // remove listener
            LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED");

            lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id;
            LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f);

            LeanTween.reset();

            Vector3[] splineArr = new Vector3[] { new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f), new Vector3(30f, 0f, 0f) };
            LTSpline  cr        = new LTSpline(splineArr);

            cr.place(cube4.transform, 0.5f);
            LeanTest.expect((Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)");
            LeanTween.color(cube4, Color.green, 0.01f);

//			Debug.Log("Point 2:"+cr.ratioAtPoint(splineArr[2]));

            // OnStart Speed Test for ignoreTimeScale vs normal timeScale

            GameObject cubeDest    = cubeNamed("cubeDest");
            Vector3    cubeDestEnd = new Vector3(100f, 20f, 0f);

            LeanTween.move(cubeDest, cubeDestEnd, 0.7f);

            GameObject cubeToTrans = cubeNamed("cubeToTrans");

            LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() => {
                LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS");
            });

            GameObject cubeDestroy = cubeNamed("cubeDestroy");

            LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true);
            LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() => {
                LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED");
            });

            GameObject cubeSpline = cubeNamed("cubeSpline");

            LeanTween.moveSpline(cubeSpline, new Vector3[] { new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 1f) }, 0.1f).setOnComplete(() => {
                LeanTest.expect(Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS");
            });

            // This test works when it is positioned last in the test queue (probably worth fixing when you have time)
            GameObject jumpCube = cubeNamed("jumpTime");

            jumpCube.transform.position    = new Vector3(100f, 0f, 0f);
            jumpCube.transform.localScale *= 100f;
            int jumpTimeId = LeanTween.moveX(jumpCube, 200f, 1f).id;

            LeanTween.delayedCall(gameObject, 0.2f, () => {
                LTDescr d     = LeanTween.descr(jumpTimeId);
                float beforeX = jumpCube.transform.position.x;
                d.setTime(0.5f);
                LeanTween.delayedCall(0.0f, () => { }).setOnStart(() => {
                    float diffAmt = 1f;                    // This variable is dependent on a good frame-rate because it evalutes at the next Update
                    beforeX      += Time.deltaTime * 100f * 2f;
                    LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < diffAmt, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX) + " beforeX:" + beforeX + " now:" + jumpCube.transform.position.x + " dt:" + Time.deltaTime);
                });
            });

            // Tween with time of zero is needs to be set to it's final value
            GameObject zeroCube = cubeNamed("zeroCube");

            LeanTween.moveX(zeroCube, 10f, 0f).setOnComplete(() => {
                LeanTest.expect(zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY", "final x:" + zeroCube.transform.position.x);
            });

            // Scale, and OnStart
            GameObject cubeScale = cubeNamed("cubeScale");

            LeanTween.scale(cubeScale, new Vector3(5f, 5f, 5f), 0.01f).setOnStart(() => {
                LeanTest.expect(true, "ON START WAS CALLED");
            }).setOnComplete(() => {
                LeanTest.expect(cubeScale.transform.localScale.z == 5f, "SCALE", "expected scale z:" + 5f + " returned:" + cubeScale.transform.localScale.z);
            });

            // Rotate
            GameObject cubeRotate = cubeNamed("cubeRotate");

            LeanTween.rotate(cubeRotate, new Vector3(0f, 180f, 0f), 0.02f).setOnComplete(() => {
                LeanTest.expect(cubeRotate.transform.eulerAngles.y == 180f, "ROTATE", "expected rotate y:" + 180f + " returned:" + cubeRotate.transform.eulerAngles.y);
            });

            // RotateAround
            GameObject cubeRotateA = cubeNamed("cubeRotateA");

            LeanTween.rotateAround(cubeRotateA, Vector3.forward, 90f, 0.3f).setOnComplete(() => {
                LeanTest.expect(cubeRotateA.transform.eulerAngles.z == 90f, "ROTATE AROUND", "expected rotate z:" + 90f + " returned:" + cubeRotateA.transform.eulerAngles.z);
            });

            // RotateAround 360
            GameObject cubeRotateB = cubeNamed("cubeRotateB");

            cubeRotateB.transform.position = new Vector3(200f, 10f, 8f);
            LeanTween.rotateAround(cubeRotateB, Vector3.forward, 360f, 0.3f).setPoint(new Vector3(5f, 3f, 2f)).setOnComplete(() => {
                LeanTest.expect(cubeRotateB.transform.position == new Vector3(200f, 10f, 8f), "ROTATE AROUND 360", "expected rotate pos:" + (new Vector3(200f, 10f, 8f)) + " returned:" + cubeRotateB.transform.position);
            });

            // Alpha, onUpdate with passing value, onComplete value
            LeanTween.alpha(cubeAlpha1, 0.5f, 0.1f).setOnUpdate((float val) => {
                LeanTest.expect(val != 0f, "ON UPDATE VAL");
            }).setOnCompleteParam("Hi!").setOnComplete((object completeObj) => {
                LeanTest.expect(((string)completeObj) == "Hi!", "ONCOMPLETE OBJECT");
                LeanTest.expect(cubeAlpha1.GetComponent <Renderer>().material.color.a == 0.5f, "ALPHA");
            });
            // Color
            float onStartTime = -1f;

            LeanTween.color(cubeAlpha2, Color.cyan, 0.3f).setOnComplete(() => {
                LeanTest.expect(cubeAlpha2.GetComponent <Renderer>().material.color == Color.cyan, "COLOR");
                LeanTest.expect(onStartTime >= 0f && onStartTime < Time.time, "ON START", "onStartTime:" + onStartTime + " time:" + Time.time);
            }).setOnStart(() => {
                onStartTime = Time.time;
            });
            // moveLocalY (make sure uses y values)
            Vector3 beforePos = cubeAlpha1.transform.position;

            LeanTween.moveY(cubeAlpha1, 3f, 0.2f).setOnComplete(() => {
                LeanTest.expect(cubeAlpha1.transform.position.x == beforePos.x && cubeAlpha1.transform.position.z == beforePos.z, "MOVE Y");
            });

            Vector3 beforePos2 = cubeAlpha2.transform.localPosition;

            LeanTween.moveLocalZ(cubeAlpha2, 12f, 0.2f).setOnComplete(() => {
                LeanTest.expect(cubeAlpha2.transform.localPosition.x == beforePos2.x && cubeAlpha2.transform.localPosition.y == beforePos2.y, "MOVE LOCAL Z", "ax:" + cubeAlpha2.transform.localPosition.x + " bx:" + beforePos.x + " ay:" + cubeAlpha2.transform.localPosition.y + " by:" + beforePos2.y);
            });

            AudioClip audioClip = LeanAudio.createAudio(new AnimationCurve(new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f)), new AnimationCurve(new Keyframe(0f, 0.001f, 0f, 0f), new Keyframe(1f, 0.001f, 0f, 0f)), LeanAudio.options());

            LeanTween.delayedSound(gameObject, audioClip, new Vector3(0f, 0f, 0f), 0.1f).setDelay(0.2f).setOnComplete(() => {
                LeanTest.expect(Time.time > 0, "DELAYED SOUND");
            });

            // value2
            bool value2UpdateCalled = false;

            LeanTween.value(gameObject, new Vector2(0, 0), new Vector2(256, 96), 0.1f).setOnUpdate((Vector2 value) => {
                value2UpdateCalled = true;
            });
            LeanTween.delayedCall(0.2f, () => {
                LeanTest.expect(value2UpdateCalled, "VALUE2 UPDATE");
            });

            StartCoroutine(timeBasedTesting());
        }
Exemple #15
0
    public LTSeq append(GameObject gameObject, System.Action callback)
    {
        append(LeanTween.delayedCall(gameObject, 0f, callback));

        return(addOn());
    }
Exemple #16
0
    //Picks up a specific item
    public void Pickup(DropItem itm)
    {
        Sprite  spr = itm.obj.GetComponentInChildren <SpriteRenderer> ().sprite;
        Vector2 pos = stairCam.WorldToScreenPoint(itm.obj.transform.position);

        //TMPro.TextMeshPro[] texts = itm.obj.GetComponentsInChildren<TMPro.TextMeshPro> ();

        if (itm.item.pickEffect != null)
        {
            GameObject eff = Instantiate(itm.item.pickEffect, itm.obj.transform.position + Vector3.up, itm.item.pickEffect.transform.rotation);
            eff.transform.parent = itm.obj.transform.parent;
        }

        //Debug.Log ("snd "+itm.item.sound.name);
        CharacterProfile curChar = charStore.GetCharacter(Persistence.currentChar);

        if (itm.item.isSpecial && curChar.specialVoice != null && character.canTalk)
        {
            LeanAudio.play(curChar.specialVoice);
        }

        Destroy(itm.obj);
        spawned.Remove(itm);


        GameObject inst = Overlay.instance.CreateOverlayObj(spr, pos);

        AudioSource src = inst.AddComponent <AudioSource> ();

        src.clip = itm.item.sound;
        src.Play();

        GameObject poof = Instantiate(pickupEff, inst.transform.position, inst.transform.rotation);

        poof.layer = LayerMask.NameToLayer("Overlay");
        Destroy(poof, 2);

        float timer = 0.4333f;



        if (itm.type == PickableItem.Type.COIN)
        {
            if (Overlay.instance.enabled)
            {
                //Overlay.instance.MoveTo (inst, bank.coinTargetPos, timer, OnCoinEnd);
                moveCoin(inst, timer);
            }
            else
            {
                OnCoinEnd();
            }
        }
        else if (itm.type == PickableItem.Type.BOMB)
        {
            Overlay.instance.MoveTo(inst, bomb.position, 0.6f, LeanTweenType.easeInOutSine, true, true, OnBombEnd);
        }
        else if (itm.type == PickableItem.Type.PINATA)
        {
            for (int i = 0; i < itm.item.coinCount; i++)
            {
                LeanTween.delayedCall(0.2f * i, () => {
                    Vector3 pek = pos + Random.insideUnitCircle.normalized * 15;

                    GameObject o = Overlay.instance.CreateOverlayObj(coin, pek);
                    o.name      += i;
                    moveCoin(o, timer);

                    //Overlay.instance.MoveTo (o, bank.bankPos, timer, OnCoinEnd);
                });
            }
        }
        else if (itm.type == PickableItem.Type.BOX)
        {
            LeanTween.delayedCall(character.gameObject, 0.3f, character.Switch);
        }
        else if (itm.type == PickableItem.Type.CRYSTAL)
        {
            if (FMC_GameDataController.instance != null)
            {
                FMC_GameDataController.instance.makeStoryModeEasier();
                Debug.LogWarning("STORY MODE MADE EASIER");
                GameObject     go   = GameObject.Find("diamonds");
                ParticleSystem part = go.GetComponent <ParticleSystem> ();
                part.Play();
            }
        }
        else if (itm.type == PickableItem.Type.LVL)
        {
            inst.SetActive(false);
            exp.LvlUp();
            FindObjectOfType <LevelUpScreen> ().Init(inst.transform.position);
        }
        else if (itm.type == PickableItem.Type.LOCK)
        {
            inst.SetActive(false);
            main.MainMenu();
            bank.Wipe();
        }
        else if (itm.type == PickableItem.Type.ROCKET)
        {
            inst.SetActive(false);
            main.Fly(Random.Range(3, 10));
        }
        else
        {
        }
    }
    //public void Play_SendPreview()
    //{
    //    isNegativeOverruled = true;
    //    PlaySound(SoundEffects.SendPreview);
    //    LeanTween.delayedCall(0.35f, () => isNegativeOverruled = false);
    //}

    //public void Play_StarPop()
    //{
    //    PlaySound(SoundEffects.StarEarned);
    //}

    //public void Play_Countdown()
    //{
    //    PlaySound(SoundEffects.Countdown);
    //}

    //public void Play_Undo()
    //{
    //    PlaySound(SoundEffects.Undo);
    //}

    //public void Play_StarCollected()
    //{
    //    PlaySound(SoundEffects.StarCollected);
    //}

    private void TemporaryMute(float muteTime = 0.35f)
    {
        canPlay = false;
        LeanTween.delayedCall(muteTime, () => canPlay = true);
    }
Exemple #18
0
 void Start()
 {
     LTDescr ltDescr = LeanTween.delayedCall(3, OnViewReady);
 }
 public void ReleaseHold()
 {
     LeanTween.delayedCall(0.1f, () => onHold = false);
 }
Exemple #20
0
        IEnumerator timeBasedTesting()
        {
            yield return(new WaitForSeconds(1));

            yield return(new WaitForEndOfFrame());

            LeanTest.expect(Mathf.Abs(timeElapsedNormalTimeScale - timeElapsedIgnoreTimeScale) < 0.15f, "START IGNORE TIMING", "timeElapsedIgnoreTimeScale:" + timeElapsedIgnoreTimeScale + " timeElapsedNormalTimeScale:" + timeElapsedNormalTimeScale);

            Time.timeScale = 4f;

            int pauseCount = 0;

            LeanTween.value(gameObject, 0f, 1f, 1f).setOnUpdate(( float val ) => {
                pauseCount++;
            }).pause();

            // Bezier should end at exact end position not just 99% close to it
            Vector3[]  roundCirc = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(-9.1f, 25.1f, 0f), new Vector3(-1.2f, 15.9f, 0f), new Vector3(-25f, 25f, 0f), new Vector3(-25f, 25f, 0f), new Vector3(-50.1f, 15.9f, 0f), new Vector3(-40.9f, 25.1f, 0f), new Vector3(-50f, 0f, 0f), new Vector3(-50f, 0f, 0f), new Vector3(-40.9f, -25.1f, 0f), new Vector3(-50.1f, -15.9f, 0f), new Vector3(-25f, -25f, 0f), new Vector3(-25f, -25f, 0f), new Vector3(0f, -15.9f, 0f), new Vector3(-9.1f, -25.1f, 0f), new Vector3(0f, 0f, 0f) };
            GameObject cubeRound = Instantiate(boxNoCollider) as GameObject;

            cubeRound.name = "bRound";
            Vector3 onStartPos = cubeRound.transform.position;

            LeanTween.moveLocal(cubeRound, roundCirc, 0.5f).setOnComplete(() => {
                LeanTest.expect(cubeRound.transform.position == onStartPos, "BEZIER CLOSED LOOP SHOULD END AT START", "onStartPos:" + onStartPos + " onEnd:" + cubeRound.transform.position);
            });

            // Spline should end at exact end position not just 99% close to it
            Vector3[]  roundSpline = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(2f, 0f, 0f), new Vector3(0.9f, 2f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f) };
            GameObject cubeSpline  = Instantiate(boxNoCollider) as GameObject;

            cubeSpline.name = "bSpline";
            Vector3 onStartPosSpline = cubeSpline.transform.position;

            LeanTween.moveSplineLocal(cubeSpline, roundSpline, 0.5f).setOnComplete(() => {
                LeanTest.expect(Vector3.Distance(onStartPosSpline, cubeSpline.transform.position) <= 0.01f, "BEZIER CLOSED LOOP SHOULD END AT START", "onStartPos:" + onStartPosSpline + " onEnd:" + cubeSpline.transform.position + " dist:" + Vector3.Distance(onStartPosSpline, cubeSpline.transform.position));
            });

            // Groups of tweens testing
            groupTweens    = new LTDescr[1200];
            groupGOs       = new GameObject[groupTweens.Length];
            groupTweensCnt = 0;
            int descriptionMatchCount = 0;

            for (int i = 0; i < groupTweens.Length; i++)
            {
                GameObject cube = Instantiate(boxNoCollider) as GameObject;
                cube.name = "c" + i;
                cube.transform.position = new Vector3(0, 0, i * 3);

                groupGOs[i] = cube;
            }

            yield return(new WaitForEndOfFrame());

            bool hasGroupTweensCheckStarted = false;
            int  setOnStartNum = 0;

            for (int i = 0; i < groupTweens.Length; i++)
            {
                groupTweens[i] = LeanTween.move(groupGOs[i], transform.position + Vector3.one * 3f, 3f).setOnStart(() => {
                    setOnStartNum++;
                }).setOnComplete(() => {
                    if (hasGroupTweensCheckStarted == false)
                    {
                        hasGroupTweensCheckStarted = true;
                        LeanTween.delayedCall(gameObject, 0.1f, () => {
                            LeanTest.expect(setOnStartNum == groupTweens.Length, "SETONSTART CALLS", "expected:" + groupTweens.Length + " was:" + setOnStartNum);
                            LeanTest.expect(groupTweensCnt == groupTweens.Length, "GROUP FINISH", "expected " + groupTweens.Length + " tweens but got " + groupTweensCnt);
                        });
                    }
                    groupTweensCnt++;
                });

                if (LeanTween.description(groupTweens[i].id).trans == groupTweens[i].trans)
                {
                    descriptionMatchCount++;
                }
            }

            while (LeanTween.tweensRunning < groupTweens.Length)
            {
                yield return(null);
            }

            LeanTest.expect(descriptionMatchCount == groupTweens.Length, "GROUP IDS MATCH");
            LeanTest.expect(LeanTween.maxSearch <= groupTweens.Length + 5, "MAX SEARCH OPTIMIZED", "maxSearch:" + LeanTween.maxSearch);
            LeanTest.expect(LeanTween.isTweening() == true, "SOMETHING IS TWEENING");

            // resume item before calling pause should continue item along it's way
            float previousXlt4 = cube4.transform.position.x;

            lt4 = LeanTween.moveX(cube4, 5.0f, 1.1f).setOnComplete(() => {
                LeanTest.expect(cube4 != null && previousXlt4 != cube4.transform.position.x, "RESUME OUT OF ORDER", "cube4:" + cube4 + " previousXlt4:" + previousXlt4 + " cube4.transform.position.x:" + (cube4 != null ? cube4.transform.position.x : 0));
            }).setDestroyOnComplete(true);
            lt4.resume();

            rotateRepeat = rotateRepeatAngle = 0;
            LeanTween.rotateAround(cube3, Vector3.forward, 360f, 0.1f).setRepeat(3).setOnComplete(rotateRepeatFinished).setOnCompleteOnRepeat(true).setDestroyOnComplete(true);
            yield return(new WaitForEndOfFrame());

            LeanTween.delayedCall(0.1f * 8f + 1f, rotateRepeatAllFinished);

            int countBeforeCancel = LeanTween.tweensRunning;

            LeanTween.cancel(lt1Id);
            LeanTest.expect(countBeforeCancel == LeanTween.tweensRunning, "CANCEL AFTER RESET SHOULD FAIL", "expected " + countBeforeCancel + " but got " + LeanTween.tweensRunning);
            LeanTween.cancel(cube2);

            int tweenCount = 0;

            for (int i = 0; i < groupTweens.Length; i++)
            {
                if (LeanTween.isTweening(groupGOs[i]))
                {
                    tweenCount++;
                }
                if (i % 3 == 0)
                {
                    LeanTween.pause(groupGOs[i]);
                }
                else if (i % 3 == 1)
                {
                    groupTweens[i].pause();
                }
                else
                {
                    LeanTween.pause(groupTweens[i].id);
                }
            }
            LeanTest.expect(tweenCount == groupTweens.Length, "GROUP ISTWEENING", "expected " + groupTweens.Length + " tweens but got " + tweenCount);

            yield return(new WaitForEndOfFrame());

            tweenCount = 0;
            for (int i = 0; i < groupTweens.Length; i++)
            {
                if (i % 3 == 0)
                {
                    LeanTween.resume(groupGOs[i]);
                }
                else if (i % 3 == 1)
                {
                    groupTweens[i].resume();
                }
                else
                {
                    LeanTween.resume(groupTweens[i].id);
                }

                if (i % 2 == 0 ? LeanTween.isTweening(groupTweens[i].id) : LeanTween.isTweening(groupGOs[i]))
                {
                    tweenCount++;
                }
            }
            LeanTest.expect(tweenCount == groupTweens.Length, "GROUP RESUME");

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "CANCEL TWEEN LTDESCR");
            LeanTest.expect(LeanTween.isTweening(cube2) == false, "CANCEL TWEEN LEANTWEEN");

            LeanTest.expect(pauseCount == 0, "ON UPDATE NOT CALLED DURING PAUSE", "expect pause count of 0, but got " + pauseCount);

            yield return(new WaitForEndOfFrame());

            Time.timeScale = 0.25f;
            float tweenTime         = 0.2f;
            float expectedTime      = tweenTime * (1f / Time.timeScale);
            float start             = Time.realtimeSinceStartup;
            bool  onUpdateWasCalled = false;

            LeanTween.moveX(cube1, -5f, tweenTime).setOnUpdate((float val) => {
                onUpdateWasCalled = true;
            }).setOnComplete(() => {
                float end  = Time.realtimeSinceStartup;
                float diff = end - start;

                LeanTest.expect(Mathf.Abs(expectedTime - diff) < 0.05f, "SCALED TIMING DIFFERENCE", "expected to complete in roughly " + expectedTime + " but completed in " + diff);
                LeanTest.expect(Mathf.Approximately(cube1.transform.position.x, -5f), "SCALED ENDING POSITION", "expected to end at -5f, but it ended at " + cube1.transform.position.x);
                LeanTest.expect(onUpdateWasCalled, "ON UPDATE FIRED");
            });

            yield return(new WaitForSeconds(expectedTime));

            Time.timeScale = 1f;

            int ltCount = 0;

            GameObject[] allGos = FindObjectsOfType(typeof(GameObject)) as GameObject[];
            foreach (GameObject go in allGos)
            {
                if (go.name == "~LeanTween")
                {
                    ltCount++;
                }
            }
            LeanTest.expect(ltCount == 1, "RESET CORRECTLY CLEANS UP");



            lotsOfCancels();
        }
Exemple #21
0
    private void RecursionShow()
    {
        float waitTime = UnityEngine.Random.Range(2000, 6000) / 1000.00f;

        LeanTween.delayedCall(waitTime, OnShow);
    }
Exemple #22
0
 private void ShowShotAnim()
 {
     avatarAnimator.SetBool("shot", true);
     LeanTween.delayedCall(shootingAnimRange, HideShotAnim);
 }
    void Update()
    {
        LeanTween.dtManual = Time.deltaTime;
        if (Input.GetKeyDown(KeyCode.Q))
        {
            //LeanTween.scale(this.gameObject, Vector3.one*3f, 1.0f).setEase(LeanTweenType.easeSpring).setUseManualTime(true);
            //print("scale punch time independent!");

            LeanTween.moveLocalX(gameObject, 5, 1).setOnComplete(() => {
                Debug.Log("on complete move local X");
            }).setOnCompleteOnStart(true);

            GameObject light = GameObject.Find("DirectionalLight");
            Light      lt    = light.GetComponent <Light>();

            LeanTween.value(lt.gameObject, lt.intensity, 0.0f, 1.5f)
            .setEase(LeanTweenType.linear)
            .setLoopPingPong()
            .setRepeat(-1)
            .setOnUpdate((float val) => {
                lt.intensity = val;
            });
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            print("scale punch!");

            tweenStatically(this.gameObject);

            LeanTween.scale(this.gameObject, new Vector3(1.15f, 1.15f, 1.15f), 0.6f);

            LeanTween.rotateAround(this.gameObject, Vector3.forward, -360f, 0.3f).setOnComplete(() =>
            {
                LeanTween.rotateAround(this.gameObject, Vector3.forward, -360f, 0.4f).setOnComplete(() =>
                {
                    LeanTween.scale(this.gameObject, new Vector3(1f, 1f, 1f), 0.1f);

                    LeanTween.value(this.gameObject, (v) =>
                    {
                    }, 0, 1, 0.3f).setDelay(1);
                });
            });
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            Vector3[] pts = new Vector3[] { new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f) };
            descr = LeanTween.move(gameObject, pts, 15f).setOrientToPath(true).setDirection(1f).setOnComplete(() => {
                Debug.Log("move path finished");
            });
        }

        if (Input.GetKeyDown(KeyCode.Y)) // Reverse the move path
        {
            descr.setDirection(-descr.direction);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            // LeanTween.rotate(this.gameObject, Vector3.one, 1.0f).setEase(LeanTweenType.punch);
            LeanTween.rotateAroundLocal(this.gameObject, this.transform.forward, -80f, 5.0f).setPoint(new Vector3(1.25f, 0f, 0f));
            print("rotate punch!");
        }

        if (Input.GetKeyDown(KeyCode.M))
        {
            // LeanTween.move(this.gameObject, new Vector3(0f,0f,1f), 1.0f).setEase(LeanTweenType.punch);
            print("move punch!");
            Time.timeScale = 0.25f;
            float start = Time.realtimeSinceStartup;
            LeanTween.moveX(this.gameObject, 1f, 1f).setOnComplete(destroyOnComp).setOnCompleteParam(this.gameObject).setOnComplete(() => {
                float end  = Time.realtimeSinceStartup;
                float diff = end - start;
                Debug.Log("start:" + start + " end:" + end + " diff:" + diff + " x:" + this.gameObject.transform.position.x);
            }).setEase(LeanTweenType.easeInBack).setOvershoot(overShootValue).setPeriod(0.3f);
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            LeanTween.color(this.gameObject, new Color(1f, 0f, 0f, 0.5f), 1f);

            Color      to = new Color(Random.Range(0f, 1f), 0f, Random.Range(0f, 1f), 0.0f);
            GameObject l  = GameObject.Find("LCharacter");
            LeanTween.color(l, to, 4.0f).setLoopPingPong(1).setEase(LeanTweenType.easeOutBounce);
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            LeanTween.delayedCall(gameObject, 0.3f, delayedMethod).setRepeat(4).setOnCompleteOnRepeat(true).setOnCompleteParam("hi");
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            LeanTween.value(gameObject, updateColor, new Color(1.0f, 0.0f, 0.0f, 1.0f), Color.blue, 4.0f);//.setRepeat(2).setLoopPingPong().setEase(LeanTweenType.easeOutBounce);
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            LeanTween.delayedCall(0.05f, enterMiniGameStart).setOnCompleteParam(new object[] { "" + 5 });
        }

        if (Input.GetKeyDown(KeyCode.U))
        {
            #if !UNITY_FLASH
            LeanTween.value(gameObject, (Vector2 val) => {
                // Debug.Log("tweening vec2 val:"+val);
                transform.position = new Vector3(val.x, transform.position.y, transform.position.z);
            }, new Vector2(0f, 0f), new Vector2(5f, 100f), 1f).setEase(LeanTweenType.easeOutBounce);

            GameObject l = GameObject.Find("LCharacter");
            Debug.Log("x:" + l.transform.position.x + " y:" + l.transform.position.y);
            LeanTween.value(l, new Vector2(l.transform.position.x, l.transform.position.y), new Vector2(l.transform.position.x, l.transform.position.y + 5), 1f).setOnUpdate(
                (Vector2 val) => {
                Debug.Log("tweening vec2 val:" + val);
                l.transform.position = new Vector3(val.x, val.y, transform.position.z);
            }

                );
            #endif
        }
    }
Exemple #24
0
 public static LTDescr LeanDelayedCall(this GameObject gameObject, float delayTime, System.Action <object> callback)
 {
     return(LeanTween.delayedCall(gameObject, delayTime, callback));
 }
    public void delayedCallExample()
    {
        Debug.Log("delayedCallExample");

        LeanTween.delayedCall(0.5f, delayedCallExampleCallback).setUseEstimatedTime(useEstimatedTime);
    }
Exemple #26
0
        private IEnumerator timeBasedTesting()
        {
            yield return(new WaitForEndOfFrame());

            var cubeNormal = cubeNamed("normalTimeScale");

            // float timeElapsedNormal = Time.time;
            LeanTween.moveX(cubeNormal, 12f, 1.5f).setIgnoreTimeScale(false).setOnComplete(() =>
            {
                timeElapsedNormalTimeScale = Time.time;
            });

            var descr = LeanTween.descriptions(cubeNormal);

            LeanTest.expect(descr.Length >= 0 && descr[0].to.x == 12f, "WE CAN RETRIEVE A DESCRIPTION");

            var cubeIgnore = cubeNamed("ignoreTimeScale");

            LeanTween.moveX(cubeIgnore, 5f, 1.5f).setIgnoreTimeScale(true).setOnComplete(() =>
            {
                timeElapsedIgnoreTimeScale = Time.time;
            });

            yield return(new WaitForSeconds(1.5f));

            LeanTest.expect(Mathf.Abs(timeElapsedNormalTimeScale - timeElapsedIgnoreTimeScale) < 0.7f,
                            "START IGNORE TIMING",
                            "timeElapsedIgnoreTimeScale:" + timeElapsedIgnoreTimeScale + " timeElapsedNormalTimeScale:" +
                            timeElapsedNormalTimeScale);

            //          yield return new WaitForSeconds(100f);
            Time.timeScale = 4f;

            var pauseCount = 0;

            LeanTween.value(gameObject, 0f, 1f, 1f).setOnUpdate((float val) => { pauseCount++; }).pause();

            // Bezier should end at exact end position not just 99% close to it
            Vector3[] roundCirc =
            {
                new Vector3(0f,         0f, 0f), new Vector3(-9.1f,   25.1f, 0f), new Vector3(-1.2f,   15.9f, 0f),
                new Vector3(-25f,      25f, 0f), new Vector3(-25f,      25f, 0f), new Vector3(-50.1f,  15.9f, 0f),
                new Vector3(-40.9f,  25.1f, 0f), new Vector3(-50f,       0f, 0f), new Vector3(-50f,       0f, 0f),
                new Vector3(-40.9f, -25.1f, 0f), new Vector3(-50.1f, -15.9f, 0f), new Vector3(-25f,     -25f, 0f),
                new Vector3(-25f,     -25f, 0f), new Vector3(0f,     -15.9f, 0f), new Vector3(-9.1f,  -25.1f, 0f),
                new Vector3(0f,         0f, 0f)
            };
            var cubeRound  = cubeNamed("bRound");
            var onStartPos = cubeRound.transform.position;

            LeanTween.moveLocal(cubeRound, roundCirc, 0.5f).setOnComplete(() =>
            {
                LeanTest.expect(cubeRound.transform.position == onStartPos,
                                "BEZIER CLOSED LOOP SHOULD END AT START",
                                "onStartPos:" + onStartPos + " onEnd:" + cubeRound.transform.position);
            });

            // should be able to retrieve a point
            var roundCircPath = new LTBezierPath(roundCirc);
            var ratioPoint    = roundCircPath.ratioAtPoint(new Vector3(-25f, 25f, 0f));

            LeanTest.expect(Equals(ratioPoint, 0.25f), "BEZIER RATIO POINT");

            // Spline should end at exact end position not just 99% close to it
            Vector3[] roundSpline =
            {
                new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(2f, 0f, 0f), new Vector3(0.9f, 2f, 0f),
                new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f)
            };
            var cubeSpline       = cubeNamed("bSpline");
            var onStartPosSpline = cubeSpline.transform.position;

            LeanTween.moveSplineLocal(cubeSpline, roundSpline, 0.5f).setOnComplete(() =>
            {
                LeanTest.expect(Vector3.Distance(onStartPosSpline, cubeSpline.transform.position) <= 0.01f,
                                "SPLINE CLOSED LOOP SHOULD END AT START",
                                "onStartPos:" + onStartPosSpline + " onEnd:" + cubeSpline.transform.position + " dist:" +
                                Vector3.Distance(onStartPosSpline, cubeSpline.transform.position));
            });

            // Sequence test, do three tweens and make sure they end at the right points
            var cubeSeq = cubeNamed("cSeq");
            var seq     = LeanTween.sequence().append(LeanTween.moveX(cubeSeq, 100f, 0.2f));

            seq.append(0.1f).append(LeanTween.scaleX(cubeSeq, 2f, 0.1f));
            seq.append(() =>
            {
                LeanTest.expect(cubeSeq.transform.position.x == 100f, "SEQ MOVE X FINISHED",
                                "move x:" + cubeSeq.transform.position.x);
                LeanTest.expect(cubeSeq.transform.localScale.x == 2f, "SEQ SCALE X FINISHED",
                                "scale x:" + cubeSeq.transform.localScale.x);
            }).setScale(0.2f);

            // Bounds check
            var cubeBounds    = cubeNamed("cBounds");
            var didPassBounds = true;
            var failPoint     = Vector3.zero;

            LeanTween.move(cubeBounds, new Vector3(10, 10, 10), 0.1f).setOnUpdate((float val) =>
            {
                //              Debug.LogWarning("cubeBounds x:"+cubeBounds.transform.position.x + " y:"+ cubeBounds.transform.position.y+" z:"+cubeBounds.transform.position.z);
                if (cubeBounds.transform.position.x < 0f || cubeBounds.transform.position.x > 10f ||
                    cubeBounds.transform.position.y < 0f || cubeBounds.transform.position.y > 10f ||
                    cubeBounds.transform.position.z < 0f || cubeBounds.transform.position.z > 10f)
                {
                    didPassBounds = false;
                    failPoint     = cubeBounds.transform.position;
                    //                  Debug.LogError("OUT OF BOUNDS");
                }
            }).setLoopPingPong().setRepeat(8).setOnComplete(() =>
            {
                LeanTest.expect(didPassBounds, "OUT OF BOUNDS",
                                "pos x:" + failPoint.x + " y:" + failPoint.y + " z:" + failPoint.z);
            });

            // Local scale check
            //GameObject cubeLocal = cubeNamed("cLocal");
            //LeanTween.scale(cubeLocal, new Vector3(0.5f, 0.5f, 0.5f), 0.2f).setOnComplete(() =>
            //{
            //    LeanTest.expect((cubeLocal.transform.localScale.x == 0.5f && cubeLocal.transform.localScale.y == 0.5f && cubeLocal.transform.localScale.z == 0.5f), "SCALE WORKS", "scale x:" + cubeLocal.transform.localScale.x + " y:" + cubeLocal.transform.localScale.y + " z:" + cubeLocal.transform.localScale.z);
            //});

            // Groups of tweens testing
            groupTweens    = new LTDescr[1200];
            groupGOs       = new GameObject[groupTweens.Length];
            groupTweensCnt = 0;
            var descriptionMatchCount = 0;

            for (var i = 0; i < groupTweens.Length; i++)
            {
                var cube = cubeNamed("c" + i);
                cube.transform.position = new Vector3(0, 0, i * 3);

                groupGOs[i] = cube;
            }

            yield return(new WaitForEndOfFrame());

            var hasGroupTweensCheckStarted = false;
            var setOnStartNum  = 0;
            var setPosNum      = 0;
            var setPosOnUpdate = true;

            for (var i = 0; i < groupTweens.Length; i++)
            {
                var finalPos  = transform.position + Vector3.one * 3f;
                var finalDict = new Dictionary <string, object> {
                    { "final", finalPos }, { "go", groupGOs[i] }
                };
                groupTweens[i] = LeanTween.move(groupGOs[i], finalPos, 3f).setOnStart(() => { setOnStartNum++; })
                                 .setOnUpdate(newPosition =>
                {
                    if (transform.position.z > newPosition.z)
                    {
                        setPosOnUpdate = false;
                    }
                    //                  Debug.LogWarning("New Position: " + newPosition.ToString());
                }).setOnCompleteParam(finalDict).setOnComplete(param =>
                {
                    var finalDictRetr = param as Dictionary <string, object>;
                    var neededPos     = (Vector3)finalDictRetr["final"];
                    var tweenedGo     = finalDictRetr["go"] as GameObject;
                    if (neededPos.ToString() == tweenedGo.transform.position.ToString())
                    {
                        setPosNum++;
                    }

                    if (hasGroupTweensCheckStarted == false)
                    {
                        hasGroupTweensCheckStarted = true;
                        LeanTween.delayedCall(gameObject, 0.1f, () =>
                        {
                            LeanTest.expect(setOnStartNum == groupTweens.Length, "SETONSTART CALLS",
                                            "expected:" + groupTweens.Length + " was:" + setOnStartNum);
                            LeanTest.expect(groupTweensCnt == groupTweens.Length, "GROUP FINISH",
                                            "expected " + groupTweens.Length + " tweens but got " + groupTweensCnt);
                            LeanTest.expect(setPosNum == groupTweens.Length, "GROUP POSITION FINISH",
                                            "expected " + groupTweens.Length + " tweens but got " + setPosNum);
                            LeanTest.expect(setPosOnUpdate, "GROUP POSITION ON UPDATE");
                        });
                    }

                    groupTweensCnt++;
                });

                if (LeanTween.description(groupTweens[i].id).trans == groupTweens[i].trans)
                {
                    descriptionMatchCount++;
                }
            }

            while (LeanTween.tweensRunning < groupTweens.Length)
            {
                yield return(null);
            }

            LeanTest.expect(descriptionMatchCount == groupTweens.Length, "GROUP IDS MATCH");
            var expectedSearch = groupTweens.Length + 7;

            LeanTest.expect(LeanTween.maxSearch <= expectedSearch, "MAX SEARCH OPTIMIZED",
                            "maxSearch:" + LeanTween.maxSearch + " should be:" + expectedSearch);
            LeanTest.expect(LeanTween.isTweening(), "SOMETHING IS TWEENING");

            // resume item before calling pause should continue item along it's way
            var previousXlt4 = cube4.transform.position.x;

            lt4 = LeanTween.moveX(cube4, 5.0f, 1.1f).setOnComplete(() =>
            {
                LeanTest.expect(cube4 != null && previousXlt4 != cube4.transform.position.x, "RESUME OUT OF ORDER",
                                "cube4:" + cube4 + " previousXlt4:" + previousXlt4 + " cube4.transform.position.x:" +
                                (cube4 != null ? cube4.transform.position.x : 0));
            }).setDestroyOnComplete(true);
            lt4.resume();

            rotateRepeat = rotateRepeatAngle = 0;
            LeanTween.rotateAround(cube3, Vector3.forward, 360f, 0.1f).setRepeat(3).setOnComplete(rotateRepeatFinished)
            .setOnCompleteOnRepeat(true).setDestroyOnComplete(true);
            yield return(new WaitForEndOfFrame());

            LeanTween.delayedCall(0.1f * 8f + 1f, rotateRepeatAllFinished);

            var countBeforeCancel = LeanTween.tweensRunning;

            LeanTween.cancel(lt1Id);
            LeanTest.expect(countBeforeCancel == LeanTween.tweensRunning, "CANCEL AFTER RESET SHOULD FAIL",
                            "expected " + countBeforeCancel + " but got " + LeanTween.tweensRunning);
            LeanTween.cancel(cube2);

            var tweenCount = 0;

            for (var i = 0; i < groupTweens.Length; i++)
            {
                if (LeanTween.isTweening(groupGOs[i]))
                {
                    tweenCount++;
                }
                if (i % 3 == 0)
                {
                    LeanTween.pause(groupGOs[i]);
                }
                else if (i % 3 == 1)
                {
                    groupTweens[i].pause();
                }
                else
                {
                    LeanTween.pause(groupTweens[i].id);
                }
            }

            LeanTest.expect(tweenCount == groupTweens.Length, "GROUP ISTWEENING",
                            "expected " + groupTweens.Length + " tweens but got " + tweenCount);

            yield return(new WaitForEndOfFrame());

            tweenCount = 0;
            for (var i = 0; i < groupTweens.Length; i++)
            {
                if (i % 3 == 0)
                {
                    LeanTween.resume(groupGOs[i]);
                }
                else if (i % 3 == 1)
                {
                    groupTweens[i].resume();
                }
                else
                {
                    LeanTween.resume(groupTweens[i].id);
                }

                if (i % 2 == 0 ? LeanTween.isTweening(groupTweens[i].id) : LeanTween.isTweening(groupGOs[i]))
                {
                    tweenCount++;
                }
            }

            LeanTest.expect(tweenCount == groupTweens.Length, "GROUP RESUME");

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "CANCEL TWEEN LTDESCR");
            LeanTest.expect(LeanTween.isTweening(cube2) == false, "CANCEL TWEEN LEANTWEEN");

            LeanTest.expect(pauseCount == 0, "ON UPDATE NOT CALLED DURING PAUSE",
                            "expect pause count of 0, but got " + pauseCount);

            yield return(new WaitForEndOfFrame());

            Time.timeScale = 0.25f;
            var tweenTime         = 0.2f;
            var expectedTime      = tweenTime * (1f / Time.timeScale);
            var start             = Time.realtimeSinceStartup;
            var onUpdateWasCalled = false;

            LeanTween.moveX(cube1, -5f, tweenTime).setOnUpdate((float val) => { onUpdateWasCalled = true; })
            .setOnComplete(() =>
            {
                var end  = Time.realtimeSinceStartup;
                var diff = end - start;

                LeanTest.expect(Mathf.Abs(expectedTime - diff) < 0.06f, "SCALED TIMING DIFFERENCE",
                                "expected to complete in roughly " + expectedTime + " but completed in " + diff);
                LeanTest.expect(Mathf.Approximately(cube1.transform.position.x, -5f), "SCALED ENDING POSITION",
                                "expected to end at -5f, but it ended at " + cube1.transform.position.x);
                LeanTest.expect(onUpdateWasCalled, "ON UPDATE FIRED");
            });

            var didGetCorrectOnUpdate = false;

            LeanTween.value(gameObject, new Vector3(1f, 1f, 1f), new Vector3(10f, 10f, 10f), 1f).setOnUpdate(val =>
            {
                didGetCorrectOnUpdate = val.x >= 1f && val.y >= 1f && val.z >= 1f;
            }).setOnComplete(() => { LeanTest.expect(didGetCorrectOnUpdate, "VECTOR3 CALLBACK CALLED"); });

            yield return(new WaitForSeconds(expectedTime));

            Time.timeScale = 1f;

            var ltCount = 0;
            var allGos  = FindObjectsOfType(typeof(GameObject)) as GameObject[];

            foreach (var go in allGos)
            {
                if (go.name == "~LeanTween")
                {
                    ltCount++;
                }
            }
            LeanTest.expect(ltCount == 1, "RESET CORRECTLY CLEANS UP");

            StartCoroutine(lotsOfCancels());
        }
Exemple #27
0
        IEnumerator timeBasedTesting()
        {
            yield return(new WaitForEndOfFrame());

            GameObject cubeNormal = cubeNamed("normalTimeScale");

            // float timeElapsedNormal = Time.time;
            LeanTween.moveX(cubeNormal, 12f, 1.5f).setIgnoreTimeScale(false).setOnComplete(() => {
                timeElapsedNormalTimeScale = Time.time;
            });

            LTDescr[] descr = LeanTween.descriptions(cubeNormal);
            LeanTest.expect(descr.Length >= 0 && descr[0].to.x == 12f, "WE CAN RETRIEVE A DESCRIPTION");

            GameObject cubeIgnore = cubeNamed("ignoreTimeScale");

            LeanTween.moveX(cubeIgnore, 5f, 1.5f).setIgnoreTimeScale(true).setOnComplete(() => {
                timeElapsedIgnoreTimeScale = Time.time;
            });

            yield return(new WaitForSeconds(1.5f));

            LeanTest.expect(Mathf.Abs(timeElapsedNormalTimeScale - timeElapsedIgnoreTimeScale) < 0.7f, "START IGNORE TIMING", "timeElapsedIgnoreTimeScale:" + timeElapsedIgnoreTimeScale + " timeElapsedNormalTimeScale:" + timeElapsedNormalTimeScale);

//			yield return new WaitForSeconds(100f);
            Time.timeScale = 4f;

            int pauseCount = 0;

            LeanTween.value(gameObject, 0f, 1f, 1f).setOnUpdate(( float val ) => {
                pauseCount++;
            }).pause();

            // Bezier should end at exact end position not just 99% close to it
            Vector3[]  roundCirc  = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(-9.1f, 25.1f, 0f), new Vector3(-1.2f, 15.9f, 0f), new Vector3(-25f, 25f, 0f), new Vector3(-25f, 25f, 0f), new Vector3(-50.1f, 15.9f, 0f), new Vector3(-40.9f, 25.1f, 0f), new Vector3(-50f, 0f, 0f), new Vector3(-50f, 0f, 0f), new Vector3(-40.9f, -25.1f, 0f), new Vector3(-50.1f, -15.9f, 0f), new Vector3(-25f, -25f, 0f), new Vector3(-25f, -25f, 0f), new Vector3(0f, -15.9f, 0f), new Vector3(-9.1f, -25.1f, 0f), new Vector3(0f, 0f, 0f) };
            GameObject cubeRound  = cubeNamed("bRound");
            Vector3    onStartPos = cubeRound.transform.position;

            LeanTween.moveLocal(cubeRound, roundCirc, 0.5f).setOnComplete(() => {
                LeanTest.expect(cubeRound.transform.position == onStartPos, "BEZIER CLOSED LOOP SHOULD END AT START", "onStartPos:" + onStartPos + " onEnd:" + cubeRound.transform.position);
            });

            // Spline should end at exact end position not just 99% close to it
            Vector3[]  roundSpline      = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(2f, 0f, 0f), new Vector3(0.9f, 2f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f) };
            GameObject cubeSpline       = cubeNamed("bSpline");
            Vector3    onStartPosSpline = cubeSpline.transform.position;

            LeanTween.moveSplineLocal(cubeSpline, roundSpline, 0.5f).setOnComplete(() => {
                LeanTest.expect(Vector3.Distance(onStartPosSpline, cubeSpline.transform.position) <= 0.01f, "SPLINE CLOSED LOOP SHOULD END AT START", "onStartPos:" + onStartPosSpline + " onEnd:" + cubeSpline.transform.position + " dist:" + Vector3.Distance(onStartPosSpline, cubeSpline.transform.position));
            });

            // Groups of tweens testing
            groupTweens    = new LTDescr[1200];
            groupGOs       = new GameObject[groupTweens.Length];
            groupTweensCnt = 0;
            int descriptionMatchCount = 0;

            for (int i = 0; i < groupTweens.Length; i++)
            {
                GameObject cube = cubeNamed("c" + i);
                cube.transform.position = new Vector3(0, 0, i * 3);

                groupGOs[i] = cube;
            }

            yield return(new WaitForEndOfFrame());

            bool hasGroupTweensCheckStarted = false;
            int  setOnStartNum  = 0;
            int  setPosNum      = 0;
            bool setPosOnUpdate = true;

            for (int i = 0; i < groupTweens.Length; i++)
            {
                Vector3 finalPos = transform.position + Vector3.one * 3f;
                Dictionary <string, object> finalDict = new Dictionary <string, object> {
                    { "final", finalPos }, { "go", groupGOs[i] }
                };
                groupTweens[i] = LeanTween.move(groupGOs[i], finalPos, 3f).setOnStart(() => {
                    setOnStartNum++;
                }).setOnUpdate((Vector3 newPosition) => {
                    if (transform.position.z > newPosition.z)
                    {
                        setPosOnUpdate = false;
                    }
//					Debug.LogWarning("New Position: " + newPosition.ToString());
                }).
                                 setOnCompleteParam(finalDict).
                                 setOnComplete((object param) => {
                    Dictionary <string, object> finalDictRetr = param as Dictionary <string, object>;
                    Vector3 neededPos    = (Vector3)finalDictRetr["final"];
                    GameObject tweenedGo = finalDictRetr["go"] as GameObject;
                    if (neededPos.ToString() == tweenedGo.transform.position.ToString())
                    {
                        setPosNum++;
                    }
                    else
                    {
                        Debug.Log("neededPos:" + neededPos + " tweenedGo.transform.position:" + tweenedGo.transform.position);
                    }
                    if (hasGroupTweensCheckStarted == false)
                    {
                        hasGroupTweensCheckStarted = true;
                        LeanTween.delayedCall(gameObject, 0.1f, () => {
                            LeanTest.expect(setOnStartNum == groupTweens.Length, "SETONSTART CALLS", "expected:" + groupTweens.Length + " was:" + setOnStartNum);
                            LeanTest.expect(groupTweensCnt == groupTweens.Length, "GROUP FINISH", "expected " + groupTweens.Length + " tweens but got " + groupTweensCnt);
                            LeanTest.expect(setPosNum == groupTweens.Length, "GROUP POSITION FINISH", "expected " + groupTweens.Length + " tweens but got " + setPosNum);
                            LeanTest.expect(setPosOnUpdate, "GROUP POSITION ON UPDATE");
                        });
                    }
                    groupTweensCnt++;
                });

                if (LeanTween.description(groupTweens[i].id).trans == groupTweens[i].trans)
                {
                    descriptionMatchCount++;
                }
            }

            while (LeanTween.tweensRunning < groupTweens.Length)
            {
                yield return(null);
            }

            LeanTest.expect(descriptionMatchCount == groupTweens.Length, "GROUP IDS MATCH");
            int expectedSearch = groupTweens.Length + 5;

            LeanTest.expect(LeanTween.maxSearch <= expectedSearch, "MAX SEARCH OPTIMIZED", "maxSearch:" + LeanTween.maxSearch + " should be:" + expectedSearch);
            LeanTest.expect(LeanTween.isTweening() == true, "SOMETHING IS TWEENING");

            // resume item before calling pause should continue item along it's way
            float previousXlt4 = cube4.transform.position.x;

            lt4 = LeanTween.moveX(cube4, 5.0f, 1.1f).setOnComplete(() => {
                LeanTest.expect(cube4 != null && previousXlt4 != cube4.transform.position.x, "RESUME OUT OF ORDER", "cube4:" + cube4 + " previousXlt4:" + previousXlt4 + " cube4.transform.position.x:" + (cube4 != null ? cube4.transform.position.x : 0));
            }).setDestroyOnComplete(true);
            lt4.resume();

            rotateRepeat = rotateRepeatAngle = 0;
            LeanTween.rotateAround(cube3, Vector3.forward, 360f, 0.1f).setRepeat(3).setOnComplete(rotateRepeatFinished).setOnCompleteOnRepeat(true).setDestroyOnComplete(true);
            yield return(new WaitForEndOfFrame());

            LeanTween.delayedCall(0.1f * 8f + 1f, rotateRepeatAllFinished);

            int countBeforeCancel = LeanTween.tweensRunning;

            LeanTween.cancel(lt1Id);
            LeanTest.expect(countBeforeCancel == LeanTween.tweensRunning, "CANCEL AFTER RESET SHOULD FAIL", "expected " + countBeforeCancel + " but got " + LeanTween.tweensRunning);
            LeanTween.cancel(cube2);

            int tweenCount = 0;

            for (int i = 0; i < groupTweens.Length; i++)
            {
                if (LeanTween.isTweening(groupGOs[i]))
                {
                    tweenCount++;
                }
                if (i % 3 == 0)
                {
                    LeanTween.pause(groupGOs[i]);
                }
                else if (i % 3 == 1)
                {
                    groupTweens[i].pause();
                }
                else
                {
                    LeanTween.pause(groupTweens[i].id);
                }
            }
            LeanTest.expect(tweenCount == groupTweens.Length, "GROUP ISTWEENING", "expected " + groupTweens.Length + " tweens but got " + tweenCount);

            yield return(new WaitForEndOfFrame());

            tweenCount = 0;
            for (int i = 0; i < groupTweens.Length; i++)
            {
                if (i % 3 == 0)
                {
                    LeanTween.resume(groupGOs[i]);
                }
                else if (i % 3 == 1)
                {
                    groupTweens[i].resume();
                }
                else
                {
                    LeanTween.resume(groupTweens[i].id);
                }

                if (i % 2 == 0 ? LeanTween.isTweening(groupTweens[i].id) : LeanTween.isTweening(groupGOs[i]))
                {
                    tweenCount++;
                }
            }
            LeanTest.expect(tweenCount == groupTweens.Length, "GROUP RESUME");

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "CANCEL TWEEN LTDESCR");
            LeanTest.expect(LeanTween.isTweening(cube2) == false, "CANCEL TWEEN LEANTWEEN");

            LeanTest.expect(pauseCount == 0, "ON UPDATE NOT CALLED DURING PAUSE", "expect pause count of 0, but got " + pauseCount);

            yield return(new WaitForEndOfFrame());

            Time.timeScale = 0.25f;
            float tweenTime         = 0.2f;
            float expectedTime      = tweenTime * (1f / Time.timeScale);
            float start             = Time.realtimeSinceStartup;
            bool  onUpdateWasCalled = false;

            LeanTween.moveX(cube1, -5f, tweenTime).setOnUpdate((float val) => {
                onUpdateWasCalled = true;
            }).setOnComplete(() => {
                float end  = Time.realtimeSinceStartup;
                float diff = end - start;

                LeanTest.expect(Mathf.Abs(expectedTime - diff) < 0.05f, "SCALED TIMING DIFFERENCE", "expected to complete in roughly " + expectedTime + " but completed in " + diff);
                LeanTest.expect(Mathf.Approximately(cube1.transform.position.x, -5f), "SCALED ENDING POSITION", "expected to end at -5f, but it ended at " + cube1.transform.position.x);
                LeanTest.expect(onUpdateWasCalled, "ON UPDATE FIRED");
            });

            bool didGetCorrectOnUpdate = false;

            LeanTween.value(gameObject, new Vector3(1f, 1f, 1f), new Vector3(10f, 10f, 10f), 1f).setOnUpdate(( Vector3 val ) => {
                didGetCorrectOnUpdate = val.x >= 1f && val.y >= 1f && val.z >= 1f;
            }).setOnComplete(() => {
                LeanTest.expect(didGetCorrectOnUpdate, "VECTOR3 CALLBACK CALLED");
            });

            yield return(new WaitForSeconds(expectedTime));

            Time.timeScale = 1f;

            int ltCount = 0;

            GameObject[] allGos = FindObjectsOfType(typeof(GameObject)) as GameObject[];
            foreach (GameObject go in allGos)
            {
                if (go.name == "~LeanTween")
                {
                    ltCount++;
                }
            }
            LeanTest.expect(ltCount == 1, "RESET CORRECTLY CLEANS UP");

            lotsOfCancels();
        }
Exemple #28
0
    /**
     * Add a time delay to the sequence
     * @method add (method(object))
     * @param {System.Action} callback:System.Action method you want to be called
     * @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
     * @example
     * var seq = LeanTween.sequence();<br>
     * seq.append( () => { // fire an event before start<br>
     * &nbsp;Debug.Log("I have started");<br>
     * });<br>
     * seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br>
     * seq.append((object obj) => { // fire event after tween
     * &nbsp;var dict = obj as Dictionary<string,string>;
     * &nbsp;Debug.Log("We are done now obj value:"+dict["hi"]);
     * &nbsp;}, new Dictionary<string,string>(){ {"hi","sup"} } );
     */
    public LTSeq append(System.Action <object> callback, object obj)
    {
        append(LeanTween.delayedCall(0f, callback).setOnCompleteParam(obj));

        return(addOn());
    }
 public void buildAllTweensAgain()
 {
     LeanTween.delayedCall(gameObject, repeatDelay, buildAllTweensAgainNow);
 }