private void GamePlay_GamestateChanged()
    {
        if (GamePlay.Instance.State == GamePlay.GameplayState.Playing)
        {
            gridColorTweenStartColor = gridColor;

            if (GamePlay.Instance.CurrentPlayer == GamePlay.Instance.DeepOnesPlayer)
            {
                gridTargetColor = Player.DeepOneColorDark;
            }
            else
            {
                gridTargetColor = Player.StrandedColorDark;
            }
            gridTargetColor.a = linesAlpha;

            if (colorTween != null) LeanTween.cancel(colorTween.id);

            colorTween = LeanTween.value(gameObject, (c) => {
                gridColor = c;
               
                for (int i = 0; i < lines.Count; i++)
                {
                    lines[i].SetColors(gridColor, gridColor);
                }
            }, gridColorTweenStartColor, gridTargetColor, 1f);
        }
    }
 public void FillPower()
 {
     StopPower();
     if (m_pValueToDescr != null)
         m_pValueToDescr.cancel();
     m_pValueToDescr = LeanTween.value(GameObject, SetPower, m_fPowerValue, m_slrPowerBar.maxValue, TweeningDefaultTime / m_slrPowerBar.maxValue * (m_slrPowerBar.maxValue - m_fPowerValue));
     //m_pValueToDescr. onUpdateFloat = SetPower;
 }
 public void StartPower()
 {
     m_fLastTweenColor = 1;
     m_bIsPowerBarOn = true;
     if(m_pValueToDescr != null)
         m_pValueToDescr.cancel();
     m_pValueToDescr = null;
 }
 public EnemyMoveTo()
 {
     OnFinish = null;
     ActionObject = null;
     isFixed = true;
     EaseType = LeanTweenType.notUsed;
     tweenDescriptor = null;
 }
Beispiel #5
0
    public void FadeIn(float dur, LeanTweenType trans = LeanTweenType.easeInCubic, Action callback = null)
    {
        if (m_ease != null && LeanTween.isTweening(m_ease.uniqueId))
            LeanTween.cancel(m_ease.uniqueId);

        m_ease = LeanTween.value(gameObject, OnFade, m_blackScreenAlpha, 0, dur).setEase(trans);
        m_ease.onComplete = callback;

    }
 public EnemyRotateTo(RotateToData _data)
 {
     tweenDesc = null;
     angle = _data.angle;
     time = _data.time;
     isAiming = _data.aim;
     ease = (LeanTweenType)Enum.Parse(typeof(LeanTweenType), _data.ease);
     direction = _data.direction;
 }
 public void SetScore(int iScore)
 {
     m_txtScore.text = iScore.ToString();
     if (m_pScorePunchDescr != null)
     {
         m_pScorePunchDescr.cancel();
     }
     m_pScorePunchDescr = LeanTween.moveLocalY(m_txtScore.gameObject, 7, 0.3f).setEase(LeanTweenType.punch);
 }
Beispiel #8
0
    void Start()
    {
        LeanTween.init();

        lt = LeanTween.move(gameObject,100*Vector3.one,2);
        id = lt.id;
        LeanTween.pause(id);

        ff = LeanTween.move(gameObject,Vector3.zero,2);
        fid = ff.id;
        LeanTween.pause(fid);
    }
Beispiel #9
0
    void Start()
    {
        descr = LeanTween.move(go, new Vector3(0f,0,100f), 10f);
        descr.passed = 5f; // this should put it at the midway
        descr.updateNow();
        descr.pause(); // doesn't matter if pause after or before setting descr.passed I think if I set the passed property and paused the next frame it would work

        //		LeanTween.scale(go2, Vector3.one * 4f, 10f).setEasePunch();

        LeanTween.scaleX (go2, (go2.transform.localScale * 1.5f).x, 15f).setEase (LeanTweenType.punch);
        LeanTween.scaleY (go2, (go2.transform.localScale * 1.5f).y, 15f).setEase (LeanTweenType.punch);
        LeanTween.scaleZ (go2, (go2.transform.localScale * 1.5f).z, 15f).setEase (LeanTweenType.punch);
    }
Beispiel #10
0
 public static int constructor(IntPtr l)
 {
     try {
         LTDescr o;
         o=new LTDescr();
         pushValue(l,true);
         pushValue(l,o);
         return 2;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
Beispiel #11
0
 public static int constructor(IntPtr l)
 {
     try {
         LTDescr o;
         o=new LTDescr();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
	void Start () {
		LeanTest.timeout = 7f;
		LeanTest.expected = 24;

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

		// ping pong

		// rotateAround, Repeat, DestroyOnComplete
		rotateRepeat = rotateRepeatAngle = 0;
		LeanTween.rotateAround(cube3, Vector3.forward, 360f, 0.1f).setRepeat(3).setOnComplete(rotateRepeatFinished).setOnCompleteOnRepeat(true).setDestroyOnComplete(true);
		LeanTween.delayedCall(0.1f*8f, rotateRepeatAllFinished);

		// test all onUpdates and onCompletes are removed when tween is initialized

		StartCoroutine( timeBasedTesting() );
	}
    private void GamePlay_GamestateChanged()
    {
        if (GamePlay.Instance.State == GamePlay.GameplayState.Playing)
        {
            if (GamePlay.Instance.CurrentPlayer == GamePlay.Instance.DeepOnesPlayer)
            {
                ambientColor = Player.DeepOneColorLight;
            }
            else
            {
                ambientColor = Player.StrandedColorLight;
            }

            if (ambientColorTween != null) LeanTween.cancel(ambientColorTween.id);

            ambientColorTween = LeanTween.value(gameObject, (v) => {
                RenderSettings.ambientLight = Color.Lerp(RenderSettings.ambientLight, ambientColor, v);
            }, 0, 1, Time.deltaTime * 3f);
        }
        else if (GamePlay.Instance.State == GamePlay.GameplayState.GameOver)
        {
            if (GamePlay.Instance.Winner == GamePlay.Instance.StrandedPlayer)
            {
                lightIntensity = 5;
                lightRange = 40;
                if (ambientColorTween != null) LeanTween.cancel(ambientColorTween.id);

                ambientColorTween = LeanTween.value(gameObject, (v) => {
                    RenderSettings.ambientLight = Color.Lerp(RenderSettings.ambientLight, Color.white, v);
                }, 0, 1, Time.deltaTime * 5f);

                ambientIntensity = 1;
            }
            else 
            {
                lightIntensity = 0.2f;
                lightRange = 4.5f;
                if (ambientColorTween != null) LeanTween.cancel(ambientColorTween.id);

                ambientColorTween = LeanTween.value(gameObject, (v) => {
                    RenderSettings.ambientLight = Color.Lerp(RenderSettings.ambientLight, Color.red, v);
                }, 0, 1, Time.deltaTime * 4f);

                ambientIntensity = 0.2f;
            }
        }
    }
Beispiel #14
0
    public void Trigger()
    {
        if (activeMove == null) {
            Vector3 to;
            if(atOrigin) {
                to = destination;
            } else {
                to = originalPosition;
            }

            activeMove = LeanTween.move(gameObject, to, duration).setOnComplete(() => {
                activeMove = null;
                atOrigin = !atOrigin;
                if(autoMove) {
                    Trigger ();
                }
            });
        }
    }
        public override void ActionStart()
        {
            float _localAngle;
            Vector3 _direction;
            if (isAiming)
            {
                //angle = EnemyManager.Instance.AngleToPlayer(ActionObject);
            }
            if (direction == 0)
            {
                if (ActionObject.transform.rotation.eulerAngles.y > angle)
                {
                    _direction = Vector3.down;
                    _localAngle = ActionObject.transform.rotation.eulerAngles.y - angle;
                }
                else
                {
                    _direction = Vector3.up;
                    _localAngle = angle - ActionObject.transform.rotation.eulerAngles.y;
                }
            }
            else
            {
                _direction = direction == 1 ? Vector3.up : Vector3.down;
                _localAngle = angle;
            }

            if (ease.Equals(LeanTweenType.notUsed))
            {
                tweenDesc = LeanTween.rotateAround(ActionObject, _direction, _localAngle, time).setOnComplete(OnActionFinished);
            }
            else
            {
                tweenDesc = LeanTween.rotateAround(ActionObject, _direction, _localAngle, time).setOnComplete(OnActionFinished).setEase(ease);
            }
        }
Beispiel #16
0
    /**
    * Move a GameObject along a set of bezier curves, in local space
    *
    * @method LeanTween.moveLocal
    * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
    * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle1,Handle2,Point2,...
    * @param {float} time:float The time to complete the tween in
    * @return {LTDescr} LTDescr an object that distinguishes the tween
    * @example
    * <i>Javascript:</i><br>
    * LeanTween.move(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br><br>
    * <i>C#:</i><br>
    * LeanTween.move(gameObject, new Vector3[]{Vector3(0f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,1f)}).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br>
    */
    public static LTDescr moveLocal(GameObject gameObject, Vector3[] to, float time)
    {
        descr = options();
        if(descr.path==null)
        descr.path = new LTBezierPath( to );
        else
        descr.path.setPoints( to );

        return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED_LOCAL, descr );
    }
Beispiel #17
0
 // LeanTween 2.0 Methods
 public static LTDescr options(LTDescr seed)
 {
     Debug.LogError("error this function is no longer used"); return null;
 }
Beispiel #18
0
    public void StopMotion()
    {
        isPlayingAnimation = false;

        if (descrRootPosition != null)
        {
            descrRootPosition.cancel();
            descrRootPosition = null;
        }

        if (descrRootRotation != null)
        {
            descrRootRotation.cancel();
            descrRootRotation = null;
        }

        if (descrChest != null)
        {
            descrChest.cancel();
            descrChest = null;
        }

        if (descrNeck != null)
        {
            descrNeck.cancel();
            descrNeck = null;
        }

        if (descrHead != null)
        {
            descrHead.cancel();
            descrHead = null;
        }

        if (descrThighL != null)
        {
            descrThighL.cancel();
            descrThighL = null;
        }

        if (descrThighR != null)
        {
            descrThighR.cancel();
            descrThighR = null;
        }

        if (descrShinL != null)
        {
            descrShinL.cancel();
            descrShinL = null;
        }

        if (descrShinR != null)
        {
            descrShinR.cancel();
            descrShinR = null;
        }

        if (descrFootL != null)
        {
            descrFootL.cancel();
            descrFootL = null;
        }

        if (descrFootR != null)
        {
            descrFootR.cancel();
            descrFootR = null;
        }

        if (descrShoulderL != null)
        {
            descrShoulderL.cancel();
            descrShoulderL = null;
        }

        if (descrShoulderR != null)
        {
            descrShoulderR.cancel();
            descrShoulderR = null;
        }

        if (descrUpperArmL != null)
        {
            descrUpperArmL.cancel();
            descrUpperArmL = null;
        }

        if (descrUpperArmR != null)
        {
            descrUpperArmR.cancel();
            descrUpperArmR = null;
        }

        if (descrForearmL != null)
        {
            descrForearmL.cancel();
            descrForearmL = null;
        }

        if (descrForearmR != null)
        {
            descrForearmR.cancel();
            descrForearmR = null;
        }

        if (descrHandL != null)
        {
            descrHandL.cancel();
            descrHandL = null;
        }

        if (descrHandR != null)
        {
            descrHandR.cancel();
            descrHandR = null;
        }
    }
Beispiel #19
0
        private void HandleTween()
        {
            _tweenObject = null;
            switch (animationType)
            {
            case UIAnimationTypes.Fade:
                Fade();
                break;

            case UIAnimationTypes.Move:
                MoveAbsolute();
                break;

            case UIAnimationTypes.Scale:
                Scale();
                break;

            case UIAnimationTypes.ScaleX:
                from = new Vector3(from.x, transform.localScale.y, transform.localScale.z);
                to   = new Vector3(to.x, transform.localScale.y, transform.localScale.z);
                Scale();
                break;

            case UIAnimationTypes.ScaleY:
                from = new Vector3(transform.localScale.x, from.y, transform.localScale.z);
                to   = new Vector3(transform.localScale.x, to.y, transform.localScale.z);
                Scale();
                break;

            case UIAnimationTypes.Rect:
                Rect();
                break;
            }

            var delayResult = delay;

            if (multiplyDelayByChildIndex)
            {
                delayResult = delay * transform.GetSiblingIndex();
            }

            _tweenObject.setDelay(delayResult);

            if ((delayResult >= 0f) && hideDuringDelay)
            {
                CanvasGroup group = objectToAnimate.GetComponent <CanvasGroup>();
                if (group == null)
                {
                    group = objectToAnimate.AddComponent <CanvasGroup>();
                }

                group.alpha = 0;
                //Show the object when it starts
                _tweenObject.setOnStart(() =>
                {
                    group.alpha = 1;
                });
            }

            _tweenObject.setEase(easeType);

            if (loop)
            {
                _tweenObject.loopCount = int.MaxValue;
            }
            if (pingpong)
            {
                _tweenObject.setLoopPingPong();
            }
            if (onComplete != null)
            {
                _tweenObject.setOnComplete(onComplete);
            }
        }
Beispiel #20
0
    void bigGuyJump()
    {
        float height = Mathf.PerlinNoise(jumpIter, 0f) * 10f;

        height = height * height * 0.3f;
        // Debug.Log("height:"+height+" jumpIter:"+jumpIter);

        LeanTween.moveY(avatarBig, height, 1f).setEase(LeanTweenType.easeInOutQuad).setOnComplete(() =>
        {
            LeanTween.moveY(avatarBig, 0f, 0.27f).setEase(LeanTweenType.easeInQuad).setOnComplete(() =>
            {
                LeanTween.cancel(gameObject);

                /**************
                * Camera Shake
                **************/

                float shakeAmt        = height * 0.2f;                    // the degrees to shake the camera
                float shakePeriodTime = 0.42f;                            // The period of each shake
                float dropOffTime     = 1.6f;                             // How long it takes the shaking to settle down to nothing
                LTDescr shakeTween    = LeanTween.rotateAroundLocal(gameObject, Vector3.right, shakeAmt, shakePeriodTime)
                                        .setEase(LeanTweenType.easeShake) // this is a special ease that is good for shaking
                                        .setLoopClamp()
                                        .setRepeat(-1);

                // Slow the camera shake down to zero
                LeanTween.value(gameObject, shakeAmt, 0f, dropOffTime).setOnUpdate(
                    (float val) =>
                {
                    shakeTween.setTo(Vector3.right * val);
                }
                    ).setEase(LeanTweenType.easeOutQuad);


                /********************
                * Shake scene objects
                ********************/

                // Make the boxes jump from the big stomping
                GameObject[] boxes = GameObject.FindGameObjectsWithTag("Respawn"); // I just arbitrarily tagged the boxes with this since it was available in the scene
                foreach (GameObject box in boxes)
                {
                    box.GetComponent <Rigidbody>().AddForce(Vector3.up * 100 * height);
                }

                // Make the lamps spin from the big stomping
                GameObject[] lamps = GameObject.FindGameObjectsWithTag("GameController"); // I just arbitrarily tagged the lamps with this since it was available in the scene
                foreach (GameObject lamp in lamps)
                {
                    float z = lamp.transform.eulerAngles.z;
                    z       = z > 0.0f && z < 180f ? 1 : -1; // push the lamps in whatever direction they are currently swinging
                    lamp.GetComponent <Rigidbody>().AddForce(new Vector3(z, 0f, 0f) * 15 * height);
                }

                // Play BOOM!
                LeanAudio.play(boomAudioClip, transform.position, height * 0.2f); // Like this sound? : http://leanaudioplay.dentedpixel.com/?d=a:fvb:8,0,0.003005181,0,0,0.01507768,0.002227979,0,0,8~8,8.130963E-06,0.06526042,0,-1,0.0007692695,2.449077,9.078861,9.078861,0.01541314,0.9343268,-40,-40,0.05169491,0.03835937,-0.08621139,-0.08621139,8~0.1,0,0,~44100

                // Have the jump happen again 2 seconds from now
                LeanTween.delayedCall(2f, bigGuyJump);
            });
        });
        jumpIter += 5.2f;
    }
        void Start()
        {
//			Time.timeScale = 0.25f;

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

            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());
        }
Beispiel #22
0
 private void StartTween()
 {
     _animationTween = LeanTween.value(0f, _tiling, _loopInSeconds).setLoopClamp().setOnUpdate(tiling =>
                                                                                               MovementUtils.SetTexturePosition(_material, _textureId, _materialXOffset, -tiling)).setDelay(_delayBeforeStart);
 }
 public void Flash()
 {
     SetShineAlpha(1);
     shineTween = LeanTween.value(gameObject, SetShineAlpha, 1, 0, 0.5f);
 }
    void Update()
    {
        LeanTween.dtManual = Time.deltaTime;
        if (Input.GetKeyDown(KeyCode.Q))
        {
            //LeanTween.scale(this.gameObject, Vector3.one*3f, 1.0f).setEase(LeanTweenType.easeSpring).setUseManualTime(true);
            //print("scale punch time independent!");

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

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

            LeanTween.value(lt.gameObject, lt.intensity, 0.0f, 1.5f)
            .setEase(LeanTweenType.linear)
            .setLoopPingPong()
            .setRepeat(-1)
            .setOnUpdate((float val) => { lt.intensity = val; });
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            print("scale punch!");

            tweenStatically(this.gameObject);

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

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

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

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

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

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

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

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

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

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

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

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

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

            GameObject l = GameObject.Find("LCharacter");
            Debug.Log("x:" + l.transform.position.x + " y:" + l.transform.position.y);
            LeanTween.value(l, new Vector2(l.transform.position.x, l.transform.position.y),
                            new Vector2(l.transform.position.x, l.transform.position.y + 5), 1f).setOnUpdate(
                (Vector2 val) =>
            {
                Debug.Log("tweening vec2 val:" + val);
                l.transform.position = new Vector3(val.x, val.y, transform.position.z);
            }
                );
#endif
        }
    }
        public void TransitionToState(AnimationStateNode newState, float transitionTime, AnimationCurve transitionCurve)
        {
            lock (transitioningLock)
            {
                if (transitioning)
                {
                    transitionTween.callOnCompletes();
                    // transitionTween.setOnUpdate((float value) => { }).setOnComplete(() => { });
                    LeanTween.cancel(transitionTween.id);
                }
            }

            mixerRunner.Output.DisconnectInput(0);
            mixerRunner.Output.DisconnectInput(1);
            // if (!mixerPlayable.GetInput(0).IsNull()) mixerPlayable.DisconnectInput(0);
            // if (!mixerPlayable.GetInput(1).IsNull()) mixerPlayable.DisconnectInput(1);

            activeState     = nextActiveState;
            nextActiveState = newState;

            // Debug.Log($"Transition from {activeState?.name} to {nextActiveState?.name}, {newState.Output.IsValid()}, {newState.Output.GetInputCount()}");

            if (nextActiveState)
            {
                mixerRunner.Output.ConnectInput(0, nextActiveState.Output, 0);
            }
            else
            {
                mixerRunner.Output.ConnectInput(0, defaultPlayable, 0);
            }

            if (activeState)
            {
                mixerRunner.Output.ConnectInput(1, activeState.Output, 0);
            }

            mixerRunner.Output.SetInputWeight(0, 1f);
            mixerRunner.Output.SetInputWeight(1, 1f);

            if (nextActiveState != null)
            {
                transitioning = true;
                mixerRunner.SetBlendFromLastPosition(true);

                transitionTween =
                    LeanTween
                    .value(sharedData.Animatable.RootTransform.gameObject, 0f, 1f, transitionTime)
                    .setEase(transitionCurve)
                    .setOnStart(() =>
                {
                    // transitioning = true;
                    // mixerRunner.SetBlendFromLastPosition(true);
                    //Debug.Log($"Start tween from {activeState?.name} to {nextActiveState?.name}");
                })
                    .setOnUpdate((float value) =>
                {
                    mixerRunner.Factor = value;
                    //Debug.Log($"Update tween value {mixerRunner.Factor}");
                })
                    .setOnComplete(() =>
                {
                    lock (transitioningLock)
                    {
                        transitioning = false;
                    }
                    mixerRunner.SetBlendFromLastPosition(false);
                    //Debug.Log($"Complete tween from {activeState?.name} to {nextActiveState?.name}");
                });
            }

            // sharedData.Animatable.playableOutput.SetSourcePlayable(newState.Output);

            // mixerRunner.Factor = 0.0f;
        }
    IEnumerator timeBasedTesting()
    {
        yield return(new WaitForSeconds(1));

        yield return(new WaitForEndOfFrame());

        LeanTest.expect(Mathf.Abs(timeElapsedNormalTimeScale - timeElapsedIgnoreTimeScale) < 0.07f, "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));
        });
        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();
    }
Beispiel #27
0
 private static float tweenOnCurve(LTDescr tweenDescr, float ratioPassed)
 {
     // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed));
     return(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed));
 }
 // Start is called before the first frame update
 void Start()
 {
     desc = LeanTween.value(gameObject, 0, 1, compSecs).setOnUpdate(UpdateValue).setOnComplete(Complete).setEase(ease);
     LeanTween.value(gameObject, 0, 1, compSecs).setOnUpdate(UpdateValue1).setOnComplete(Complete1).setEase(ease);
 }
