description() public static méthode

public static description ( int uniqueId ) : LTDescr,
uniqueId int
Résultat LTDescr,
Exemple #1
0
        public void OnAttnGanUpdateResponse(byte[] receivedBase64Img)
        {
            if (!startText2Image)
            {
                return;
            }
            if (LeanTween.isTweening(plateTweenId))
            {
                return;
            }

            textureSwapCount++;
            if (textureSwapCount % 2 == 1)
            {
                attnGanTextureB.LoadImage(receivedBase64Img);
                currentPlateMaterialTargetBlend = 1;
            }
            else
            {
                attnGanTextureA.LoadImage(receivedBase64Img);
                currentPlateMaterialTargetBlend = 0;
            }

            plateTweenId = LeanTween.value(gameObject, plateMaterial.GetFloat("_Blend"), currentPlateMaterialTargetBlend, .5f)
                           .setOnUpdate((float val) =>
            {
                plateMaterial.SetFloat("_Blend", val);
                plateTransparentMaterial.SetFloat("_Blend", val);
            })
                           .id;

            if (!tableOpeningEnded)
            {
                LTDescr descr = LeanTween.description(plateTweenId);
                descr.setOnComplete(() => {
                    //FadeColorToTexture();
                    tableOpenSequence.StartTableDinner();
                    DisableText2Image();
                });
            }
        }
        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 #3
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 #4
0
    IEnumerator timeBasedTesting()
    {
        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        Time.timeScale = 0.25f;
        float tweenTime         = 0.2f;
        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(tweenTime * (1f / Time.timeScale) - diff) < 0.05f, "SCALED TIMING DIFFERENCE", "expected to complete in roughly 0.8f 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(1.0f));

        Time.timeScale = 1f;

        // 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 = GameObject.CreatePrimitive(PrimitiveType.Cube);
            Destroy(cube.GetComponent(typeof(BoxCollider)) as Component);
            cube.transform.position = new Vector3(0, 0, i * 3);
            cube.name      = "c" + i;
            groupGOs[i]    = cube;
            groupTweens[i] = LeanTween.move(cube, transform.position + Vector3.one * 3f, 0.6f).setOnComplete(groupTweenFinished);

            if (LeanTween.description(groupTweens[i].id).trans == groupTweens[i].trans)
            {
                descriptionMatchCount++;
            }
        }
        LeanTween.delayedCall(gameObject, 0.82f, groupTweensFinished);

        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));
        });
        lt4.resume();

        yield return(new WaitForSeconds(0.1f));

        int countBeforeCancel = LeanTween.tweensRunning;

        lt1.cancel();
        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");



        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");
    }
Exemple #5
0
    IEnumerator timeBasedTesting()
    {
        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

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

        for (int i = 0; i < groupTweens.Length; i++)
        {
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            Destroy(cube.GetComponent(typeof(BoxCollider)) as Component);
            cube.transform.position = new Vector3(0, 0, i * 3);
            cube.name      = "c" + i;
            groupGOs[i]    = cube;
            groupTweens[i] = LeanTween.move(cube, transform.position + Vector3.one * 3f, 0.6f).setOnComplete(groupTweenFinished);

            if (LeanTween.description(groupTweens[i].id).trans == groupTweens[i].trans)
            {
                descriptionMatchCount++;
            }
        }
        LeanTween.delayedCall(0.82f, groupTweensFinished);

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

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

        lt3 = LeanTween.moveX(cube3, 5.0f, 1.1f);
        lt3.resume();

        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        lt1.cancel();
        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.debug("GROUP ISTWEENING", tweenCount == groupTweens.Length, "expected " + groupTweens.Length + " tweens but got " + tweenCount);

        LeanTest.debug("RESUME OUT OF ORDER", previousXLT3 != cube3.transform.position.x, "previousXLT3:" + previousXLT3 + " cube3.transform.position.x:" + cube3.transform.position.x);

        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.debug("GROUP RESUME", tweenCount == groupTweens.Length);

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

        Time.timeScale = 0.25f;
        float start = Time.realtimeSinceStartup;

        LeanTween.moveX(cube1, -5f, 0.2f).setOnComplete(() => {
            float end  = Time.realtimeSinceStartup;
            float diff = end - start;
            LeanTest.debug("SCALED TIMING diff:" + diff, Mathf.Abs(0.8f - diff) < 0.05f, "expected to complete in 0.8f but completed in " + diff);
            LeanTest.debug("SCALED ENDING POSITION", Mathf.Approximately(cube1.transform.position.x, -5f), "expected to end at -5f, but it ended at " + cube1.transform.position.x);
        });
    }
Exemple #6
0
 public static LTDescr LTDesctiption(this Transform self, int uniqueId)
 {
     return(LeanTween.description(uniqueId));
 }
Exemple #7
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());
        }