place() public method

public place ( Transform transform, float ratio ) : void
transform Transform
ratio float
return void
Beispiel #1
0
    void Update()
    {
        // Switch tracks on keyboard input
        float turn = Input.GetAxis("Horizontal");

        if (Input.anyKeyDown)
        {
            if (turn < 0f && trackIter > 0)
            {
                trackIter--;
                playSwish();
            }
            else if (turn > 0f && trackIter < 2)
            { // We have three track "rails" so stopping it from going above 3
                trackIter++;
                playSwish();
            }
            // Move the internal local x of the car to simulate changing tracks
            LeanTween.moveLocalX(carInternal, (trackIter - 1) * 6f, 0.3f).setEase(LeanTweenType.easeOutBack);
        }

        // Update avatar's position on correct track
        track.place(car.transform, trackPosition);

        trackPosition += Time.deltaTime * 0.03f; // * Input.GetAxis("Vertical"); // Uncomment to have the forward and backwards controlled by the directional arrows

        if (trackPosition < 0f)                  // We need to keep the ratio between 0-1 so after one we will loop back to the beginning of the track
        {
            trackPosition = 1f;
        }
        else if (trackPosition > 1f)
        {
            trackPosition = 0f;
        }
    }
Beispiel #2
0
 static public int place(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             LTSpline self = (LTSpline)checkSelf(l);
             UnityEngine.Transform a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.place(a1, a2);
             return(0);
         }
         else if (argc == 4)
         {
             LTSpline self = (LTSpline)checkSelf(l);
             UnityEngine.Transform a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             UnityEngine.Vector3 a3;
             checkType(l, 4, out a3);
             self.place(a1, a2, a3);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Beispiel #3
0
    static int place(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(LTSpline), typeof(UnityEngine.Transform), typeof(float)))
            {
                LTSpline obj = (LTSpline)ToLua.ToObject(L, 1);
                UnityEngine.Transform arg0 = (UnityEngine.Transform)ToLua.ToObject(L, 2);
                float arg1 = (float)LuaDLL.lua_tonumber(L, 3);
                obj.place(arg0, arg1);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(LTSpline), typeof(UnityEngine.Transform), typeof(float), typeof(UnityEngine.Vector3)))
            {
                LTSpline obj = (LTSpline)ToLua.ToObject(L, 1);
                UnityEngine.Transform arg0 = (UnityEngine.Transform)ToLua.ToObject(L, 2);
                float arg1 = (float)LuaDLL.lua_tonumber(L, 3);
                UnityEngine.Vector3 arg2 = ToLua.ToVector3(L, 4);
                obj.place(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: LTSpline.place"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Beispiel #4
0
 static public int place(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             LTSpline self = (LTSpline)checkSelf(l);
             UnityEngine.Transform a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.place(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             LTSpline self = (LTSpline)checkSelf(l);
             UnityEngine.Transform a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             UnityEngine.Vector3 a3;
             checkType(l, 4, out a3);
             self.place(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function place to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Beispiel #5
0
    private void Move()
    {
        resultSpeed = speed * speedFactor;

        if (Input.GetKeyDown(KeyCode.P))
        {
            pause = !pause;
        }
        if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            speed += 0.2f;
        }
        if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            speed -= 0.2f;
        }

        if (track == null || pause)
        {
            return;
        }

        // Update avatar's position on correct track
        if (!done)
        {
            track.place(ObjectFollowing.transform, trackPosition);

            trackPosition += Time.deltaTime * resultSpeed;            // * Input.GetAxis("Vertical"); // Uncomment to have the forward and backwards controlled by the directional arrows
        }
        if (repeat)
        {
            if (trackPosition < 0f)             // We need to keep the ratio between 0-1 so after one we will loop back to the beginning of the track
            {
                trackPosition = 1f;
            }
            else if (trackPosition > 1f)
            {
                trackPosition = 0f;
            }
        }
        else
        {
            if (trackPosition < 0f)
            {
                trackPosition = 0f;
            }
            else if (trackPosition > 1f)
            {
                trackPosition = 1f;
                done          = true;
            }
        }
    }
    void Update()
    {
        float zLastDist = (trackPts[trackPts.Count - 1].z - transform.position.z);

        if (zLastDist < 200f)
        {
            // if the last node is too close we'll add in a new point and refresh the spline
            addRandomTrackPoint();
            refreshSpline();
        }

        // Update avatar's position on correct track
        track.place(car.transform, carIter);
        carIter += carAdd * Time.deltaTime;

        // we'll place the trail renders always a bit in front of the car
        track.place(trackTrailRenderers.transform, carIter + pushTrackAhead);


        // Switch tracks on keyboard input
        float turn = Input.GetAxis("Horizontal");

        if (Input.anyKeyDown)
        {
            if (turn < 0f && trackIter > 0)
            {
                trackIter--;
                playSwish();
            }
            else if (turn > 0f && trackIter < 2)
            {
                // We have three track "rails" so stopping it from going above 3
                trackIter++;
                playSwish();
            }

            // Move the internal local x of the car to simulate changing tracks
            LeanTween.moveLocalX(carInternal, (trackIter - 1) * 6f, 0.3f).setEase(LeanTweenType.easeOutBack);
        }
    }
Beispiel #7
0
        void Start()
        {
//			Time.timeScale = 0.25f;

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

            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();

            // Queue up a bunch of tweens, cancel some of them but expect the remainder to finish
            GameObject[] cubes    = new GameObject[99];
            int[]        tweenIds = new int[cubes.Length];
            for (int i = 0; i < cubes.Length; i++)
            {
                GameObject c = cubeNamed("cancel" + i);
                tweenIds[i] = LeanTween.moveX(c, 100f, 1f).id;
                cubes [i]   = c;
            }
            int onCompleteCount = 0;

            LeanTween.delayedCall(cubes[0], 0.2f, () => {
                for (int 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)
                    {
                        LTDescr 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[] { 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.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((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");
            });

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

            for (int j = 0; j < 2; j++)
            {
                bool isCheckingFrom       = j == 1;
                int  totalTweenTypeLength = (int)LeanTweenType.easeShake;
                for (int i = (int)LeanTweenType.notUsed; i < totalTweenTypeLength; i++)
                {
                    LeanTweenType easeType = (LeanTweenType)i;
                    GameObject    cube     = cubeNamed("cube" + easeType);
                    LTDescr       descr    = LeanTween.moveLocalX(cube, 5, 0.1f).setOnComplete((object obj) => {
                        GameObject 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
            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");
            });

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

            StartCoroutine(timeBasedTesting());
        }
    void Start()
    {
        LeanTest.timeout = 45f;
        LeanTest.expected = 33;

        LeanTween.init(14 + 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();

        LTSpline cr = new LTSpline( 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)} );
        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);

        // 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 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");
            });
        });

        StartCoroutine( timeBasedTesting() );
    }
	void Start () {
		LeanTest.timeout = 45f;
		LeanTest.expected = 31;

		LeanTween.init(10 + 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();


		LTSpline cr = new LTSpline( 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)} );
		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);	

		// 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;
		});

		StartCoroutine( timeBasedTesting() );
	}
        void Start()
        {
            //			Time.timeScale = 0.25f;

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

            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();

            // Queue up a bunch of tweens, cancel some of them but expect the remainder to finish
            GameObject[] cubes = new GameObject[99];
            int[] tweenIds = new int[cubes.Length];
            for (int i = 0; i < cubes.Length; i++) {
                GameObject c = cubeNamed("cancel"+i);
                tweenIds[i] = LeanTween.moveX (c, 100f, 1f).id;
                cubes [i] = c;
            }
            int onCompleteCount = 0;
            LeanTween.delayedCall (cubes[0], 0.2f, () => {
                for (int 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){
                        LTDescr 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[] {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.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( (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() );
        }
Beispiel #11
0
    void Start()
    {
        LeanTest.timeout  = 46f;
        LeanTest.expected = 35;

        LeanTween.init(14 + 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();


        LTSpline cr = new LTSpline(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) });

        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);

        // 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));
            });
        });


        StartCoroutine(timeBasedTesting());
    }
    void Start()
    {
        LeanTest.timeout  = 45f;
        LeanTest.expected = 31;

        LeanTween.init(10 + 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();


        LTSpline cr = new LTSpline(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) });

        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);

        // 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;
        });

        StartCoroutine(timeBasedTesting());
    }
Beispiel #13
0
        void Start()
        {
//			Time.timeScale = 0.25f;

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

            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);
            });
            // 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");
            });

            StartCoroutine(timeBasedTesting());
        }
Beispiel #14
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();

            LTSpline cr = new LTSpline( 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)} );
            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);

            // 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() );
        }
    void Start()
    {
        LeanTest.timeout = 45f;
        LeanTest.expected = 29;

        LeanTween.init(6 + 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" );

        // 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" );

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

        LeanTween.reset();

        LTSpline cr = new LTSpline( 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)} );
        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);

        StartCoroutine( timeBasedTesting() );
    }