Beispiel #29
0
    public bool Flip(bool toLeft = true, float speedMultiplier = 1)
    {
        int desiredIndex = (toLeft? index + 1 : index - 1);

        if (0 > desiredIndex || desiredIndex >= presets.Count)
        {
            return(false);
        }

        Poser  currentPoser  = CurrentPoser();
        Preset currentPreset = CurrentPreset();

        if (currentPreset.Pose != null)
        {
            currentPoser.StopMotion();
            currentPoser.ApplyPose(currentPreset.Pose, FLIP_DURATION / speedMultiplier / 2);
        }

        index = desiredIndex;

        int tweenSlotBeginIndex = 0;
        int tweenSlotEndIndex   = 0;
        int lastSlotIndex       = SlotsNum - 1;

        if (toLeft)
        {
            tweenSlotBeginIndex = 1;
            tweenSlotEndIndex   = lastSlotIndex;
        }
        else
        {
            tweenSlotBeginIndex = 0;
            tweenSlotEndIndex   = lastSlotIndex - 1;
        }

        for (int i = tweenSlotBeginIndex; i <= tweenSlotEndIndex; i++)
        {
            int     newIndex    = i + (toLeft? -1 : +1);
            Vector3 newPosition = GetSlotPosition(newIndex);
            LTDescr tween       = LeanTween.moveLocal(slots[i].gameObject, newPosition, FLIP_DURATION / speedMultiplier).setEase(LeanTweenType.easeInOutCubic);
            if (i == CenterSlot)
            {
                tween.setOnComplete(OnCenterSlotFlipComplete);
            }
        }

        int   poppingSlotIndex = (toLeft? 0 : lastSlotIndex);
        Poser reusedSlot       = slots[poppingSlotIndex];

        slots.RemoveAt(poppingSlotIndex);

        int halfSlotsNum        = SlotsNum / 2;
        int endPointPresetIndex = index + (toLeft? halfSlotsNum : -halfSlotsNum);

        reusedSlot.ApplyPreset(presets.Get(endPointPresetIndex));

        int pushingSlotIndex = (toLeft? lastSlotIndex : 0);

        slots.Insert(pushingSlotIndex, reusedSlot);

        reusedSlot.transform.localPosition = GetSlotPosition(pushingSlotIndex);

        return(true);
    }
	public static void update()
	{
		if (frameRendered != Time.frameCount)
		{ // make sure update is only called once per frame
			init();

#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
		dtEstimated = Time.realtimeSinceStartup - previousRealTime;
		if(dtEstimated>0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large
			dtEstimated = 0.2f;
		previousRealTime = Time.realtimeSinceStartup;
#else
			dtEstimated = Time.unscaledDeltaTime;
#endif

			dtActual = Time.deltaTime;
			maxTweenReached = 0;
			finishedCnt = 0;
			// if(tweenMaxSearch>1500)
			// Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens);
			for (int i = 0; i <= tweenMaxSearch && i < maxTweens; i++)
			{

				//if(i==0 && tweens[i].toggle)
				//	Debug.Log("tweens["+i+"]"+tweens[i]+" dt:"+dt);
				if (tweens[i].toggle)
				{
					maxTweenReached = i;
					tween = tweens[i];
					trans = tween.trans;
					timeTotal = tween.time;
					tweenAction = tween.type;

					/*if(trans.gameObject.name=="Main Camera"){
						Debug.Log("main tween:"+tween+" i:"+i);
					}*/

					if (tween.useEstimatedTime)
					{
						dt = dtEstimated;
					}
					else if (tween.useFrames)
					{
						dt = 1;
					}
					else if (tween.useManualTime)
					{
						dt = dtManual;
					}
					else if (tween.direction == 0f)
					{
						dt = 0f;
					}
					else
					{
						dt = dtActual;
					}

					if (trans == null)
					{
						removeTween(i);
						continue;
					}
					// Debug.Log("i:"+i+" tween:"+tween+" dt:"+dt);

					// Check for tween finished
					isTweenFinished = false;
					if (tween.delay <= 0)
					{
						if ((tween.passed + dt > tween.time && tween.direction > 0.0f))
						{
							// Debug.Log("i:"+i+" passed:"+tween.passed+" dt:"+dt+" time:"+tween.time+" dir:"+tween.direction);
							isTweenFinished = true;
							tween.passed = tween.time; // Set to the exact end time so that it can finish tween exactly on the end value
						}
						else if (tween.direction < 0.0f && tween.passed - dt < 0.0f)
						{
							isTweenFinished = true;
							tween.passed = Mathf.Epsilon;
						}
					}

					if (!tween.hasInitiliazed && ((tween.passed == 0.0 && tween.delay == 0.0) || tween.passed > 0.0))
					{
						tween.init();
					}

					if (tween.delay <= 0)
					{
						// Move Values
						if (timeTotal <= 0f)
						{
							//Debug.LogError("time total is zero Time.timeScale:"+Time.timeScale+" useEstimatedTime:"+tween.useEstimatedTime);
							ratioPassed = 1f;
						}
						else
						{
							ratioPassed = tween.passed / timeTotal;
						}

						if (ratioPassed > 1.0f)
						{
							ratioPassed = 1.0f;
						}
						else if (ratioPassed < 0f)
						{
							ratioPassed = 0f;
						}
						// Debug.Log("action:"+tweenAction+" ratioPassed:"+ratioPassed + " timeTotal:" + timeTotal + " tween.passed:"+ tween.passed +" dt:"+dt);

						if (tweenAction >= TweenAction.MOVE_X && tweenAction < TweenAction.MOVE)
						{
							if (tween.animationCurve != null)
							{
								val = tweenOnCurve(tween, ratioPassed);
							}
							else
							{
								switch (tween.tweenType)
								{
									case LeanTweenType.linear:
										val = tween.from.x + tween.diff.x * ratioPassed; break;
									case LeanTweenType.easeOutQuad:
										val = easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
									case LeanTweenType.easeInQuad:
										val = easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
									case LeanTweenType.easeInOutQuad:
										val = easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
									case LeanTweenType.easeInCubic:
										val = easeInCubic(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeOutCubic:
										val = easeOutCubic(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInOutCubic:
										val = easeInOutCubic(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInQuart:
										val = easeInQuart(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeOutQuart:
										val = easeOutQuart(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInOutQuart:
										val = easeInOutQuart(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInQuint:
										val = easeInQuint(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeOutQuint:
										val = easeOutQuint(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInOutQuint:
										val = easeInOutQuint(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInSine:
										val = easeInSine(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeOutSine:
										val = easeOutSine(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInOutSine:
										val = easeInOutSine(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInExpo:
										val = easeInExpo(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeOutExpo:
										val = easeOutExpo(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInOutExpo:
										val = easeInOutExpo(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInCirc:
										val = easeInCirc(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeOutCirc:
										val = easeOutCirc(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInOutCirc:
										val = easeInOutCirc(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInBounce:
										val = easeInBounce(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeOutBounce:
										val = easeOutBounce(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInOutBounce:
										val = easeInOutBounce(tween.from.x, tween.to.x, ratioPassed); break;
									case LeanTweenType.easeInBack:
										val = easeInBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot); break;
									case LeanTweenType.easeOutBack:
										val = easeOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot); break;
									case LeanTweenType.easeInOutBack:
										val = easeInOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot); break;
									case LeanTweenType.easeInElastic:
										val = easeInElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period); break;
									case LeanTweenType.easeOutElastic:
										val = easeOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period); break;
									case LeanTweenType.easeInOutElastic:
										val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period); break;
									case LeanTweenType.punch:
									case LeanTweenType.easeShake:
										if (tween.tweenType == LeanTweenType.punch)
										{
											tween.animationCurve = LeanTween.punch;
										}
										else if (tween.tweenType == LeanTweenType.easeShake)
										{
											tween.animationCurve = LeanTween.shake;
										}
										tween.to.x = tween.from.x + tween.to.x;
										tween.diff.x = tween.to.x - tween.from.x;
										val = tweenOnCurve(tween, ratioPassed); break;
									case LeanTweenType.easeSpring:
										val = spring(tween.from.x, tween.to.x, ratioPassed); break;
									default:
										{
											val = tween.from.x + tween.diff.x * ratioPassed; break;
										}
								}

							}

							// Debug.Log("from:"+from+" val:"+val+" ratioPassed:"+ratioPassed);
							if (tweenAction == TweenAction.MOVE_X)
							{
								trans.position = new Vector3(val, trans.position.y, trans.position.z);
							}
							else if (tweenAction == TweenAction.MOVE_Y)
							{
								trans.position = new Vector3(trans.position.x, val, trans.position.z);
							}
							else if (tweenAction == TweenAction.MOVE_Z)
							{
								trans.position = new Vector3(trans.position.x, trans.position.y, val);
							}
							if (tweenAction == TweenAction.MOVE_LOCAL_X)
							{
								trans.localPosition = new Vector3(val, trans.localPosition.y, trans.localPosition.z);
							}
							else if (tweenAction == TweenAction.MOVE_LOCAL_Y)
							{
								trans.localPosition = new Vector3(trans.localPosition.x, val, trans.localPosition.z);
							}
							else if (tweenAction == TweenAction.MOVE_LOCAL_Z)
							{
								trans.localPosition = new Vector3(trans.localPosition.x, trans.localPosition.y, val);
							}
							else if (tweenAction == TweenAction.MOVE_CURVED)
							{
								if (tween.path.orientToPath)
								{
									if (tween.path.orientToPath2d)
									{
										tween.path.place2d(trans, val);
									}
									else
									{
										tween.path.place(trans, val);
									}
								}
								else
								{
									trans.position = tween.path.point(val);
								}
								// Debug.Log("val:"+val+" trans.position:"+trans.position + " 0:"+ tween.curves[0] +" 1:"+tween.curves[1] +" 2:"+tween.curves[2] +" 3:"+tween.curves[3]);
							}
							else if ((TweenAction)tweenAction == TweenAction.MOVE_CURVED_LOCAL)
							{
								if (tween.path.orientToPath)
								{
									if (tween.path.orientToPath2d)
									{
										tween.path.placeLocal2d(trans, val);
									}
									else
									{
										tween.path.placeLocal(trans, val);
									}
								}
								else
								{
									trans.localPosition = tween.path.point(val);
								}
								// Debug.Log("val:"+val+" trans.position:"+trans.position);
							}
							else if (tweenAction == TweenAction.MOVE_SPLINE)
							{
								if (tween.spline.orientToPath)
								{
									if (tween.spline.orientToPath2d)
									{
										tween.spline.place2d(trans, val);
									}
									else
									{
										tween.spline.place(trans, val);
									}
								}
								else
								{
									trans.position = tween.spline.point(val);
								}
							}
							else if (tweenAction == TweenAction.MOVE_SPLINE_LOCAL)
							{
								if (tween.spline.orientToPath)
								{
									if (tween.spline.orientToPath2d)
									{
										tween.spline.placeLocal2d(trans, val);
									}
									else
									{
										tween.spline.placeLocal(trans, val);
									}
								}
								else
								{
									trans.localPosition = tween.spline.point(val);
								}
							}
							else if (tweenAction == TweenAction.SCALE_X)
							{
								trans.localScale = new Vector3(val, trans.localScale.y, trans.localScale.z);
							}
							else if (tweenAction == TweenAction.SCALE_Y)
							{
								trans.localScale = new Vector3(trans.localScale.x, val, trans.localScale.z);
							}
							else if (tweenAction == TweenAction.SCALE_Z)
							{
								trans.localScale = new Vector3(trans.localScale.x, trans.localScale.y, val);
							}
							else if (tweenAction == TweenAction.ROTATE_X)
							{
								trans.eulerAngles = new Vector3(val, trans.eulerAngles.y, trans.eulerAngles.z);
							}
							else if (tweenAction == TweenAction.ROTATE_Y)
							{
								trans.eulerAngles = new Vector3(trans.eulerAngles.x, val, trans.eulerAngles.z);
							}
							else if (tweenAction == TweenAction.ROTATE_Z)
							{
								trans.eulerAngles = new Vector3(trans.eulerAngles.x, trans.eulerAngles.y, val);
							}
							else if (tweenAction == TweenAction.ROTATE_AROUND)
							{
								Vector3 origPos = trans.localPosition;
								Vector3 rotateAroundPt = (Vector3)trans.TransformPoint(tween.point);
								trans.RotateAround(rotateAroundPt, tween.axis, -val);
								Vector3 diff = origPos - trans.localPosition;

								trans.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
								trans.rotation = tween.origRotation;

								rotateAroundPt = (Vector3)trans.TransformPoint(tween.point);
								trans.RotateAround(rotateAroundPt, tween.axis, val);

								//GameObject cubeMarker = GameObject.Find("TweenRotatePoint");
								//cubeMarker.transform.position = rotateAroundPt;

							}
							else if (tweenAction == TweenAction.ROTATE_AROUND_LOCAL)
							{
								Vector3 origPos = trans.localPosition;
								trans.RotateAround((Vector3)trans.TransformPoint(tween.point), trans.TransformDirection(tween.axis), -val);
								Vector3 diff = origPos - trans.localPosition;

								trans.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
								trans.localRotation = tween.origRotation;
								Vector3 rotateAroundPt = (Vector3)trans.TransformPoint(tween.point);
								trans.RotateAround(rotateAroundPt, trans.TransformDirection(tween.axis), val);

								//GameObject cubeMarker = GameObject.Find("TweenRotatePoint");
								//cubeMarker.transform.position = rotateAroundPt;

							}
							else if (tweenAction == TweenAction.ALPHA)
							{
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2

					    	if(trans.gameObject.renderer){
								foreach(Material mat in trans.gameObject.renderer.materials){
	        						mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val);
	    						}
							}
							if(trans.childCount>0){
								foreach (Transform child in trans) {
									if(child.gameObject.renderer!=null){
										foreach(Material mat in child.gameObject.renderer.materials){
			        						mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val);
			    						}
			    					}
								}
							}

#else

								SpriteRenderer ren = trans.gameObject.GetComponent<SpriteRenderer>();

								if (ren != null)
								{
									ren.color = new Color(ren.color.r, ren.color.g, ren.color.b, val);
								}
								else
								{
									if (trans.gameObject.GetComponent<Renderer>() != null)
									{
										foreach (Material mat in trans.gameObject.GetComponent<Renderer>().materials)
										{
											if (mat.HasProperty("_Color"))
											{
												mat.color = new Color(mat.color.r, mat.color.g, mat.color.b, val);
											}
											else if (mat.HasProperty("_TintColor"))
											{
												Color col = mat.GetColor("_TintColor");
												mat.SetColor("_TintColor", new Color(col.r, col.g, col.b, val));
											}
										}
									}
									if (trans.childCount > 0)
									{
										foreach (Transform child in trans)
										{
											if (child.gameObject.GetComponent<Renderer>() != null)
											{
												foreach (Material mat in child.gameObject.GetComponent<Renderer>().materials)
												{
													mat.color = new Color(mat.color.r, mat.color.g, mat.color.b, val);
												}
											}
										}
									}
								}

#endif
							}
							else if (tweenAction == TweenAction.ALPHA_VERTEX)
							{
								Mesh mesh = trans.GetComponent<MeshFilter>().mesh;
								Vector3[] vertices = mesh.vertices;
								Color32[] colors = new Color32[vertices.Length];
								Color32 c = mesh.colors32[0];
								c = new Color(c.r, c.g, c.b, val);
								for (int k = 0; k < vertices.Length; k++)
								{
									colors[k] = c;
								}
								mesh.colors32 = colors;
							}
							else if (tweenAction == TweenAction.COLOR || tweenAction == TweenAction.CALLBACK_COLOR)
							{
								Color toColor = tweenColor(tween, val);

#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
								SpriteRenderer ren = trans.gameObject.GetComponent<SpriteRenderer>();
								if (ren != null)
								{
									ren.color = toColor;
								}
								else
								{
#endif
									// Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
									if (tweenAction == TweenAction.COLOR)
									{
										if (trans.gameObject.GetComponent<Renderer>() != null)
										{
											foreach (Material mat in trans.gameObject.GetComponent<Renderer>().materials)
											{
												mat.color = toColor;
											}
										}
										if (trans.childCount > 0)
										{
											foreach (Transform child in trans)
											{
												if (child.gameObject.GetComponent<Renderer>() != null)
												{
													foreach (Material mat in child.gameObject.GetComponent<Renderer>().materials)
													{
														mat.color = toColor;
													}
												}
											}
										}
									}
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
								}
#endif
								if (dt != 0f && tween.onUpdateColor != null)
								{
									tween.onUpdateColor(toColor);
								}
							}
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
							else if (tweenAction == TweenAction.CANVAS_ALPHA)
							{
								Color c = tween.uiImage.color;
								c.a = val;
								tween.uiImage.color = c;
							}
							else if (tweenAction == TweenAction.CANVAS_COLOR)
							{
								Color toColor = tweenColor(tween, val);
								tween.uiImage.color = toColor;
								if (dt != 0f && tween.onUpdateColor != null)
								{
									tween.onUpdateColor(toColor);
								}
							}
							else if (tweenAction == TweenAction.TEXT_ALPHA)
							{
								textAlphaRecursive(trans, val);
							}
							else if (tweenAction == TweenAction.TEXT_COLOR)
							{
								Color toColor = tweenColor(tween, val);
								tween.uiText.color = toColor;
								if (dt != 0f && tween.onUpdateColor != null)
								{
									tween.onUpdateColor(toColor);
								}
								if (trans.childCount > 0)
								{
									foreach (Transform child in trans)
									{
										UnityEngine.UI.Text uiText = child.gameObject.GetComponent<UnityEngine.UI.Text>();
										if (uiText != null)
										{
											uiText.color = toColor;
										}
									}
								}
							}
							else if (tweenAction == TweenAction.CANVAS_ROTATEAROUND)
							{
								// figure out how much the rotation has shifted the object over
								RectTransform rect = tween.rectTransform;
								Vector3 origPos = rect.localPosition;
								rect.RotateAround((Vector3)rect.TransformPoint(tween.point), tween.axis, -val);
								Vector3 diff = origPos - rect.localPosition;

								rect.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
								rect.rotation = tween.origRotation;
								rect.RotateAround((Vector3)rect.TransformPoint(tween.point), tween.axis, val);
							}
							else if (tweenAction == TweenAction.CANVAS_ROTATEAROUND_LOCAL)
							{
								// figure out how much the rotation has shifted the object over
								RectTransform rect = tween.rectTransform;
								Vector3 origPos = rect.localPosition;
								rect.RotateAround((Vector3)rect.TransformPoint(tween.point), rect.TransformDirection(tween.axis), -val);
								Vector3 diff = origPos - rect.localPosition;

								rect.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position
								rect.rotation = tween.origRotation;
								rect.RotateAround((Vector3)rect.TransformPoint(tween.point), rect.TransformDirection(tween.axis), val);
							}
							else if (tweenAction == TweenAction.CANVAS_PLAYSPRITE)
							{
								int frame = (int)Mathf.Round(val);
								// Debug.Log("frame:"+frame+" val:"+val);
								tween.uiImage.sprite = tween.sprites[frame];
							}
							else if (tweenAction == TweenAction.CANVAS_MOVE_X)
							{
								Vector3 current = tween.rectTransform.anchoredPosition3D;
								tween.rectTransform.anchoredPosition3D = new Vector3(val, current.y, current.z);
							}
							else if (tweenAction == TweenAction.CANVAS_MOVE_Y)
							{
								Vector3 current = tween.rectTransform.anchoredPosition3D;
								tween.rectTransform.anchoredPosition3D = new Vector3(current.x, val, current.z);
							}
							else if (tweenAction == TweenAction.CANVAS_MOVE_Z)
							{
								Vector3 current = tween.rectTransform.anchoredPosition3D;
								tween.rectTransform.anchoredPosition3D = new Vector3(current.x, current.y, val);
							}
#endif

						}
						else if (tweenAction >= TweenAction.MOVE)
						{
							//

							if (tween.animationCurve != null)
							{
								newVect = tweenOnCurveVector(tween, ratioPassed);
							}
							else
							{
								if (tween.tweenType == LeanTweenType.linear)
								{
									newVect = new Vector3(tween.from.x + tween.diff.x * ratioPassed, tween.from.y + tween.diff.y * ratioPassed, tween.from.z + tween.diff.z * ratioPassed);
								}
								else if (tween.tweenType >= LeanTweenType.linear)
								{
									switch (tween.tweenType)
									{
										case LeanTweenType.easeOutQuad:
											newVect = new Vector3(easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
										case LeanTweenType.easeInQuad:
											newVect = new Vector3(easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
										case LeanTweenType.easeInOutQuad:
											newVect = new Vector3(easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
										case LeanTweenType.easeInCubic:
											newVect = new Vector3(easeInCubic(tween.from.x, tween.to.x, ratioPassed), easeInCubic(tween.from.y, tween.to.y, ratioPassed), easeInCubic(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutCubic:
											newVect = new Vector3(easeOutCubic(tween.from.x, tween.to.x, ratioPassed), easeOutCubic(tween.from.y, tween.to.y, ratioPassed), easeOutCubic(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInOutCubic:
											newVect = new Vector3(easeInOutCubic(tween.from.x, tween.to.x, ratioPassed), easeInOutCubic(tween.from.y, tween.to.y, ratioPassed), easeInOutCubic(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInQuart:
											newVect = new Vector3(easeInQuart(tween.from.x, tween.to.x, ratioPassed), easeInQuart(tween.from.y, tween.to.y, ratioPassed), easeInQuart(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutQuart:
											newVect = new Vector3(easeOutQuart(tween.from.x, tween.to.x, ratioPassed), easeOutQuart(tween.from.y, tween.to.y, ratioPassed), easeOutQuart(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInOutQuart:
											newVect = new Vector3(easeInOutQuart(tween.from.x, tween.to.x, ratioPassed), easeInOutQuart(tween.from.y, tween.to.y, ratioPassed), easeInOutQuart(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInQuint:
											newVect = new Vector3(easeInQuint(tween.from.x, tween.to.x, ratioPassed), easeInQuint(tween.from.y, tween.to.y, ratioPassed), easeInQuint(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutQuint:
											newVect = new Vector3(easeOutQuint(tween.from.x, tween.to.x, ratioPassed), easeOutQuint(tween.from.y, tween.to.y, ratioPassed), easeOutQuint(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInOutQuint:
											newVect = new Vector3(easeInOutQuint(tween.from.x, tween.to.x, ratioPassed), easeInOutQuint(tween.from.y, tween.to.y, ratioPassed), easeInOutQuint(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInSine:
											newVect = new Vector3(easeInSine(tween.from.x, tween.to.x, ratioPassed), easeInSine(tween.from.y, tween.to.y, ratioPassed), easeInSine(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutSine:
											newVect = new Vector3(easeOutSine(tween.from.x, tween.to.x, ratioPassed), easeOutSine(tween.from.y, tween.to.y, ratioPassed), easeOutSine(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInOutSine:
											newVect = new Vector3(easeInOutSine(tween.from.x, tween.to.x, ratioPassed), easeInOutSine(tween.from.y, tween.to.y, ratioPassed), easeInOutSine(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInExpo:
											newVect = new Vector3(easeInExpo(tween.from.x, tween.to.x, ratioPassed), easeInExpo(tween.from.y, tween.to.y, ratioPassed), easeInExpo(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutExpo:
											newVect = new Vector3(easeOutExpo(tween.from.x, tween.to.x, ratioPassed), easeOutExpo(tween.from.y, tween.to.y, ratioPassed), easeOutExpo(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInOutExpo:
											newVect = new Vector3(easeInOutExpo(tween.from.x, tween.to.x, ratioPassed), easeInOutExpo(tween.from.y, tween.to.y, ratioPassed), easeInOutExpo(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInCirc:
											newVect = new Vector3(easeInCirc(tween.from.x, tween.to.x, ratioPassed), easeInCirc(tween.from.y, tween.to.y, ratioPassed), easeInCirc(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutCirc:
											newVect = new Vector3(easeOutCirc(tween.from.x, tween.to.x, ratioPassed), easeOutCirc(tween.from.y, tween.to.y, ratioPassed), easeOutCirc(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInOutCirc:
											newVect = new Vector3(easeInOutCirc(tween.from.x, tween.to.x, ratioPassed), easeInOutCirc(tween.from.y, tween.to.y, ratioPassed), easeInOutCirc(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInBounce:
											newVect = new Vector3(easeInBounce(tween.from.x, tween.to.x, ratioPassed), easeInBounce(tween.from.y, tween.to.y, ratioPassed), easeInBounce(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutBounce:
											newVect = new Vector3(easeOutBounce(tween.from.x, tween.to.x, ratioPassed), easeOutBounce(tween.from.y, tween.to.y, ratioPassed), easeOutBounce(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInOutBounce:
											newVect = new Vector3(easeInOutBounce(tween.from.x, tween.to.x, ratioPassed), easeInOutBounce(tween.from.y, tween.to.y, ratioPassed), easeInOutBounce(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeInBack:
											newVect = new Vector3(easeInBack(tween.from.x, tween.to.x, ratioPassed), easeInBack(tween.from.y, tween.to.y, ratioPassed), easeInBack(tween.from.z, tween.to.z, ratioPassed)); break;
										case LeanTweenType.easeOutBack:
											newVect = new Vector3(easeOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot), easeOutBack(tween.from.y, tween.to.y, ratioPassed, tween.overshoot), easeOutBack(tween.from.z, tween.to.z, ratioPassed, tween.overshoot)); break;
										case LeanTweenType.easeInOutBack:
											newVect = new Vector3(easeInOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot), easeInOutBack(tween.from.y, tween.to.y, ratioPassed, tween.overshoot), easeInOutBack(tween.from.z, tween.to.z, ratioPassed, tween.overshoot)); break;
										case LeanTweenType.easeInElastic:
											newVect = new Vector3(easeInElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period), easeInElastic(tween.from.y, tween.to.y, ratioPassed, tween.overshoot, tween.period), easeInElastic(tween.from.z, tween.to.z, ratioPassed, tween.overshoot, tween.period)); break;
										case LeanTweenType.easeOutElastic:
											newVect = new Vector3(easeOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period), easeOutElastic(tween.from.y, tween.to.y, ratioPassed, tween.overshoot, tween.period), easeOutElastic(tween.from.z, tween.to.z, ratioPassed, tween.overshoot, tween.period)); break;
										case LeanTweenType.easeInOutElastic:
											newVect = new Vector3(easeInOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period), easeInOutElastic(tween.from.y, tween.to.y, ratioPassed, tween.overshoot, tween.period), easeInOutElastic(tween.from.z, tween.to.z, ratioPassed, tween.overshoot, tween.period)); break;
										case LeanTweenType.punch:
										case LeanTweenType.easeShake:
											if (tween.tweenType == LeanTweenType.punch)
											{
												tween.animationCurve = LeanTween.punch;
											}
											else if (tween.tweenType == LeanTweenType.easeShake)
											{
												tween.animationCurve = LeanTween.shake;
											}
											tween.to = tween.from + tween.to;
											tween.diff = tween.to - tween.from;
											if (tweenAction == TweenAction.ROTATE || tweenAction == TweenAction.ROTATE_LOCAL)
											{
												tween.to = new Vector3(closestRot(tween.from.x, tween.to.x), closestRot(tween.from.y, tween.to.y), closestRot(tween.from.z, tween.to.z));
											}
											newVect = tweenOnCurveVector(tween, ratioPassed); break;
										case LeanTweenType.easeSpring:
											newVect = new Vector3(spring(tween.from.x, tween.to.x, ratioPassed), spring(tween.from.y, tween.to.y, ratioPassed), spring(tween.from.z, tween.to.z, ratioPassed)); break;

									}
								}
								else
								{
									newVect = new Vector3(tween.from.x + tween.diff.x * ratioPassed, tween.from.y + tween.diff.y * ratioPassed, tween.from.z + tween.diff.z * ratioPassed);
								}
							}

							if (tweenAction == TweenAction.MOVE)
							{
								trans.position = newVect;
							}
							else if (tweenAction == TweenAction.MOVE_LOCAL)
							{
								trans.localPosition = newVect;
							}
							else if (tweenAction == TweenAction.ROTATE)
							{
								/*if(tween.hasPhysics){
									trans.gameObject.rigidbody.MoveRotation(Quaternion.Euler( newVect ));
								}else{*/
								trans.eulerAngles = newVect;
								// }
							}
							else if (tweenAction == TweenAction.ROTATE_LOCAL)
							{
								trans.localEulerAngles = newVect;
							}
							else if (tweenAction == TweenAction.SCALE)
							{
								trans.localScale = newVect;
							}
							else if (tweenAction == TweenAction.GUI_MOVE)
							{
								tween.ltRect.rect = new Rect(newVect.x, newVect.y, tween.ltRect.rect.width, tween.ltRect.rect.height);
							}
							else if (tweenAction == TweenAction.GUI_MOVE_MARGIN)
							{
								tween.ltRect.margin = new Vector2(newVect.x, newVect.y);
							}
							else if (tweenAction == TweenAction.GUI_SCALE)
							{
								tween.ltRect.rect = new Rect(tween.ltRect.rect.x, tween.ltRect.rect.y, newVect.x, newVect.y);
							}
							else if (tweenAction == TweenAction.GUI_ALPHA)
							{
								tween.ltRect.alpha = newVect.x;
							}
							else if (tweenAction == TweenAction.GUI_ROTATE)
							{
								tween.ltRect.rotation = newVect.x;
							}
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
							else if (tweenAction == TweenAction.CANVAS_MOVE)
							{
								tween.rectTransform.anchoredPosition3D = newVect;
							}
							else if (tweenAction == TweenAction.CANVAS_SCALE)
							{
								tween.rectTransform.localScale = newVect;
							}
#endif
						}
						// Debug.Log("tween.delay:"+tween.delay + " tween.passed:"+tween.passed + " tweenAction:"+tweenAction + " to:"+newVect+" axis:"+tween.axis);

						if (dt != 0f && tween.hasUpdateCallback)
						{
							if (tween.onUpdateFloat != null)
							{
								tween.onUpdateFloat(val);
							}
							if (tween.onUpdateFloatRatio != null)
							{
								tween.onUpdateFloatRatio(val, ratioPassed);
							}
							else if (tween.onUpdateFloatObject != null)
							{
								tween.onUpdateFloatObject(val, tween.onUpdateParam);
							}
							else if (tween.onUpdateVector3Object != null)
							{
								tween.onUpdateVector3Object(newVect, tween.onUpdateParam);
							}
							else if (tween.onUpdateVector3 != null)
							{
								tween.onUpdateVector3(newVect);
							}
							else if (tween.onUpdateVector2 != null)
							{
								tween.onUpdateVector2(new Vector2(newVect.x, newVect.y));
							}
						}
#if LEANTWEEN_1
					else if(tween.optional!=null){ // LeanTween 1.x legacy stuff
						var onUpdate = tween.optional["onUpdate"];
						if(onUpdate!=null){
							Hashtable updateParam = (Hashtable)tween.optional["onUpdateParam"];
							if((TweenAction)tweenAction==TweenAction.VALUE3){
								if(onUpdate.GetType() == typeof(string)){
									string onUpdateS = onUpdate as string;
									customTarget = tween.optional["onUpdateTarget"]!=null ? tween.optional["onUpdateTarget"] as GameObject : trans.gameObject;
									customTarget.BroadcastMessage( onUpdateS, newVect );
								}else if(onUpdate.GetType() == typeof(System.Action<Vector3, Hashtable>)){
									System.Action<Vector3, Hashtable> onUpdateA = (System.Action<Vector3, Hashtable>)onUpdate;
									onUpdateA(newVect, updateParam);
								}else{
									System.Action<Vector3> onUpdateA = (System.Action<Vector3>)onUpdate;
									onUpdateA(newVect);
								}
							}else{
								if(onUpdate.GetType() == typeof(string)){
									string onUpdateS = onUpdate as string;
									if (tween.optional["onUpdateTarget"]!=null){
										customTarget = tween.optional["onUpdateTarget"] as GameObject;
										customTarget.BroadcastMessage( onUpdateS, val );
									}else{
										trans.gameObject.BroadcastMessage( onUpdateS, val );
									}
								}else if(onUpdate.GetType() == typeof(System.Action<float, Hashtable>)){
									System.Action<float, Hashtable> onUpdateA = (System.Action<float, Hashtable>)onUpdate;
									onUpdateA(val, updateParam);
								}else if(onUpdate.GetType() == typeof(System.Action<Vector3>)){
									System.Action<Vector3> onUpdateA = (System.Action<Vector3>)onUpdate;
									onUpdateA( newVect );
								}else{
									System.Action<float> onUpdateA = (System.Action<float>)onUpdate;
									onUpdateA(val);
								}
							}
						}
					}
#endif
					}

					if (isTweenFinished)
					{
						if (tween.loopType == LeanTweenType.once || tween.loopCount == 1)
						{
							tweensFinished[finishedCnt] = i;
							finishedCnt++;

							//Debug.Log("finished tween:"+i+" tween:"+tween);
							if (tweenAction == TweenAction.GUI_ROTATE)
								tween.ltRect.rotateFinished = true;

							if (tweenAction == TweenAction.DELAYED_SOUND)
							{
								AudioSource.PlayClipAtPoint((AudioClip)tween.onCompleteParam, tween.to, tween.from.x);
							}
						}
						else
						{
							if ((tween.loopCount < 0 && tween.type == TweenAction.CALLBACK) || tween.onCompleteOnRepeat)
							{
								if (tweenAction == TweenAction.DELAYED_SOUND)
								{
									AudioSource.PlayClipAtPoint((AudioClip)tween.onCompleteParam, tween.to, tween.from.x);
								}
								if (tween.onComplete != null)
								{
									tween.onComplete();
								}
								else if (tween.onCompleteObject != null)
								{
									tween.onCompleteObject(tween.onCompleteParam);
								}
							}
							if (tween.loopCount >= 1)
							{
								tween.loopCount--;
							}
							// Debug.Log("tween.loopType:"+tween.loopType+" tween.loopCount:"+tween.loopCount+" passed:"+tween.passed);
							if (tween.loopType == LeanTweenType.pingPong)
							{
								tween.direction = 0.0f - (tween.direction);
							}
							else
							{
								tween.passed = Mathf.Epsilon;
							}
						}
					}
					else if (tween.delay <= 0f)
					{
						tween.passed += dt * tween.direction;
					}
					else
					{
						tween.delay -= dt;
						// Debug.Log("dt:"+dt+" tween:"+i+" tween:"+tween);
						if (tween.delay < 0f)
						{
							tween.passed = 0.0f;//-tween.delay
							tween.delay = 0.0f;
						}
					}
				}
			}

			// Debug.Log("maxTweenReached:"+maxTweenReached);
			tweenMaxSearch = maxTweenReached;
			frameRendered = Time.frameCount;

			for (int i = 0; i < finishedCnt; i++)
			{
				j = tweensFinished[i];
				tween = tweens[j];

				// logError("removing tween:"+tween);
				if (tween.onComplete != null)
				{
					System.Action onComplete = tween.onComplete;
					//logError("removing tween for j:"+j+" tween:"+tween);
					removeTween(j);
					//tween.cleanup();
					onComplete();

				}
				else if (tween.onCompleteObject != null)
				{
					System.Action<object> onCompleteObject = tween.onCompleteObject;
					object onCompleteParam = tween.onCompleteParam;
					removeTween(j);
					//tween.cleanup();
					onCompleteObject(onCompleteParam);
				}
#if LEANTWEEN_1
			else if(tween.optional!=null){
				System.Action callback=null;
				System.Action<object> callbackWithParam = null;
				string callbackS=string.Empty;
				object callbackParam=null;
				Hashtable optional = tween.optional;
				if(tween.optional!=null && tween.trans){
					if(tween.optional["onComplete"]!=null){
						callbackParam = tween.optional["onCompleteParam"];
						if(tween.optional["onComplete"].GetType()==typeof(string)){
							callbackS = tween.optional["onComplete"] as string;
						}else{
							if(callbackParam!=null){
								callbackWithParam = (System.Action<object>)tween.optional["onComplete"];
							}else{
								callback = (System.Action)tween.optional["onComplete"];	
								if(callback==null)
									Debug.LogWarning("callback was not converted");
							}
						}
					}
				}
				removeTween(j);
				if(callbackWithParam!=null){
					callbackWithParam( callbackParam );
				}else if(callback!=null){
					callback();
				}else if(callbackS!=string.Empty){
					if (optional["onCompleteTarget"]!=null){
						customTarget = optional["onCompleteTarget"] as GameObject;
						if(callbackParam!=null) customTarget.BroadcastMessage ( callbackS, callbackParam );
						else customTarget.BroadcastMessage( callbackS );
					}else{
						if(callbackParam!=null) trans.gameObject.BroadcastMessage ( callbackS, callbackParam );
						else trans.gameObject.BroadcastMessage( callbackS );
					}
				}
				
			}
#endif
				else
				{
					removeTween(j);
					//tween.cleanup();
				}
			}

		}
	}
Beispiel #31
0
 private void ShowPanel()
 {
     StopTween();
     PanelTransform.anchoredPosition = FromPosition;
     _panelMoveDescr = LeanTween.move(PanelTransform, ToPosition, TweenTime).setOnComplete(OnShowPanelFinish);
 }
	public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time)
	{
		d = options();
		d.spline = to;

		return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, d);
	}
 public void SetCoolDown(float amount) => progressBarId = LeanTween.value(gameObject, 100, 0, amount)
                                                          .setOnUpdate(value => coolDownProgressBar.Current = value);
Beispiel #34
0
    private static LTDescr pushNewTween( GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, LTDescr tween )
    {
        init(maxTweens);
        if(gameObject==null)
        return null;
        tween.trans = gameObject.transform;
        tween.to = to;
        tween.time = time;
        tween.type = tweenAction;
        //tween.hasPhysics = gameObject.rigidbody!=null;

        return tween;
    }
        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));
            });

            // Sequence test, do three tweens and make sure they end at the right points
            GameObject 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
            GameObject cubeBounds    = cubeNamed("cBounds");
            bool       didPassBounds = true;
            Vector3    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);
            });


            // 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 + 7;

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

            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();
        }
Beispiel #36
0
        bool Tween(System.Action endAction = null)
        {
            Init();

            TweenStop();
            LTDescr lt = TweenRun(!m_StartByReversed, tweenTime).setIgnoreTimeScale(ignoreTimeScale).setEase(tweenEaseType);

            if (lt == null)
            {
                if (endAction != null)
                {
                    endAction();
                }
                return(false);
            }

            m_LastTweenId = lt.uniqueId;

            lt.onComplete = () => {
                switch (tweenWrapMode)
                {
                case WrapMode.Loop:
                    if (m_TweenLoopCount > 0)
                    {
                        m_TweenLoopCount--;
                    }
                    if (m_TweenLoopCount != 0)
                    {
                        m_IsInited = false;
                        Tween(endAction);
                        return;
                    }
                    break;

                case WrapMode.PingPong:
                    if (m_TweenLoopCount > 0)
                    {
                        m_TweenLoopCount--;
                    }
                    if (m_TweenLoopCount != 0)
                    {
                        m_StartByReversed = !m_StartByReversed;
                        Tween(endAction);
                        return;
                    }
                    break;

                case WrapMode.Once:
                    m_IsInited = false;
                    Init();
                    break;
                }

                if (endAction != null)
                {
                    endAction();
                }
            };

            return(true);
        }
Beispiel #37
0
 public void reset()
 {
     previous   = null;
     tween      = null;
     totalDelay = 0f;
 }
Beispiel #38
0
    public override List <LTDescr> Animate(GameEvent gameEvent)
    {
        Text createdText = Instantiate(scoreDeltaTextPrefab, rect);

        createdText.text = scoreDelta;
        RectTransform textTransform = createdText.rectTransform;

        textTransform.localScale = Vector3.zero;
        Vector2 iconRadiusVector = rect.localToWorldMatrix.MultiplyVector(new Vector2(rect.rect.width, rect.rect.height));
        float   iconRadius       = Mathf.Min(iconRadiusVector.x, iconRadiusVector.y) / 2;

        LTDescr iconScaleDown = LeanTween.scale(
            rectTrans: rect,
            to: new Vector3(1.1f, 1.1f, 1.1f),
            time: 0.2f);
        LTDescr iconScaleUp = LeanTween.scale(
            rectTrans: rect,
            to: new Vector3(1f, 1f, 1f),
            time: 0.3f)
                              .setEaseOutBack()
                              .PlayAfter(iconScaleDown)
                              .SetCallEventOnStart(new GameEvent()
        {
            eventType = GameEvent.EventEnum.PlayPop
        });
        LTDescr scaleTextUp = LeanTween.scale(
            rectTrans: textTransform,
            to: Vector3.one,
            time: 0.2f)
                              .setEaseOutBack()
                              .PlayAfter(iconScaleDown);
        LTDescr moveTextUp = LeanTweenHelper.Singleton.UIMoveRelative(
            rectTransform: textTransform,
            to: new Vector3(0, iconRadius + 0.2f, 0),
            time: 0.2f)
                             .setEaseOutBack()
                             .PlayAfter(iconScaleDown);
        LTDescr shakeText = LeanTweenHelper.Singleton.UIShake(
            rectTransform: textTransform,
            magnitude: 0.05f,
            rateOfChange: 0.001f,
            frequency: 0.7f,
            time: 3f)
                            .PlayAfter(moveTextUp);
        LTDescr scaleTextDown = LeanTween.scale(
            rectTrans: textTransform,
            to: Vector3.zero,
            time: 0.2f)
                                .setEaseInBack()
                                .PlayAfter(shakeText);
        LTDescr moveTextDown = LeanTweenHelper.Singleton.UIMoveRelative(
            rectTransform: textTransform,
            to: new Vector3(0, -2, 0),
            time: 0.2f)
                               .setEaseInBack()
                               .PlayAfter(shakeText);

        return(new List <LTDescr>()
        {
            iconScaleDown,
            iconScaleUp,
            scaleTextUp,
            moveTextUp,
            shakeText,
            scaleTextDown,
            moveTextDown
        });
    }
 public WaitForTween(LTDescr tween)
 {
     this.tween = tween;
     tween.setOnComplete(() => complete = true);
 }
Beispiel #40
0
 private void Start()
 {
     tweenObject = LeanTween.move(gameObject, transform.position + (Vector3.up * distance), duration);
     tweenObject.setLoopPingPong();
     tweenObject.setEase(easeType);
 }
Beispiel #41
0
 // Tweening Functions - Thanks to Robert Penner and GFX47
 private static float tweenOnCurve( LTDescr tweenDescr, float ratioPassed )
 {
     // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed));
     return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed);
 }
Beispiel #42
0
 public void OnPointerEnter(PointerEventData eventData)
 {
     delay = LeanTween.delayedCall(1f, () => {
         TooltipSystem.Show(content, header);
     });
 }
Beispiel #43
0
    private static int pushNewTween( GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, Hashtable optional )
    {
        init(maxTweens);
        if(gameObject==null)
        return -1;

        j = 0;
        for(i = startSearch; j < maxTweens; i++){
        if(i>=maxTweens-1)
            i = 0;
        if(tweens[i].toggle==false){
            if(i+1>tweenMaxSearch)
                tweenMaxSearch = i+1;
            startSearch = i + 1;
            break;
        }

        j++;
        if(j>=maxTweens){
            logError("LeanTween - You have run out of available spaces for tweening. To avoid this error increase the number of spaces to available for tweening when you initialize the LeanTween class ex: LeanTween.init( "+(maxTweens*2)+" );");
            return -1;
        }
        }
        tween = tweens[i];
        tween.toggle = true;
        tween.reset();
        tween.trans = gameObject.transform;
        tween.to = to;
        tween.time = time;
        tween.type = tweenAction;
        tween.optional = optional;
        tween.setId( (uint)i );
        //tween.hasPhysics = gameObject.rigidbody!=null;

        if(optional!=null){
        var ease = optional["ease"];
        //LeanTweenType ease;
        var optionsNotUsed = 0;
        if(ease!=null) {
            tween.tweenType = LeanTweenType.linear;
            if( ease.GetType() ==typeof( LeanTweenType) ){
                tween.tweenType = (LeanTweenType)ease;// Enum.Parse(typeof(LeanTweenType), optional["ease"].ToString());
            } else if(ease.GetType() == typeof(AnimationCurve)){
                tween.animationCurve = optional["ease"] as AnimationCurve;
            } else{
                string func = optional["ease"].ToString();
                if(func.Equals("easeOutQuad")){
                    tween.tweenType = LeanTweenType.easeOutQuad;
                }else if(func.Equals("easeInQuad")){
                    tween.tweenType = LeanTweenType.easeInQuad;
                }else if(func.Equals("easeInOutQuad")){
                    tween.tweenType = LeanTweenType.easeInOutQuad;
                }
            }
            optionsNotUsed++;
        }
        if(optional["rect"]!=null){
            tween.ltRect = (LTRect)optional["rect"];
            optionsNotUsed++;
        }
        if(optional["path"]!=null){
            tween.path = (LTBezierPath)optional["path"];
            optionsNotUsed++;
        }
        if(optional["delay"]!=null){
            tween.delay = (float)optional["delay"];
            optionsNotUsed++;
        }
        if(optional["useEstimatedTime"]!=null){
            tween.useEstimatedTime =(bool) optional["useEstimatedTime"];
            optionsNotUsed++;
        }
        if(optional["useFrames"]!=null){
            tween.useFrames =(bool) optional["useFrames"];
            optionsNotUsed++;
        }
        if(optional["loopType"]!=null){
            tween.loopType = (LeanTweenType)optional["loopType"];
            optionsNotUsed++;
        }
        if(optional["repeat"]!=null){
            tween.loopCount = (int)optional["repeat"];
            if(tween.loopType==LeanTweenType.once)
                tween.loopType = LeanTweenType.clamp;
            optionsNotUsed++;
        }
        if(optional["point"]!=null){
            tween.point = (Vector3)optional["point"];
            optionsNotUsed++;
        }
        if(optional["axis"]!=null){
            tween.axis = (Vector3)optional["axis"];
            optionsNotUsed++;
        }
        if(optional.Count <= optionsNotUsed)
            tween.optional = null;  // nothing else is used with the extra piece, so set to null
        }else{
        tween.optional = null;
        }
        //Debug.Log("pushing new tween["+i+"]:"+tweens[i]);

        return tweens[i].uniqueId;
    }
Beispiel #44
0
 private static Vector3 tweenOnCurveVector(LTDescr tweenDescr, float ratioPassed)
 {
     return(new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed),
                        tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.animationCurve.Evaluate(ratioPassed),
                        tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.animationCurve.Evaluate(ratioPassed)));
 }
Beispiel #45
0
    void Update()
    {
        LeanTween.dtManual = Time.deltaTime;
        if (Input.GetKeyDown(KeyCode.Q))
        {
            //LeanTween.scale(this.gameObject, Vector3.one*3f, 1.0f).setEase(LeanTweenType.easeSpring).setUseManualTime(true);
            //print("scale punch time independent!");

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

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

            LeanTween.value(lt.gameObject, lt.intensity, 0.0f, 1.5f)
              .setEase(LeanTweenType.linear)
              .setLoopPingPong()
              .setRepeat(-1)
              .setOnUpdate((float val)=>{

            lt.intensity = val;
            });
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            print("scale punch!");

            tweenStatically( this.gameObject );

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

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

                    LeanTween.value(this.gameObject, (v) =>
                    {

                    }, 0, 1, 0.3f).setDelay(1);

                });

            });

        }

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

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

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

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

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

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

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

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

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

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

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

            );
            #endif
        }
    }
Beispiel #46
0
        ////////////////////////////////////////////////////////////////////////
        // Static Methods


        public static void AnimateData(BridgeObject bridgeObject, JArray dataArray)
        {
            GameObject go = bridgeObject.gameObject;

            if (leanTweenBridge == null)
            {
                Debug.LogError("LeanTweenBridge: AnimateData: no leanTweenBridge has been created.");
                return;
            }

            foreach (JObject data in dataArray)
            {
                LTDescr    result = null;
                GameObject target = go;

                float time = 1.0f;
                if (data.ContainsKey("time"))
                {
                    time = data.GetFloat("time");
                    if (time <= 0.0f)
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: time must be > 0. data: " + data);
                        return;
                    }
                }

                if (data.ContainsKey("target"))
                {
                    string targetPath = data.GetString("target");

                    if (targetPath == "")
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: empty targetPath");
                        return;
                    }

                    Accessor accessor = null;
                    if (!Accessor.FindAccessor(
                            bridgeObject,
                            targetPath,
                            ref accessor))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: target: can't find accessor for targetPath: " + targetPath);
                        return;
                    }

                    object obj = null;
                    if (!accessor.Get(ref obj))
                    {
                        if (!accessor.conditional)
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: target: can't get accessor: " + accessor + " targetPath: " + targetPath);
                            return;
                        }
                    }

                    GameObject goTarget = obj as GameObject;
                    if (goTarget == null)
                    {
                        Transform xform = obj as Transform;
                        if (xform != null)
                        {
                            goTarget = xform.gameObject;
                        }
                        else
                        {
                            Component component = obj as Component;
                            if (component != null)
                            {
                                goTarget = component.gameObject;
                            }
                        }
                    }

                    if (goTarget == null)
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: null targetPath: " + targetPath + " obj: " + obj);
                        return;
                    }

                    //Debug.Log("LeanTweenBridge: AnimateData: targetPath: " + targetPath + " goTarget: " + goTarget);
                    target = goTarget;
                }

                var command = (string)data.GetString("command");
                if (string.IsNullOrEmpty(command))
                {
                    Debug.LogError("LeanTweenBridge: AnimateData: missing command from data: " + data);
                    return;
                }

                switch (command)
                {
                case "init":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "play":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "cancel":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "cancelAll":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "pause":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "pauseAll":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "resume":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "resumeAll":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "sequence":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "value":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "move":
                case "moveLocal":
                case "moveSpline":
                case "moveSplineLocal":

                    //Debug.Log("LeanTweenBridge: AnimateData: command: " + command + " data: " + data);

                    // TODO: handle RectTransform instead of GameObject

                    if (data.ContainsKey("position"))
                    {
                        Vector3 position = Vector3.zero;
                        if (!Bridge.mainBridge.ConvertToType <Vector3>(data["position"], ref position))
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: position must be a Vector3. data: " + data);
                            return;
                        }

                        switch (command)
                        {
                        case "move":
                            result = LeanTween.move(target, position, time);
                            break;

                        case "moveLocal":
                            result = LeanTween.moveLocal(target, position, time);
                            break;

                        case "moveSpline":
                        case "moveSplineLocal":
                            Debug.LogError("LeanTweenBridge: AnimateData: position not supported for " + command + ". data: " + data);
                            return;
                        }
                    }
                    else if (data.ContainsKey("transform"))
                    {
                        Transform xform = null;

                        string path = data.GetString("transform");

                        Accessor accessor = null;
                        if (!Accessor.FindAccessor(
                                bridgeObject,
                                path,
                                ref accessor))
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: transform must be a path. path: " + path + " data: " + data);
                            return;
                        }
                        object val = null;
                        if (!accessor.Get(ref val) ||
                            (val == null))
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: error getting path to transform. path: " + path + " data: " + data);
                            return;
                        }

                        xform = val as Transform;

                        if (xform == null)
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: path does not point to transform. path: " + path + " data: " + data);
                            return;
                        }

                        switch (command)
                        {
                        case "move":
                            result = LeanTween.move(target, xform, time);
                            break;

                        case "moveLocal":
                        case "moveSpline":
                        case "moveSplineLocal":
                            Debug.LogError("LeanTweenBridge: AnimateData: transform not supported for " + command + ". data: " + data);
                            return;
                        }
                    }
                    else if (data.ContainsKey("path"))
                    {
                        Vector3[] path = null;
                        if (!Bridge.mainBridge.ConvertToType <Vector3[]>(data["path"], ref path))
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: path must be an Vector3[]. data: " + data);
                            return;
                        }

                        switch (command)
                        {
                        case "move":
                            result = LeanTween.move(target, path, time);
                            break;

                        case "moveLocal":
                            result = LeanTween.moveLocal(target, path, time);
                            break;

                        case "moveSpline":
                            result = LeanTween.moveSpline(target, path, time);
                            break;

                        case "moveSplineLocal":
                            result = LeanTween.moveSplineLocal(target, path, time);
                            break;
                        }
                    }
                    else if (data.ContainsKey("spline"))
                    {
                        LTSpline spline = null;
                        if (!Bridge.mainBridge.ConvertToType <LTSpline>(data["spline"], ref spline))
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: spline must be a LTSpline. data: " + data);
                            return;
                        }

                        switch (command)
                        {
                        case "moveSpline":
                            result = LeanTween.moveSpline(target, spline, time);
                            break;

                        case "move":
                        case "moveLocal":
                        case "moveSplineLocal":
                            Debug.LogError("LeanTweenBridge: AnimateData: spline not supported for " + command + ". data: " + data);
                            break;
                        }
                    }
                    else
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: command: " + command + " should contain position, transform, path or spline. data: " + data);
                        return;
                    }

                    break;

                case "moveX":
                case "moveY":
                case "moveZ":

                    // TODO: handle RectTransform instead of GameObject

                    if (!data.ContainsKey("to"))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: missing to parameter. data: " + data);
                        return;
                    }

                    float moveTo = data.GetFloat("to");

                    switch (command)
                    {
                    case "moveX":
                        result = LeanTween.moveX(target, moveTo, time);
                        break;

                    case "moveY":
                        result = LeanTween.moveY(target, moveTo, time);
                        break;

                    case "moveZ":
                        result = LeanTween.moveZ(target, moveTo, time);
                        break;
                    }

                    break;

                case "rotate":
                case "rotateLocal":

                    //Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);

                    // TODO: handle RectTransform instead of GameObject

                    if (!data.ContainsKey("to"))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: missing to. data: " + data);
                        return;
                    }

                    Vector3 rotateTo = Vector3.zero;
                    if (!Bridge.mainBridge.ConvertToType <Vector3>(data["to"], ref rotateTo))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: to must be an Vector3. data: " + data);
                        return;
                    }

                    switch (command)
                    {
                    case "rotate":
                        result = LeanTween.rotate(target, rotateTo, time);
                        break;

                    case "rotateLocal":
                        result = LeanTween.rotateLocal(target, rotateTo, time);
                        break;
                    }

                    break;

                case "rotateX":
                case "rotateY":
                case "rotateZ":

                    //Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);

                    // TODO: handle RectTransform instead of GameObject

                    if (!data.ContainsKey("to"))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: missing to. data: " + data);
                        return;
                    }

                    float rotateToValue = data.GetFloat("to");

                    switch (command)
                    {
                    case "rotateX":
                        result = LeanTween.rotateX(target, rotateToValue, time);
                        break;

                    case "rotateY":
                        result = LeanTween.rotateY(target, rotateToValue, time);
                        break;

                    case "rotateZ":
                        result = LeanTween.rotateZ(target, rotateToValue, time);
                        break;
                    }

                    break;

                case "rotateAround":
                case "rotateAroundLocal":

                    //Debug.Log("LeanTweenBridge: AnimateData: command: " + command + " data: " + data);

                    // TODO: handle RectTransform instead of GameObject

                    if (!data.ContainsKey("axis"))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: missing axis. data: " + data);
                        return;
                    }

                    if (!data.ContainsKey("to"))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: missing to. data: " + data);
                        return;
                    }

                    Vector3 rotateAroundAxis = Vector3.zero;
                    if (!Bridge.mainBridge.ConvertToType <Vector3>(data["axis"], ref rotateAroundAxis))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: to must be an Vector3. data: " + data);
                        return;
                    }

                    float rotateAroundTo = data.GetFloat("to");

                    switch (command)
                    {
                    case "rotateAround":
                        result = LeanTween.rotateAround(target, rotateAroundAxis, rotateAroundTo, time);
                        break;

                    case "rotateLocalLocal":
                        result = LeanTween.rotateAroundLocal(target, rotateAroundAxis, rotateAroundTo, time);
                        break;
                    }

                    break;

                case "scale":

                    //Debug.Log("LeanTweenBridge: AnimateData: command: " + command + " data: " + data);

                    // TODO: handle RectTransform instead of GameObject

                    if (!data.ContainsKey("to"))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: missing to. data: " + data);
                        return;
                    }

                    Vector3 to      = Vector3.one;
                    JToken  toToken = data["to"];
                    if (toToken.IsNumber())
                    {
                        float s = (float)toToken;
                        to = new Vector3(s, s, s);
                    }
                    else if (toToken.IsObject())
                    {
                        if (!Bridge.mainBridge.ConvertToType <Vector3>(toToken, ref to))
                        {
                            Debug.LogError("LeanTweenBridge: AnimateData: error converting to object to Vector3. data: " + data);
                            return;
                        }
                    }
                    else
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: to should be number or object. toToken: " + toToken + " " + toToken.Type + " data: " + data);
                        return;
                    }

                    result = LeanTween.scale(target, to, time);

                    break;

                case "scaleX":
                case "scaleY":
                case "scaleZ":

                    //Debug.Log("LeanTweenBridge: AnimateData: command: " + command + " data: " + data);

                    if (!data.ContainsKey("to"))
                    {
                        Debug.LogError("LeanTweenBridge: AnimateData: missing to. data: " + data);
                        return;
                    }

                    float scaleTo = data.GetFloat("to");

                    switch (command)
                    {
                    case "scaleX":
                        result = LeanTween.scaleX(target, scaleTo, time);
                        break;

                    case "scaleY":
                        result = LeanTween.scaleY(target, scaleTo, time);
                        break;

                    case "scaleZ":
                        result = LeanTween.scaleZ(target, scaleTo, time);
                        break;
                    }

                    break;

                case "size":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    // TODO: handle RectTransform but not GameObject
                    break;

                case "alpha":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "color":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                case "colorText":
                    Debug.Log("LeanTweenBridge: AnimateData: TODO: command: " + command + " data: " + data);
                    break;

                default:
                    Debug.LogError("LeanTweenBridge: AnimateData: unknown command: " + command + " in data: " + data);
                    return;
                }

                if (result != null)
                {
/*
 *              pause
 *              resume
 *              axis
 *              delay
 *              direction
 *              ease
 *              from
 *              ignoreTimeScale
 *              loopClamp
 *              loopOnce
 *              loopPingPong
 *              onComplete
 *              onCompleteOnRepeat
 *              onCompleteOnStart
 *              onCompleteParam
 *              onStart
 *              onUpdate
 *              onUpdateParam
 *              orientToPath
 *              orientToPath2d
 *              overshoot
 *              passed
 *              period
 *              point
 *              recursive
 *              repeat
 *              scale
 *              speed
 *              time
 *              to
 *              useFrames
 *              updateNow
 */
                }
            }
        }
	public static LTDescr moveLocal(GameObject gameObject, LTBezierPath to, float time)
	{
		d = options();
		d.path = to;

		return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED_LOCAL, d);
	}
Beispiel #48
0
    public void Show()
    {
        if (myCanvas.worldCamera == null && CoreGameManager.instance.currentSceneManager != null)
        {
            myCanvas.worldCamera = CoreGameManager.instance.currentSceneManager.cameraForConsumableScreen.mainCamera;
        }
        else
        {
            myCanvas.worldCamera = Camera.main;
        }

        currentState = State.Show;
        MyAudioManager.instance.PlaySfx(GameInformation.instance.globalAudioInfo.sfx_TogglePanel);

        for (int i = listData.Count - 1; i >= 0 && i < listData.Count; i--)
        {
            AddPanelDetail(listData[i]);
        }

        myCanvasGroup.blocksRaycasts = true;

        if (onStartShow != null)
        {
            onStartShow();
        }

        if (myTweenCanvasGroup != null)
        {
            LeanTween.cancel(myCanvasGroup.gameObject, myTweenCanvasGroup.uniqueId);
            myTweenCanvasGroup = null;
        }
        myTweenCanvasGroup = LeanTween.alphaCanvas(myCanvasGroup, 1f, 0.1f).setOnComplete(() => { myTweenCanvasGroup = null; });

        if (myTweenMainContent != null)
        {
            LeanTween.cancel(mainContent.gameObject);
            myTweenMainContent = null;
        }
        myTweenMainContent = LeanTween.moveX(mainContent, 0f, timeTweenMainContent).setEase(LeanTweenType.easeOutSine).setOnComplete(() => { myTweenMainContent = null; });
    }
Beispiel #49
0
    public static void update()
    {
        if(frameRendered != Time.frameCount){ // make sure update is only called once per frame
        init();

        dtEstimated = Time.realtimeSinceStartup - previousRealTime;
        if(dtEstimated>0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large
            dtEstimated = 0.2f;
        previousRealTime = Time.realtimeSinceStartup;
        dtActual = Time.deltaTime*Time.timeScale;
        // if(tweenMaxSearch>1500)
        // 	Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens);
        for( int i = 0; i < tweenMaxSearch && i < maxTweens; i++){

            //Debug.Log("tweens["+i+"].toggle:"+tweens[i].toggle);
            if(tweens[i].toggle){
                tween = tweens[i];
                trans = tween.trans;
                timeTotal = tween.time;
                tweenAction = tween.type;

                dt = dtActual;
                if( tween.useEstimatedTime ){
                    dt = dtEstimated;
                    timeTotal = tween.time;
                }else if( tween.useFrames ){
                    dt = 1;
                }else if(tween.direction==0f){
                    dt = 0f;
                }

                if(trans==null){
                    removeTween(i);
                    continue;
                }
                // Debug.Log("i:"+i+" tween:"+tween+" dt:"+dt);

                // Check for tween finished
                isTweenFinished = false;
                if(tween.delay<=0){
                    if((tween.passed + dt > timeTotal && tween.direction > 0.0f )){
                        isTweenFinished = true;
                        tween.passed = tween.time; // Set to the exact end time so that it can finish tween exactly on the end value
                    }else if(tween.direction<0.0f && tween.passed - dt < 0.0f){
                        isTweenFinished = true;
                        tween.passed = Mathf.Epsilon;
                    }
                }

                if(!tween.hasInitiliazed && ((tween.passed==0.0 && tween.delay==0.0) || tween.passed>0.0) ){
                    tween.hasInitiliazed = true;

                    // Set time based on current timeScale
                    if( !tween.useEstimatedTime ){
                        tween.time = tween.time*Time.timeScale;
                    }

                    // Initialize From Values
                    switch(tweenAction){
                        case TweenAction.MOVE:
                            tween.from = trans.position; break;
                        case TweenAction.MOVE_X:
                            tween.from.x = trans.position.x; break;
                        case TweenAction.MOVE_Y:
                            tween.from.x = trans.position.y; break;
                        case TweenAction.MOVE_Z:
                            tween.from.x = trans.position.z; break;
                        case TweenAction.MOVE_LOCAL_X:
                            tweens[i].from.x = trans.localPosition.x; break;
                        case TweenAction.MOVE_LOCAL_Y:
                            tweens[i].from.x = trans.localPosition.y; break;
                        case TweenAction.MOVE_LOCAL_Z:
                            tweens[i].from.x = trans.localPosition.z; break;
                        case TweenAction.SCALE_X:
                            tween.from.x = trans.localScale.x; break;
                        case TweenAction.SCALE_Y:
                            tween.from.x = trans.localScale.y; break;
                        case TweenAction.SCALE_Z:
                            tween.from.x = trans.localScale.z; break;
                        case TweenAction.ALPHA:
                            #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
                                tween.from.x = trans.gameObject.renderer.material.color.a;
                                break;
                            #else
                                SpriteRenderer ren = trans.gameObject.GetComponent<SpriteRenderer>();
                                if(ren!=null){
                                    tween.from.x = ren.color.a;
                                }else if(trans.gameObject.renderer!=null){
                                    tween.from.x = trans.gameObject.renderer.material.color.a;
                                }
                                break;
                            #endif
                        case TweenAction.MOVE_LOCAL:
                            tween.from = trans.localPosition; break;
                        case TweenAction.MOVE_CURVED:
                        case TweenAction.MOVE_CURVED_LOCAL:
                        case TweenAction.MOVE_SPLINE:
                        case TweenAction.MOVE_SPLINE_LOCAL:
                            tween.from.x = 0; break;
                        case TweenAction.ROTATE:
                            tween.from = trans.eulerAngles;
                            tween.to = new Vector3(LeanTween.closestRot( tween.from.x, tween.to.x), LeanTween.closestRot( tween.from.y, tween.to.y), LeanTween.closestRot( tween.from.z, tween.to.z));
                            break;
                        case TweenAction.ROTATE_X:
                            tween.from.x = trans.eulerAngles.x;
                            tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
                            break;
                        case TweenAction.ROTATE_Y:
                            tween.from.x = trans.eulerAngles.y;
                            tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
                            break;
                        case TweenAction.ROTATE_Z:
                            tween.from.x = trans.eulerAngles.z;
                            tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
                            break;
                        case TweenAction.ROTATE_AROUND:
                            tween.lastVal = 0.0f; // optional["last"]
                            tween.from.x = 0.0f;
                            tween.origRotation = trans.rotation; // optional["origRotation"
                            break;
                        case TweenAction.ROTATE_AROUND_LOCAL:
                            tween.lastVal = 0.0f; // optional["last"]
                            tween.from.x = 0.0f;
                            tween.origRotation = trans.localRotation; // optional["origRotation"
                            break;
                        case TweenAction.ROTATE_LOCAL:
                            tween.from = trans.localEulerAngles;
                            tween.to = new Vector3(LeanTween.closestRot( tween.from.x, tween.to.x), LeanTween.closestRot( tween.from.y, tween.to.y), LeanTween.closestRot( tween.from.z, tween.to.z));
                            break;
                        case TweenAction.SCALE:
                            tween.from = trans.localScale; break;
                        case TweenAction.GUI_MOVE:
                            tween.from = new Vector3(tween.ltRect.rect.x, tween.ltRect.rect.y, 0); break;
                        case TweenAction.GUI_MOVE_MARGIN:
                            tween.from = new Vector2(tween.ltRect.margin.x, tween.ltRect.margin.y); break;
                        case TweenAction.GUI_SCALE:
                            tween.from = new  Vector3(tween.ltRect.rect.width, tween.ltRect.rect.height, 0); break;
                        case TweenAction.GUI_ALPHA:
                            tween.from.x = tween.ltRect.alpha; break;
                        case TweenAction.GUI_ROTATE:
                            if(tween.ltRect.rotateEnabled==false){
                                tween.ltRect.rotateEnabled = true;
                                tween.ltRect.resetForRotation();
                            }

                            tween.from.x = tween.ltRect.rotation; break;
                        case TweenAction.ALPHA_VERTEX:
                            tween.from.x = trans.GetComponent<MeshFilter>().mesh.colors32[0].a;
                            break;
                        case TweenAction.CALLBACK_COLOR:
                            tween.diff = new Vector3(1.0f,0.0f,0.0f);
                            break;
                        case TweenAction.COLOR:
                            #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
                                if(trans.gameObject.renderer){
                                    Color col = trans.gameObject.renderer.material.color;
                                    tween.from = new Vector3(0.0f, col.a, 0.0f);
                                    tween.diff = new Vector3(1.0f,0.0f,0.0f);
                                    tween.axis = new Vector3( col.r, col.g, col.b );
                                }
                            #else
                                SpriteRenderer ren2 = trans.gameObject.GetComponent<SpriteRenderer>();
                                if(ren2!=null){
                                    tween.from = new Vector3(0.0f, ren2.color.a, 0.0f);
                                    tween.diff = new Vector3(1.0f,0.0f,0.0f);
                                    tween.axis = new Vector3( ren2.color.r, ren2.color.g, ren2.color.b );
                                }else if(trans.gameObject.renderer!=null){
                                    if(trans.gameObject.renderer){
                                        Color col = trans.gameObject.renderer.material.color;
                                        tween.from = new Vector3(0.0f, col.a, 0.0f);
                                        tween.diff = new Vector3(1.0f,0.0f,0.0f);
                                        tween.axis = new Vector3( col.r, col.g, col.b );
                                    }
                                }
                            #endif
                            break;
                    }
                    if(tweenAction!=TweenAction.CALLBACK_COLOR && tweenAction!=TweenAction.COLOR)
                        tween.diff = tween.to - tween.from;
                }
                if(tween.delay<=0){
                    // Move Values
                    if(timeTotal<=0f){
                        //Debug.LogError("time total is zero Time.timeScale:"+Time.timeScale+" useEstimatedTime:"+tween.useEstimatedTime);
                        ratioPassed = 0f;
                    }else{
                        ratioPassed = tween.passed / timeTotal;
                    }

                    if(ratioPassed>1.0f){
                        ratioPassed = 1.0f;
                    }else if(ratioPassed<0f){
                        ratioPassed = 0f;
                    }
                    // Debug.Log("action:"+tweenAction+" ratioPassed:"+ratioPassed + " timeTotal:" + timeTotal + " tween.passed:"+ tween.passed +" dt:"+dt);

                    if(tweenAction>=TweenAction.MOVE_X && tweenAction<=TweenAction.CALLBACK){
                        if(tween.animationCurve!=null){
                            val = tweenOnCurve(tween, ratioPassed);
                        }else {
                            switch( tween.tweenType ){
                                case LeanTweenType.linear:
                                    val = tween.from.x + tween.diff.x * ratioPassed; break;
                                case LeanTweenType.easeOutQuad:
                                    val = easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
                                case LeanTweenType.easeInQuad:
                                    val = easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
                                case LeanTweenType.easeInOutQuad:
                                    val = easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
                                case LeanTweenType.easeInCubic:
                                    val = easeInCubic(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutCubic:
                                    val = easeOutCubic(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutCubic:
                                    val = easeInOutCubic(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInQuart:
                                    val = easeInQuart(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutQuart:
                                    val = easeOutQuart(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutQuart:
                                    val = easeInOutQuart(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInQuint:
                                    val = easeInQuint(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutQuint:
                                    val = easeOutQuint(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutQuint:
                                    val = easeInOutQuint(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInSine:
                                    val = easeInSine(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutSine:
                                    val = easeOutSine(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutSine:
                                    val = easeInOutSine(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInExpo:
                                    val = easeInExpo(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutExpo:
                                    val = easeOutExpo(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutExpo:
                                    val = easeInOutExpo(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInCirc:
                                    val = easeInCirc(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutCirc:
                                    val = easeOutCirc(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutCirc:
                                    val = easeInOutCirc(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInBounce:
                                    val = easeInBounce(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutBounce:
                                    val = easeOutBounce(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutBounce:
                                    val = easeInOutBounce(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInBack:
                                    val = easeInBack(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutBack:
                                    val = easeOutBack(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutBack:
                                    val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInElastic:
                                    val = easeInElastic(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeOutElastic:
                                    val = easeOutElastic(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.easeInOutElastic:
                                    val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); break;
                                case LeanTweenType.punch:
                                case LeanTweenType.easeShake:
                                    if(tween.tweenType==LeanTweenType.punch){
                                        tween.animationCurve = LeanTween.punch;
                                    }else if(tween.tweenType==LeanTweenType.easeShake){
                                        tween.animationCurve = LeanTween.shake;
                                    }
                                    tween.to.x = tween.from.x + tween.to.x;
                                    tween.diff.x = tween.to.x - tween.from.x;
                                    val = tweenOnCurve(tween, ratioPassed); break;
                                case LeanTweenType.easeSpring:
                                    val = spring(tween.from.x, tween.to.x, ratioPassed); break;
                                default:
                                    {
                                        val = tween.from.x + tween.diff.x * ratioPassed; break;
                                    }
                            }

                        }

                        //Debug.Log("from:"+from+" to:"+to+" val:"+val+" ratioPassed:"+ratioPassed);
                        if(tweenAction==TweenAction.MOVE_X){
                            trans.position=new Vector3( val,trans.position.y,trans.position.z);
                        }else if(tweenAction==TweenAction.MOVE_Y){
                            trans.position =new Vector3( trans.position.x,val,trans.position.z);
                        }else if(tweenAction==TweenAction.MOVE_Z){
                            trans.position=new Vector3( trans.position.x,trans.position.y,val);
                        }if(tweenAction==TweenAction.MOVE_LOCAL_X){
                            trans.localPosition=new Vector3( val,trans.localPosition.y,trans.localPosition.z);
                        }else if(tweenAction==TweenAction.MOVE_LOCAL_Y){
                            trans.localPosition=new Vector3( trans.localPosition.x,val,trans.localPosition.z);
                        }else if(tweenAction==TweenAction.MOVE_LOCAL_Z){
                            trans.localPosition=new Vector3( trans.localPosition.x,trans.localPosition.y,val);
                        }else if(tweenAction==TweenAction.MOVE_CURVED){
                            if(tween.path.orientToPath){
                                tween.path.place( trans, val );
                            }else{
                                trans.position = tween.path.point( val );
                            }
                            // Debug.Log("val:"+val+" trans.position:"+trans.position + " 0:"+ tween.curves[0] +" 1:"+tween.curves[1] +" 2:"+tween.curves[2] +" 3:"+tween.curves[3]);
                        }else if((TweenAction)tweenAction==TweenAction.MOVE_CURVED_LOCAL){
                            if(tween.path.orientToPath){
                                tween.path.placeLocal( trans, val );
                            }else{
                                trans.localPosition = tween.path.point( val );
                            }
                            // Debug.Log("val:"+val+" trans.position:"+trans.position);
                        }else if((TweenAction)tweenAction==TweenAction.MOVE_SPLINE){
                            if(tween.spline.orientToPath){
                                tween.spline.place( trans, val );
                            }else{
                                trans.position = tween.spline.point( val );
                            }
                        }else if((TweenAction)tweenAction==TweenAction.MOVE_SPLINE_LOCAL){
                            if(tween.spline.orientToPath){
                                tween.spline.placeLocal( trans, val );
                            }else{
                                trans.localPosition = tween.spline.point( val );
                            }
                        }else if(tweenAction==TweenAction.SCALE_X){
                            trans.localScale=new Vector3(val, trans.localScale.y,trans.localScale.z);
                        }else if(tweenAction==TweenAction.SCALE_Y){
                            trans.localScale=new Vector3( trans.localScale.x,val,trans.localScale.z);
                        }else if(tweenAction==TweenAction.SCALE_Z){
                            trans.localScale=new Vector3(trans.localScale.x,trans.localScale.y,val);
                        }else if(tweenAction==TweenAction.ROTATE_X){
                            trans.eulerAngles=new Vector3(val, trans.eulerAngles.y,trans.eulerAngles.z);
                        }else if(tweenAction==TweenAction.ROTATE_Y){
                            trans.eulerAngles=new Vector3(trans.eulerAngles.x,val,trans.eulerAngles.z);
                        }else if(tweenAction==TweenAction.ROTATE_Z){
                            trans.eulerAngles=new Vector3(trans.eulerAngles.x,trans.eulerAngles.y,val);
                        }else if(tweenAction==TweenAction.ROTATE_AROUND){

                            float move = val -  tween.lastVal;
                            // Debug.Log("move:"+move+" val:"+val + " timeTotal:"+timeTotal + " from:"+tween.from+ " diff:"+tween.diff);
                            if(isTweenFinished){
                                if(tween.direction>0){
                                    trans.rotation = tween.origRotation;
                                    trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), tween.axis, tween.to.x);
                                }else{
                                    trans.rotation = tween.origRotation;
                                }
                            }else{
                                /*trans.rotation = tween.origRotation;
                                trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), tween.axis, val);
                                tween.lastVal = val;*/

                                trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), tween.axis, move);
                                tween.lastVal = val;

                                //trans.rotation =  * Quaternion.AngleAxis(val, tween.axis);
                            }

                        }else if(tweenAction==TweenAction.ROTATE_AROUND_LOCAL){
                            float move = val -  tween.lastVal;
                            if(isTweenFinished){
                                if(tween.direction>0){
                                    trans.localRotation = tween.origRotation;
                                trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), trans.TransformDirection(tween.axis), tween.to.x);
                                }else{
                                    trans.localRotation = tween.origRotation;
                                }
                            }else{
                                trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), trans.TransformDirection(tween.axis), move);
                                tween.lastVal = val;
                            }
                        }else if(tweenAction==TweenAction.ALPHA){
                            #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2

                            foreach(Material mat in trans.gameObject.renderer.materials){
                                mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val);
                            }

                            #else

                            SpriteRenderer ren = trans.gameObject.GetComponent<SpriteRenderer>();
                            if(ren!=null){
                                ren.color = new Color( ren.color.r, ren.color.g, ren.color.b, val);
                            }else{
                                if(trans.gameObject.renderer!=null){
                                    foreach(Material mat in trans.gameObject.renderer.materials){
                                        mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val);
                                    }
                                }
                                if(trans.childCount>0){
                                    foreach (Transform child in trans) {
                                        if(child.gameObject.renderer!=null){
                                            foreach(Material mat in child.gameObject.renderer.materials){
                                                mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val);
                                            }
                                        }
                                    }
                                }
                            }

                            #endif
                        }else if(tweenAction==TweenAction.ALPHA_VERTEX){
                            Mesh mesh = trans.GetComponent<MeshFilter>().mesh;
                            Vector3[] vertices = mesh.vertices;
                            Color32[] colors = new Color32[vertices.Length];
                            Color32 c = mesh.colors32[0];
                            c = new Color( c.r, c.g, c.b, val);
                            for (int k= 0; k < vertices.Length; k++) {
                                colors[k] = c;
                            }
                            mesh.colors32 = colors;
                        }else if(tweenAction==TweenAction.COLOR || tweenAction==TweenAction.CALLBACK_COLOR){
                            Color toColor = tweenColor(tween, val);
                            // Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
                            if(tweenAction==TweenAction.COLOR){
                                if(trans.gameObject.renderer!=null){
                                    foreach(Material mat in trans.gameObject.renderer.materials){
                                        mat.color = toColor;
                                    }
                                }
                            }else if(tweenAction==TweenAction.CALLBACK_COLOR){
                                tween.onUpdateColor(toColor);
                            }
                        }

                    }else if(tweenAction>=TweenAction.MOVE){
                        //

                        if(tween.animationCurve!=null){
                            newVect = tweenOnCurveVector(tween, ratioPassed);
                        }else{
                            if(tween.tweenType == LeanTweenType.linear){
                                newVect = new Vector3( tween.from.x + tween.diff.x * ratioPassed, tween.from.y + tween.diff.y * ratioPassed, tween.from.z + tween.diff.z * ratioPassed);
                            }else if(tween.tweenType >= LeanTweenType.linear){
                                switch(tween.tweenType){
                                    case LeanTweenType.easeOutQuad:
                                        newVect = new Vector3(easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
                                    case LeanTweenType.easeInQuad:
                                        newVect = new Vector3(easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutQuad:
                                        newVect = new Vector3(easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
                                    case LeanTweenType.easeInCubic:
                                        newVect = new Vector3(easeInCubic(tween.from.x, tween.to.x, ratioPassed), easeInCubic(tween.from.y, tween.to.y, ratioPassed), easeInCubic(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutCubic:
                                        newVect = new Vector3(easeOutCubic(tween.from.x, tween.to.x, ratioPassed), easeOutCubic(tween.from.y, tween.to.y, ratioPassed), easeOutCubic(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutCubic:
                                        newVect = new Vector3(easeInOutCubic(tween.from.x, tween.to.x, ratioPassed), easeInOutCubic(tween.from.y, tween.to.y, ratioPassed), easeInOutCubic(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInQuart:
                                        newVect = new Vector3(easeInQuart(tween.from.x, tween.to.x, ratioPassed), easeInQuart(tween.from.y, tween.to.y, ratioPassed), easeInQuart(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutQuart:
                                        newVect = new Vector3(easeOutQuart(tween.from.x, tween.to.x, ratioPassed), easeOutQuart(tween.from.y, tween.to.y, ratioPassed), easeOutQuart(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutQuart:
                                        newVect = new Vector3(easeInOutQuart(tween.from.x, tween.to.x, ratioPassed), easeInOutQuart(tween.from.y, tween.to.y, ratioPassed), easeInOutQuart(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInQuint:
                                        newVect = new Vector3(easeInQuint(tween.from.x, tween.to.x, ratioPassed), easeInQuint(tween.from.y, tween.to.y, ratioPassed), easeInQuint(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutQuint:
                                        newVect = new Vector3(easeOutQuint(tween.from.x, tween.to.x, ratioPassed), easeOutQuint(tween.from.y, tween.to.y, ratioPassed), easeOutQuint(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutQuint:
                                        newVect = new Vector3(easeInOutQuint(tween.from.x, tween.to.x, ratioPassed), easeInOutQuint(tween.from.y, tween.to.y, ratioPassed), easeInOutQuint(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInSine:
                                        newVect = new Vector3(easeInSine(tween.from.x, tween.to.x, ratioPassed), easeInSine(tween.from.y, tween.to.y, ratioPassed), easeInSine(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutSine:
                                        newVect = new Vector3(easeOutSine(tween.from.x, tween.to.x, ratioPassed), easeOutSine(tween.from.y, tween.to.y, ratioPassed), easeOutSine(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutSine:
                                        newVect = new Vector3(easeInOutSine(tween.from.x, tween.to.x, ratioPassed), easeInOutSine(tween.from.y, tween.to.y, ratioPassed), easeInOutSine(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInExpo:
                                        newVect = new Vector3(easeInExpo(tween.from.x, tween.to.x, ratioPassed), easeInExpo(tween.from.y, tween.to.y, ratioPassed), easeInExpo(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutExpo:
                                        newVect = new Vector3(easeOutExpo(tween.from.x, tween.to.x, ratioPassed), easeOutExpo(tween.from.y, tween.to.y, ratioPassed), easeOutExpo(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutExpo:
                                        newVect = new Vector3(easeInOutExpo(tween.from.x, tween.to.x, ratioPassed), easeInOutExpo(tween.from.y, tween.to.y, ratioPassed), easeInOutExpo(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInCirc:
                                        newVect = new Vector3(easeInCirc(tween.from.x, tween.to.x, ratioPassed), easeInCirc(tween.from.y, tween.to.y, ratioPassed), easeInCirc(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutCirc:
                                        newVect = new Vector3(easeOutCirc(tween.from.x, tween.to.x, ratioPassed), easeOutCirc(tween.from.y, tween.to.y, ratioPassed), easeOutCirc(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutCirc:
                                        newVect = new Vector3(easeInOutCirc(tween.from.x, tween.to.x, ratioPassed), easeInOutCirc(tween.from.y, tween.to.y, ratioPassed), easeInOutCirc(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInBounce:
                                        newVect = new Vector3(easeInBounce(tween.from.x, tween.to.x, ratioPassed), easeInBounce(tween.from.y, tween.to.y, ratioPassed), easeInBounce(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutBounce:
                                        newVect = new Vector3(easeOutBounce(tween.from.x, tween.to.x, ratioPassed), easeOutBounce(tween.from.y, tween.to.y, ratioPassed), easeOutBounce(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutBounce:
                                        newVect = new Vector3(easeInOutBounce(tween.from.x, tween.to.x, ratioPassed), easeInOutBounce(tween.from.y, tween.to.y, ratioPassed), easeInOutBounce(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInBack:
                                        newVect = new Vector3(easeInBack(tween.from.x, tween.to.x, ratioPassed), easeInBack(tween.from.y, tween.to.y, ratioPassed), easeInBack(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutBack:
                                        newVect = new Vector3(easeOutBack(tween.from.x, tween.to.x, ratioPassed), easeOutBack(tween.from.y, tween.to.y, ratioPassed), easeOutBack(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutBack:
                                        newVect = new Vector3(easeInOutBack(tween.from.x, tween.to.x, ratioPassed), easeInOutBack(tween.from.y, tween.to.y, ratioPassed), easeInOutBack(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInElastic:
                                        newVect = new Vector3(easeInElastic(tween.from.x, tween.to.x, ratioPassed), easeInElastic(tween.from.y, tween.to.y, ratioPassed), easeInElastic(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeOutElastic:
                                        newVect = new Vector3(easeOutElastic(tween.from.x, tween.to.x, ratioPassed), easeOutElastic(tween.from.y, tween.to.y, ratioPassed), easeOutElastic(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.easeInOutElastic:
                                        newVect = new Vector3(easeInOutElastic(tween.from.x, tween.to.x, ratioPassed), easeInOutElastic(tween.from.y, tween.to.y, ratioPassed), easeInOutElastic(tween.from.z, tween.to.z, ratioPassed)); break;
                                    case LeanTweenType.punch:
                                    case LeanTweenType.easeShake:
                                        if(tween.tweenType==LeanTweenType.punch){
                                            tween.animationCurve = LeanTween.punch;
                                        }else if(tween.tweenType==LeanTweenType.easeShake){
                                            tween.animationCurve = LeanTween.shake;
                                        }
                                        tween.to = tween.from + tween.to;
                                        tween.diff = tween.to - tween.from;
                                        if(tweenAction==TweenAction.ROTATE || tweenAction==TweenAction.ROTATE_LOCAL){
                                            tween.to = new Vector3(closestRot(tween.from.x, tween.to.x), closestRot(tween.from.y, tween.to.y), closestRot(tween.from.z, tween.to.z));
                                        }
                                        newVect = tweenOnCurveVector(tween, ratioPassed); break;
                                    case LeanTweenType.easeSpring:
                                        newVect = new Vector3(spring(tween.from.x, tween.to.x, ratioPassed), spring(tween.from.y, tween.to.y, ratioPassed), spring(tween.from.z, tween.to.z, ratioPassed)); break;

                                }
                            }else{
                                newVect = new Vector3( tween.from.x + tween.diff.x * ratioPassed, tween.from.y + tween.diff.y * ratioPassed, tween.from.z + tween.diff.z * ratioPassed);
                            }
                        }

                        if(tweenAction==TweenAction.MOVE){
                            trans.position = newVect;
                        }else if(tweenAction==TweenAction.MOVE_LOCAL){
                            trans.localPosition = newVect;
                        }else if(tweenAction==TweenAction.ROTATE){
                            /*if(tween.hasPhysics){
                                trans.gameObject.rigidbody.MoveRotation(Quaternion.Euler( newVect ));
                            }else{*/
                                trans.eulerAngles = newVect;
                            // }
                        }else if(tweenAction==TweenAction.ROTATE_LOCAL){
                            trans.localEulerAngles = newVect;
                        }else if(tweenAction==TweenAction.SCALE){
                            trans.localScale = newVect;
                        }else if(tweenAction==TweenAction.GUI_MOVE){
                            tween.ltRect.rect = new Rect( newVect.x, newVect.y, tween.ltRect.rect.width, tween.ltRect.rect.height);
                        }else if(tweenAction==TweenAction.GUI_MOVE_MARGIN){
                            tween.ltRect.margin = new Vector2(newVect.x, newVect.y);
                        }else if(tweenAction==TweenAction.GUI_SCALE){
                            tween.ltRect.rect = new Rect( tween.ltRect.rect.x, tween.ltRect.rect.y, newVect.x, newVect.y);
                        }else if(tweenAction==TweenAction.GUI_ALPHA){
                            tween.ltRect.alpha = newVect.x;
                        }else if(tweenAction==TweenAction.GUI_ROTATE){
                            tween.ltRect.rotation = newVect.x;
                        }
                    }
                    //Debug.Log("tween.delay:"+tween.delay + " tween.passed:"+tween.passed + " tweenAction:"+tweenAction + " to:"+newVect+" axis:"+tween.axis);

                    if(tween.onUpdateFloat!=null){
                        tween.onUpdateFloat(val);
                    }else if(tween.onUpdateFloatObject!=null){
                        tween.onUpdateFloatObject(val, tween.onUpdateParam);
                    }else if(tween.onUpdateVector3Object!=null){
                        tween.onUpdateVector3Object(newVect, tween.onUpdateParam);
                    }else if(tween.onUpdateVector3!=null){
                        tween.onUpdateVector3(newVect);
                    }
                    #if !UNITY_METRO
                    else if(tween.optional!=null){ // LeanTween 1.x legacy stuff

                        var onUpdate = tween.optional["onUpdate"];
                        if(onUpdate!=null){
                            Hashtable updateParam = (Hashtable)tween.optional["onUpdateParam"];
                            if((TweenAction)tweenAction==TweenAction.VALUE3){
                                if(onUpdate.GetType() == typeof(string)){
                                    string onUpdateS = onUpdate as string;
                                    customTarget = tween.optional["onUpdateTarget"]!=null ? tween.optional["onUpdateTarget"] as GameObject : trans.gameObject;
                                    customTarget.BroadcastMessage( onUpdateS, newVect );
                                }else if(onUpdate.GetType() == typeof(System.Action<Vector3, Hashtable>)){
                                    System.Action<Vector3, Hashtable> onUpdateA = (System.Action<Vector3, Hashtable>)onUpdate;
                                    onUpdateA(newVect, updateParam);
                                }else{
                                    System.Action<Vector3> onUpdateA = (System.Action<Vector3>)onUpdate;
                                    onUpdateA(newVect);
                                }
                            }else{
                                if(onUpdate.GetType() == typeof(string)){
                                    string onUpdateS = onUpdate as string;
                                    if (tween.optional["onUpdateTarget"]!=null){
                                        customTarget = tween.optional["onUpdateTarget"] as GameObject;
                                        customTarget.BroadcastMessage( onUpdateS, val );
                                    }else{
                                        trans.gameObject.BroadcastMessage( onUpdateS, val );
                                    }
                                }else if(onUpdate.GetType() == typeof(System.Action<float, Hashtable>)){
                                    System.Action<float, Hashtable> onUpdateA = (System.Action<float, Hashtable>)onUpdate;
                                    onUpdateA(val, updateParam);
                                }else if(onUpdate.GetType() == typeof(System.Action<Vector3>)){
                                    System.Action<Vector3> onUpdateA = (System.Action<Vector3>)onUpdate;
                                    onUpdateA( newVect );
                                }else{
                                    System.Action<float> onUpdateA = (System.Action<float>)onUpdate;
                                    onUpdateA(val);
                                }
                            }
                        }
                    }
                    #endif
                }

                if(isTweenFinished){
                    // Debug.Log("finished tween:"+i+" tween:"+tween);
                    if(tweenAction==TweenAction.GUI_ROTATE)
                        tween.ltRect.rotateFinished = true;

                    if(tween.loopType==LeanTweenType.once || tween.loopCount==1){
                        if(tweenAction==TweenAction.DELAYED_SOUND){
                            AudioSource.PlayClipAtPoint((AudioClip)tween.onCompleteParam, tween.to, tween.from.x);
                        }
                        if(tween.onComplete!=null){
                            removeTween(i);
                            tween.onComplete();

                        }else if(tween.onCompleteObject!=null){
                            removeTween(i);
                            tween.onCompleteObject(tween.onCompleteParam);
                        }

                        #if !UNITY_METRO
                        else if(tween.optional!=null){
                            System.Action callback=null;
                            System.Action<object> callbackWithParam = null;
                            string callbackS=string.Empty;
                            object callbackParam=null;
                            if(tween.optional!=null && tween.trans){
                                if(tween.optional["onComplete"]!=null){
                                    callbackParam = tween.optional["onCompleteParam"];
                                    if(tween.optional["onComplete"].GetType()==typeof(string)){
                                        callbackS = tween.optional["onComplete"] as string;
                                    }else{
                                        if(callbackParam!=null){
                                            callbackWithParam = (System.Action<object>)tween.optional["onComplete"];
                                        }else{
                                            callback = (System.Action)tween.optional["onComplete"];
                                            if(callback==null)
                                                Debug.LogWarning("callback was not converted");
                                        }
                                    }
                                }
                            }
                            removeTween(i);
                            if(callbackWithParam!=null){
                                callbackWithParam( callbackParam );
                            }else if(callback!=null){
                                callback();
                            }else if(callbackS!=string.Empty){
                                if (tween.optional["onCompleteTarget"]!=null){
                                    customTarget = tween.optional["onCompleteTarget"] as GameObject;
                                    if(callbackParam!=null) customTarget.BroadcastMessage ( callbackS, callbackParam );
                                    else customTarget.BroadcastMessage( callbackS );
                                }else{
                                    if(callbackParam!=null) trans.gameObject.BroadcastMessage ( callbackS, callbackParam );
                                    else trans.gameObject.BroadcastMessage( callbackS );
                                }
                            }
                        }
                        #endif
                        else{
                            removeTween(i);
                        }
                    }else{
                        if((tween.loopCount<0 && tween.type==TweenAction.CALLBACK) || tween.onCompleteOnRepeat){
                            if(tweenAction==TweenAction.DELAYED_SOUND){
                                AudioSource.PlayClipAtPoint((AudioClip)tween.onCompleteParam, tween.to, tween.from.x);
                            }
                            if(tween.onComplete!=null){
                                tween.onComplete();
                            }else if(tween.onCompleteObject!=null){
                                tween.onCompleteObject(tween.onCompleteParam);
                            }
                        }
                        if(tween.loopCount>=1){
                            tween.loopCount--;
                        }
                        if(tween.loopType==LeanTweenType.clamp){
                            tween.passed = Mathf.Epsilon;
                            // tween.delay = 0.0;
                        }else if(tween.loopType==LeanTweenType.pingPong){
                            tween.direction = 0.0f-(tween.direction);
                        }
                    }
                }else if(tween.delay<=0){
                    tween.passed += dt*tween.direction;
                }else{
                    tween.delay -= dt;
                    // Debug.Log("dt:"+dt+" tween:"+i+" tween:"+tween);
                    if(tween.delay<0){
                        tween.passed = 0.0f;//-tween.delay
                        tween.delay = 0.0f;
                    }
                }
            }
        }

        frameRendered = Time.frameCount;
        }
    }
Beispiel #50
0
 public void movePosition()
 {
     gameObjectPosition = LeanTween.moveX(this.gameObject, posX, showTime).setDelay(delayTime).setEase(easeType);
     gameObjectPosition.setOnComplete(onComplete);
 }
Beispiel #51
0
 private static Color tweenColor( LTDescr tween, float val )
 {
     Vector3 diff3 = tween.point - tween.axis;
     float diffAlpha = tween.to.y - tween.from.y;
     return new Color(tween.axis.x + diff3.x*val, tween.axis.y + diff3.y*val, tween.axis.z + diff3.z*val, tween.from.y + diffAlpha*val);
 }
    /// <summary>
    /// Shake this GameObject around its target angle.
    /// </summary>
    public void Shake()
    {
        LTDescr tweenDescription = LeanTween.rotateZ(gameObject, maxShakeAngle, shakeTime / 5).setEase(LeanTweenType.easeOutQuad);

        LeanTween.rotateZ(gameObject, defaultAngle, shakeTime).setEase(LeanTweenType.easeOutElastic).setDelay(shakeTime / 5);
    }
Beispiel #53
0
 private static Vector3 tweenOnCurveVector( LTDescr tweenDescr, float ratioPassed )
 {
     return	new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed),
                     tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.animationCurve.Evaluate(ratioPassed),
                     tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.animationCurve.Evaluate(ratioPassed) );
 }
 // Use this for initialization
 void Start()
 {
     tween = LeanTween.move(gameObject, transform.position + Vector3.one * 3f, Random.Range(2, 2)).setRepeat(-1).setLoopClamp();
 }
Beispiel #55
0
 /**
 * This line is optional. Here you can specify the maximum number of tweens you will use (the default is 400).  This must be called before any use of LeanTween is made for it to be effective.
 *
 * @method LeanTween.init
 * @param {integer} maxSimultaneousTweens:int The maximum number of tweens you will use, make sure you don't go over this limit, otherwise the code will throw an error
 * @example
 *   LeanTween.init( 800 );
 */
 public static void init(int maxSimultaneousTweens)
 {
     if(tweens==null){
     maxTweens = maxSimultaneousTweens;
     tweens = new LTDescr[maxTweens];
     _tweenEmpty = new GameObject();
     _tweenEmpty.name = "~LeanTween";
     _tweenEmpty.AddComponent(typeof(LeanTween));
     _tweenEmpty.isStatic = true;
     #if !UNITY_EDITOR
     _tweenEmpty.hideFlags = HideFlags.HideAndDontSave;
     #endif
     DontDestroyOnLoad( _tweenEmpty );
     for(int i = 0; i < maxTweens; i++){
         tweens[i] = new LTDescr();
     }
     }
 }
    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);
    }
Beispiel #57
0
    /**
    * Move a GameObject through a set of points, in local space
    *
    * @method LeanTween.moveSplineLocal
    * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
    * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd
    * @param {float} time:float The time to complete the tween in
    * @return {LTDescr} LTDescr an object that distinguishes the tween
    * @example
    * <i>Javascript:</i><br>
    * LeanTween.moveSpline(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br><br>
    * <i>C#:</i><br>
    * LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br>
    */
    public static LTDescr moveSplineLocal(GameObject gameObject, Vector3[] to, float time)
    {
        descr = options();
        descr.spline = new LTSpline( to );

        return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, descr );
    }
Beispiel #58
0
 public LTSeq insert(LTDescr tween)
 {
     this.current.tween = tween;
     tween.setDelay(this.addPreviousDelays());
     return(this.addOn());
 }
Beispiel #59
0
    public static LTDescr options()
    {
        init();

        for(j=0, i = startSearch; j < maxTweens; i++){
        if(i>=maxTweens-1)
            i = 0;
        if(tweens[i].toggle==false){
            if(i+1>tweenMaxSearch)
                tweenMaxSearch = i+1;
            startSearch = i + 1;
            break;
        }

        j++;
        if(j>=maxTweens)
            return logError("LeanTween - You have run out of available spaces for tweening. To avoid this error increase the number of spaces to available for tweening when you initialize the LeanTween class ex: LeanTween.init( "+(maxTweens*2)+" );") as LTDescr;
        }
        tween = tweens[i];
        tween.reset();
        tween.setId( (uint)i );

        return tween;
    }
Beispiel #60
0
 public void reset()
 {
     this.previous   = null;
     this.tween      = null;
     this.totalDelay = 0f;
 }