moveSpline() public static method

public static moveSpline ( GameObject gameObject, LTSpline, to, float time ) : LTDescr,
gameObject GameObject
to LTSpline,
time float
return LTDescr,
Beispiel #1
0
    void Start()
    {
        cr      = new LTSpline(new Vector3[] { trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position });
        sprite1 = GameObject.Find("sprite1");
        sprite2 = GameObject.Find("sprite2");
                #if !(UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
        sprite1.AddComponent <SpriteRenderer>();
        sprite1.GetComponent <SpriteRenderer>().sprite = Sprite.Create(spriteTexture, new Rect(0.0f, 0.0f, 100.0f, 100.0f), new Vector2(50.0f, 50.0f), 10.0f);
        sprite2.AddComponent <SpriteRenderer>();
        sprite2.GetComponent <SpriteRenderer>().sprite = Sprite.Create(spriteTexture, new Rect(0.0f, 0.0f, 100.0f, 100.0f), new Vector2(0.0f, 0.0f), 10.0f);
                #endif
        // LeanTween.moveSpline( ltLogo2, new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position}, 1f).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong().setOrientToPath(true);

        LTDescr zoomInPath_LT = LeanTween.moveSpline(sprite2, new Vector3[] { Vector3.zero, Vector3.zero, new Vector3(1, 1, 1), new Vector3(2, 1, 1), new Vector3(2, 1, 1) }, 1.5f).setOrientToPath2d(true);
        zoomInPath_LT.setUseEstimatedTime(true);
    }
Beispiel #2
0
    void Start()
    {
        spline = new LTSpline(new Vector3[]
                              { trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position });
        ltLogo  = GameObject.Find("LeanTweenLogo1");
        ltLogo2 = GameObject.Find("LeanTweenLogo2");

        LeanTween.moveSpline(ltLogo2, spline.pts, 1f).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong()
        .setOrientToPath(true);

        LTDescr zoomInPath_LT = LeanTween.moveSpline(ltLogo2,
                                                     new Vector3[]
                                                     { Vector3.zero, Vector3.zero, new Vector3(1, 1, 1), new Vector3(2, 1, 1), new Vector3(2, 1, 1) }, 1.5f);

        zoomInPath_LT.setUseEstimatedTime(true);
    }
Beispiel #3
0
    IEnumerator ExecuteSpline()
    {
        isExecuting = true;

        if (m_LeanType == LeanTweenType.animationCurve)
        {
            LeanTween.moveSpline(this.gameObject, m_Positions.ToArray(), m_Duration).setEase(m_AnimCurve);
        }
        else
        {
            LeanTween.moveSpline(this.gameObject, m_Positions.ToArray(), m_Duration).setEase(m_LeanType);
        }

        yield return(new WaitForSeconds(m_Duration));

        isExecuting = false;
    }
Beispiel #4
0
    private void Start()
    {
        Vector3[] path = new Vector3[] {
            cubes[0].position,
            cubes[1].position,
            cubes[2].position,
            cubes[3].position,
            cubes[4].position
        };

        visualizePath = new LTSpline(path);
        // move
        LeanTween.moveSpline(dude1, path, 10f).setOrientToPath2d(true).setSpeed(2f);

        // move Local
        LeanTween.moveSplineLocal(dude2, path, 10f).setOrientToPath2d(true).setSpeed(2f);
    }
Beispiel #5
0
 private void OnMovingBlockTriggerExit(int id)
 {
     if (id == Id)
     {
         // If the movement is completed, we need to create a new one in a reversed direction
         if (movement.ratioPassed == 1f)
         {
             movement = LeanTween.moveSpline(gameObject, spline.pts, MovementSpeed / 2).setEase(LeanTweenType.easeInOutQuad).setDirection(-1);
             rotation = LeanTween.rotate(gameObject, initialRotation.eulerAngles, MovementSpeed / 2);
         }
         else
         {
             movement.setDirection(-1).setTime(MovementSpeed / 2);
             rotation.setDirection(-1).setTime(MovementSpeed / 2);
         }
     }
 }
        private void PlayOnce(Transform[] waypoints, float timeToComplete)
        {
            if (playingAnim != null)
            {
                return;
            }

            Vector3[] animPath = Utils.SimpleSplinePath(waypoints, true); // Why did I set loop flag?

            playingAnim = LeanTween.moveSpline(gameObject, animPath, timeToComplete)
                          .setOrientToPath(true).setLoopType(LeanTweenType.once).setOnComplete(
                () =>
            {
                SetAnimation(restingAnim);
                playingAnim = null;
            }
                );
        }
        public void MoveAlongPathThen(Transform[] waypoints, float timeToComplete, string restAnim)
        {
            Vector3[] animPath = Utils.SimpleSplinePath(waypoints, false);

            if (playingAnim != null)
            {
                return;
            }

            playingAnim = LeanTween.moveSpline(gameObject, animPath, timeToComplete)
                          .setOrientToPath(true).setLoopType(LeanTweenType.once).setOnComplete(
                () =>
            {
                SetAnimation(restAnim);
                playingAnim = null;
            }
                );
        }
Beispiel #8
0
    void Start()
    {
        Vector3[] points = new Vector3[waypoints.Length];
        for (int i = 0; i < waypoints.Length; i++)
        {
            points[i] = waypoints[i].position;
        }
        pathIntro = new LTSpline(points);

        System.Array.Reverse(points);
        pathEnding = new LTSpline(points);

        if (enableRotation)
        {
            Rotation();
        }
        LeanTween.moveSpline(gameObject, pathIntro, movementDuration).setOrientToPath(true).setOnStart(OnStart.Invoke).setOnComplete(OnComplete.Invoke);
    }
Beispiel #9
0
    private void Init()
    {
        startLocalPos = transform.localPosition;

        if (target != null)
        {
            TargetPos = target.position;
        }

        LTDescr ltdescr;

        if (midPointHeightDelta > 0f)
        {
            List <Vector3> TargetPath = new List <Vector3>();
            TargetPath.Add(transform.position);             //first element indicates initial angle
            TargetPath.Add(transform.position);             //first element indicates initial angle
            TargetPath.Add(((TargetPos + transform.position) / 2) + new Vector3(0f, midPointHeightDelta, 0f));
            TargetPath.Add(TargetPos);
            TargetPath.Add(TargetPos);             //must be added twice since last element only indicates final angle
            ltdescr = LeanTween.moveSpline(gameObject, TargetPath.ToArray(), time);
        }
        else
        {
            ltdescr = LeanTween.move(gameObject, TargetPos, time);
        }

        if (easeType == LeanTweenType.animationCurve)
        {
            ltdescr.setEase(easingCurve);
            ltdescr.setOrientToPath(orientToPath);
        }
        else
        {
            ltdescr.setEase(easeType);
        }

        if (speed > 0f)
        {
            ltdescr.setSpeed(speed);
        }

        ltdescr.setDestroyOnComplete(destroyOnComplete);
        ltdescr.setOnComplete(OnComplete);
    }
Beispiel #10
0
    private void Start()
    {
        // select every transform.position from the List<Transform> Points
        spline = new LTSpline(Points.Select(transform => transform.position).ToArray());

        initialRotation = transform.rotation;
        finalRotation   = Points.Last().rotation;

        if (StartPingPongOnLoad)
        {
            movement = LeanTween.moveSpline(gameObject, spline.pts, MovementSpeed).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong();
            rotation = LeanTween.rotate(gameObject, finalRotation.eulerAngles, MovementSpeed).setLoopPingPong();
        }
        else
        {
            GameEvents.Instance.onMovingBlockTriggerEnter += OnMovingBlockTriggerEnter;
            GameEvents.Instance.onMovingBlockTriggerExit  += OnMovingBlockTriggerExit;
        }
    }
Beispiel #11
0
        public override void SpawnUnits(int numUnits)
        {
            for (int i = 0; i < numUnits; i++)
            {
                var go = Instantiate(abaUnitPrefab);
                go.transform.position = GetEdgePointWithinInfluence();

                go.transform.SetParent(unitsContainer);
                var unit = go.GetComponent <AbaUnit>();
                unit.agent.map = map;
                unit.tower     = this;

                var scale = unit.transform.localScale;
                unit.transform.localScale = Vector3.zero;

                unitSpawnTrail.emitting = true;
                unitSpawnTrail.transform.localPosition = Vector2.zero;
                AddUnit(unit);
                var      seq      = LeanTween.sequence();
                LTSpline ltSpline = new LTSpline(
                    new Vector3[] {
                    new Vector3(UnityEngine.Random.Range(0, 1), UnityEngine.Random.Range(0, 1), 0f),
                    transform.position,
                    unit.transform.position,
                    new Vector3(UnityEngine.Random.Range(0, 1), UnityEngine.Random.Range(0, 1), 0f)
                });
                seq.append(LeanTween.moveSpline(unitSpawnTrail.gameObject, ltSpline, 0.1f));

                seq.append(LeanTween.scale(unit.gameObject, scale * 2, 0.1f));
                seq.append(LeanTween.scale(unit.gameObject, scale, 0.25f));
                seq.append(() =>
                {
                    if (unitSpawnTrail)
                    {
                        //Debug.Break();
                        unitSpawnTrail.emitting = false;
                        unitSpawnTrail.transform.localPosition = Vector2.zero;
                    }
                });
            }
        }
Beispiel #12
0
    public void ThrowTheItemPoker(int idxItem, int from, int to)
    {
        GameObject o = Instantiate(prefabItem[idxItem]);

        o.transform.position = _PokerGameManager.instance.stockParasite[from].uiPlayerPoker.postThrowTarget.position;
        Vector3 target = _PokerGameManager.instance.stockParasite[to].uiPlayerPoker.postThrowTarget.position;

        o.transform.LookAt(target);

        if (curveThrow[idxItem])
        {
            Vector3 middleVector = new Vector3(target.x - o.transform.position.x, 50f, target.z - o.transform.position.z);

            Vector3 startAngle = o.transform.position - (middleVector * 0.25f);
            Vector3 endAngle   = new Vector3(target.x + (middleVector.x * 0.25f), target.y - (middleVector.y * 0.25f), target.z + (middleVector.z * 0.25f));

            LeanTween.moveSpline(o, new Vector3[] { startAngle, o.transform.position, target, endAngle }, 0.8f).setEaseInQuad().setOnComplete(() => { CompleteThrow(o, _PokerGameManager.instance.stockParasite[to].uiPlayerPoker.hero, idxItem); });
        }
        else
        {
            LeanTween.move(o, target, 0.8f).setOnComplete(() => { CompleteThrow(o, _PokerGameManager.instance.stockParasite[to].uiPlayerPoker.hero, idxItem); });
        }
    }
Beispiel #13
0
    public void creatIcon()
    {
        int count = Random.Range(19, 20);

        for (int i = 1; i <= count; i++)
        {
            GameObject     obj = new GameObject();
            SpriteRenderer sr  = obj.AddComponent <SpriteRenderer>();
            sr.sprite = Materiral.GetIconByName("actionIcon_6");

            Vector3 endpos = new Vector3(startpos.x + Random.Range(-0.5f, 0.5f), startpos.y + Random.Range(-0.05f, 0.05f), 0);

            float randomheight = Random.Range(0.3f, 0.6f);
            float time         = Mathf.Abs(randomheight);
            Debug.Log(randomheight);
            Vector3[] _path = new Vector3[] { startpos, startpos, new Vector3(endpos.x / 2, randomheight + startpos.y, startpos.z), endpos, endpos };
            LeanTween.moveSpline(obj, _path, time).setOnComplete(() => {
                LeanTween.moveY(obj, randomheight / 5 + startpos.y, time / 5).setOnComplete(() => {
                    LeanTween.moveY(obj, endpos.y, time / 5).setEase(LeanTweenType.easeOutBounce);
                });
            });
        }
    }
Beispiel #14
0
        public void Run()
        {
            if (animPath == null)
            {
                return;
            }

            Debug.Log("*** Run() called in SimplePathAnimator ***");

            if (cycle)
            {
                LeanTween.moveSpline(gameObject, animPath, time)
                .setOrientToPath(true)
                .setLoopClamp();
            }
            else
            {
                LeanTween.moveSpline(gameObject, animPath, time)
                //.setEase(LeanTweenType.easeOutQuad) // No easing until I sync animation
                .setOrientToPath(true)
                .setOnComplete(() =>
                {
                    if (OnComplete != null)
                    {
                        Debug.Log("Calling OnComplete");
                        OnComplete();
                    }
                    OnMoveComplete();

                    if (ueOnComplete != null)
                    {
                        Debug.Log("Calling ueOnComplete");
                        ueOnComplete.Invoke();
                    }
                });
            }
        }
        private void SendTrail(float duration)
        {
            var go = Instantiate(trailPrefab);

            go.transform.position = transform.position;
            var currencyRT =
                Util.bootController.gameplayUI.currencyContainer.GetComponent <RectTransform>();

            var targetPos = Util.GetUIWorldPos(currencyRT);

            targetPos.z = transform.position.z;

            LTSpline ltSpline = new LTSpline(
                new Vector3[] {
                new Vector3(UnityEngine.Random.Range(-10, 10), UnityEngine.Random.Range(-10, 10), 0f),
                transform.position,
                targetPos,
                targetPos
            });

            // for (int i = 0; i < 10; i++)
            // {
            //     if (i + 1 < 10)
            //     {
            //         var point1 = ltSpline.point(i / 10.0f);
            //         var point2 = ltSpline.point((i + 1) / 10.0f);
            //         Debug.DrawLine(point1, point2, Color.red);
            //     }
            // }

            // Debug.Break();

            LeanTween.moveSpline(go, ltSpline, duration).setOnComplete(() =>
            {
                Destroy(go);
            });
        }
Beispiel #16
0
 public static LTDescr LeanMoveSpline(this Transform transform, LTSpline to, float time)
 {
     return(LeanTween.moveSpline(transform.gameObject, to, time));
 }
Beispiel #17
0
 void DoPath()
 {
     LeanTween.moveSpline(moveObject.gameObject, tweenPath.vec3, 2.5f).setOrientToPath2d(true).setDelay(1.0f).setEase(LeanTweenType.easeInOutQuad).setOnUpdate(this.onUpdate).setOnComplete(this.onCompletePath);
 }
Beispiel #18
0
 public void EndingTween()
 {
     LeanTween.moveSpline(gameObject, pathEnding, 20f).setOrientToPath(true).setOnStart(OnStart.Invoke).setOnComplete(OnEndingCompleted.Invoke).setDelay(4f);
 }
Beispiel #19
0
 public static LTDescr LeanMoveSpline(this GameObject gameObject, LTSpline to, float time)
 {
     return(LeanTween.moveSpline(gameObject, to, time));
 }
Beispiel #20
0
        private void buildTween(LeanTweenItem item, float delayAdd, bool generateCode)
        {
            float delay = item.delay + delayAdd;
            bool  code  = generateCode;
            float d     = item.duration;

            // Debug.Log("item:"+item.action);
            if (item.action == TweenAction.ALPHA)
            {
                tween = code ? append("alpha", item.to.x, d) : LeanTween.alpha(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.ALPHA_VERTEX)
            {
                tween = code ? append("alphaVertex", item.to.x, d) : LeanTween.alphaVertex(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.MOVE)
            {
                tween = code ? append("move", item.to, d) : LeanTween.move(gameObject, item.to, d);
            }
            else if (item.action == TweenAction.MOVE_LOCAL)
            {
                tween = code ? append("moveLocal", item.to, d) : LeanTween.moveLocal(gameObject, item.to, d);
            }
            else if (item.action == TweenAction.MOVE_LOCAL_X)
            {
                tween = code ? append("moveLocalX", item.to.x, d) : LeanTween.moveLocalX(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.MOVE_LOCAL_Y)
            {
                tween = code ? append("moveLocalY", item.to.x, d) : LeanTween.moveLocalY(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.MOVE_LOCAL_Z)
            {
                tween = code ? append("moveLocalZ", item.to.x, d) : LeanTween.moveLocalZ(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.MOVE_X)
            {
                tween = code ? append("moveX", item.to.x, d) : LeanTween.moveX(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.MOVE_Y)
            {
                tween = code ? append("moveY", item.to.x, d) : LeanTween.moveY(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.MOVE_Z)
            {
                tween = code ? append("moveZ", item.to.x, d) : LeanTween.moveZ(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.MOVE_CURVED)
            {
                tween = code ? append("move", item.bezierPath ? item.bezierPath.vec3 : null, d) : LeanTween.move(gameObject, item.bezierPath.vec3, d);
                if (item.orientToPath)
                {
                    if (code)
                    {
                        codeBuild.Append(".setOrientToPath(" + item.orientToPath + ")");
                    }
                    else
                    {
                        tween.setOrientToPath(item.orientToPath);
                    }
                }
                if (item.isPath2d)
                {
                    if (code)
                    {
                        codeBuild.Append(".setOrientToPath2d(true)");
                    }
                    else
                    {
                        tween.setOrientToPath2d(item.isPath2d);
                    }
                }
            }
            else if (item.action == TweenAction.MOVE_CURVED_LOCAL)
            {
                tween = code ? append("moveLocal", item.bezierPath ? item.bezierPath.vec3 : null, d) : LeanTween.moveLocal(gameObject, item.bezierPath.vec3, d);
                if (item.orientToPath)
                {
                    if (code)
                    {
                        codeBuild.Append(".setOrientToPath(" + item.orientToPath + ")");
                    }
                    else
                    {
                        tween.setOrientToPath(item.orientToPath);
                    }
                }
                if (item.isPath2d)
                {
                    if (code)
                    {
                        codeBuild.Append(".setOrientToPath2d(true)");
                    }
                    else
                    {
                        tween.setOrientToPath2d(item.isPath2d);
                    }
                }
            }
            else if (item.action == TweenAction.MOVE_SPLINE)
            {
                tween = code ? append("moveSpline", item.splinePath ? item.splinePath.splineVector() : null, d) : LeanTween.moveSpline(gameObject, item.splinePath.splineVector(), d);
                if (item.orientToPath)
                {
                    if (code)
                    {
                        codeBuild.Append(".setOrientToPath(" + item.orientToPath + ")");
                    }
                    else
                    {
                        tween.setOrientToPath(item.orientToPath);
                    }
                }
                if (item.isPath2d)
                {
                    if (code)
                    {
                        codeBuild.Append(".setOrientToPath2d(true)");
                    }
                    else
                    {
                        tween.setOrientToPath2d(item.isPath2d);
                    }
                }
            }
            else if (item.action == TweenAction.ROTATE)
            {
                tween = code ? append("rotate", item.to, d) : LeanTween.rotate(gameObject, item.to, d);
            }
            else if (item.action == TweenAction.ROTATE_AROUND)
            {
                if (generateCode)
                {
                    codeBuild.Append(tabs + "LeanTween.rotateAround(gameObject, " + vecToStr(item.axis) + ", " + item.to.x + "f , " + d + "f)");
                }
                else
                {
                    tween = LeanTween.rotateAround(gameObject, item.axis, item.to.x, d);
                }
            }
            else if (item.action == TweenAction.ROTATE_AROUND_LOCAL)
            {
                if (generateCode)
                {
                    codeBuild.Append(tabs + "LeanTween.rotateAroundLocal(gameObject, " + vecToStr(item.axis) + ", " + item.to.x + "f , " + d + "f)");
                }
                else
                {
                    tween = LeanTween.rotateAroundLocal(gameObject, item.axis, item.to.x, d);
                }
            }
            else if (item.action == TweenAction.ROTATE_LOCAL)
            {
                tween = code ? append("rotateLocal", item.to, d) : LeanTween.rotateLocal(gameObject, item.to, d);
            }
            else if (item.action == TweenAction.ROTATE_X)
            {
                tween = code ? append("rotateX", item.to.x, d) : LeanTween.rotateX(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.ROTATE_Y)
            {
                tween = code ? append("rotateY", item.to.x, d) : LeanTween.rotateY(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.ROTATE_Z)
            {
                tween = code ? append("rotateZ", item.to.x, d) : LeanTween.rotateZ(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.SCALE)
            {
                tween = code ? append("scale", item.to, d) : LeanTween.scale(gameObject, item.to, d);
            }
            else if (item.action == TweenAction.SCALE_X)
            {
                tween = code ? append("scaleX", item.to.x, d) : LeanTween.scaleX(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.SCALE_Y)
            {
                tween = code ? append("scaleY", item.to.x, d) : LeanTween.scaleY(gameObject, item.to.x, d);
            }
            else if (item.action == TweenAction.SCALE_Z)
            {
                tween = code ? append("scaleZ", item.to.x, d) : LeanTween.scaleZ(gameObject, item.to.x, d);
            }
                        #if !UNITY_4_3 && !UNITY_4_5
            else if (item.action == TweenAction.CANVAS_MOVE)
            {
                tween = code ? appendRect("move", item.to, d) : LeanTween.move(GetComponent <RectTransform>(), item.to, d);
            }
            else if (item.action == TweenAction.CANVAS_SCALE)
            {
                tween = code ? appendRect("scale", item.to, d) : LeanTween.scale(GetComponent <RectTransform>(), item.to, d);
            }
            else if (item.action == TweenAction.CANVAS_ROTATEAROUND)
            {
                if (generateCode)
                {
                    codeBuild.Append(tabs + "LeanTween.rotateAround(rectTransform, " + vecToStr(item.axis) + ", " + item.to.x + "f , " + d + "f)");
                }
                else
                {
                    tween = LeanTween.rotateAround(GetComponent <RectTransform>(), item.axis, item.to.x, d);
                }
            }
            else if (item.action == TweenAction.CANVAS_ROTATEAROUND_LOCAL)
            {
                if (generateCode)
                {
                    codeBuild.Append(tabs + "LeanTween.rotateAroundLocal(rectTransform, " + vecToStr(item.axis) + ", " + item.to.x + "f , " + d + "f)");
                }
                else
                {
                    tween = LeanTween.rotateAroundLocal(GetComponent <RectTransform>(), item.axis, item.to.x, d);
                }
            }
            else if (item.action == TweenAction.CANVAS_ALPHA)
            {
                tween = code ? appendRect("alpha", item.to.x, d) : LeanTween.alpha(GetComponent <RectTransform>(), item.to.x, d);
            }
            else if (item.action == TweenAction.CANVAS_COLOR)
            {
                tween = code ? appendRect("color", item.colorTo, d) : LeanTween.color(GetComponent <RectTransform>(), item.colorTo, d);
            }
            else if (item.action == TweenAction.TEXT_ALPHA)
            {
                tween = code ? appendRect("textAlpha", item.to.x, d) : LeanTween.textAlpha(GetComponent <RectTransform>(), item.to.x, d);
            }
            else if (item.action == TweenAction.TEXT_COLOR)
            {
                tween = code ? appendRect("textColor", item.colorTo, d) : LeanTween.textColor(GetComponent <RectTransform>(), item.colorTo, d);
            }
            else if (item.action == TweenAction.CANVAS_PLAYSPRITE)
            {
                if (generateCode)
                {
                    codeBuild.Append(tabs + "LeanTween.play(rectTransform, sprites).setFrameRate(" + item.frameRate + "f)");
                }
                else
                {
                    tween = LeanTween.play(GetComponent <RectTransform>(), item.sprites).setFrameRate(item.frameRate);
                }
            }
                        #endif
            else if (item.action == TweenAction.COLOR)
            {
                tween = code ? append("color", item.colorTo, d) : LeanTween.color(gameObject, item.colorTo, d);
            }
            else if (item.action == TweenAction.DELAYED_SOUND)
            {
                if (generateCode)
                {
                    codeBuild.Append(tabs + "LeanTween.delayedSound(gameObject, passAudioClipHere, " + vecToStr(item.from) + ", " + d + "f)");
                }
                else
                {
                    tween = LeanTween.delayedSound(gameObject, item.audioClip, item.from, item.duration);
                }
            }
            else
            {
                tween = null;
                Debug.Log("The tween '" + item.action.ToString() + "' has not been implemented. info item:" + item);
                return;
            }


            // Append Extras
            if (generateCode)
            {
                if (delay > 0f)
                {
                    codeBuild.Append(".setDelay(" + delay + "f)");
                }
            }
            else
            {
                tween = tween.setDelay(delay);
            }
            if (item.ease == LeanTweenType.animationCurve)
            {
                if (generateCode)
                {
                    codeBuild.Append(".setEase(");
                    append(item.animationCurve);
                    codeBuild.Append(")");
                }
                else
                {
                    tween.setEase(item.animationCurve);
                }
            }
            else
            {
                if (generateCode)
                {
                    if (item.ease != LeanTweenType.linear)
                    {
                        codeBuild.Append(".setEase(LeanTweenType." + item.ease + ")");
                    }
                }
                else
                {
                    tween.setEase(item.ease);
                }
            }
            // Debug.Log("curve:"+item.animationCurve+" item.ease:"+item.ease);
            if (item.between == LeanTweenBetween.FromTo)
            {
                if (generateCode)
                {
                    codeBuild.Append(".setFrom(" + item.from + ")");
                }
                else
                {
                    tween.setFrom(item.from);
                }
            }
            if (item.doesLoop)
            {
                if (generateCode)
                {
                    codeBuild.Append(".setRepeat(" + item.loopCount + ")");
                }
                else
                {
                    tween.setRepeat(item.loopCount);
                }

                if (item.loopType == LeanTweenType.pingPong)
                {
                    if (generateCode)
                    {
                        codeBuild.Append(".setLoopPingPong()");
                    }
                    else
                    {
                        tween.setLoopPingPong();
                    }
                }
            }
            if (generateCode)
            {
                codeBuild.Append(";\n");
            }
        }
Beispiel #21
0
 public static LTDescr LTMoveSpline(this Transform self, List <Vector3> to, float time)
 {
     return(LeanTween.moveSpline(self.gameObject, to.ToArray(), time));
 }
 void Start()
 {
     s = new LTSpline(ltPath.splineVector());
     LeanTween.moveSpline(ltLogo, s.pts, .6f).setEase(LeanTweenType.easeOutQuad);
 }
Beispiel #23
0
    void Start()
    {
        LeanTest.timeout  = 46f;
        LeanTest.expected = 35;

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

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

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

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

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

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

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

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

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

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

        LeanTween.reset();


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

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

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

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

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

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

        GameObject cubeDest = Instantiate(boxNoCollider) as GameObject;

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

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

        cubeToTrans.name = "cubeToTrans";

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

        GameObject cubeDestroy = Instantiate(boxNoCollider) as GameObject;

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

        GameObject cubeSpline = Instantiate(boxNoCollider) as GameObject;

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

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

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

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


        StartCoroutine(timeBasedTesting());
    }
        ////////////////////////////////////////////////////////////////////////
        // 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
 */
                }
            }
        }
Beispiel #25
0
 void ShinePathDirection()
 {
     LeanTween.moveSpline(shine, pathSpline, 10f).setSpeed(5f).setOnComplete(ShinePathDirection);
 }
Beispiel #26
0
 public void MoveTrain()
 {
     movingObject.SetActive(true);
     LeanTween.moveSpline(movingObject, cr.pts, RotationDurationInSeconds).setOrientToPath(true).setRepeat(-1).setDirection(1f);
 }
Beispiel #27
0
        void Start()
        {
//			Time.timeScale = 0.25f;

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

            LeanTween.init(15 + 1200);

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

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

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

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

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

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

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

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

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

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

            LeanTween.reset();

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

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

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

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

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

            // OnStart Speed Test for ignoreTimeScale vs normal timeScale

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

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

            GameObject cubeToTrans = cubeNamed("cubeToTrans");

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

            GameObject cubeDestroy = cubeNamed("cubeDestroy");

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

            GameObject cubeSpline = cubeNamed("cubeSpline");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            Vector3 beforePos2 = cubeAlpha2.transform.localPosition;

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

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

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

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

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

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

            // value2
            bool value2UpdateCalled = false;

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

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

            StartCoroutine(timeBasedTesting());
        }
Beispiel #28
0
 private void StartMovement()
 {
     LeanTween.cancel(gameObject);
     Vector3[] path = GeneratePath(12, -14f, 14f);
     LeanTween.moveSpline(gameObject, path, moveDuration).setOnComplete(StartMovement).setDelay(delay);
 }
 void Start()
 {
     LeanTween.moveSpline(lt, mg.ltpath, life);
     this.gameObject.GetComponent <TrailRenderer>().enabled = true;
     Invoke("destroythis", life);
 }
Beispiel #30
0
        void Start()
        {
//			Time.timeScale = 0.25f;

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

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

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

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

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

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

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

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

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

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

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

            LeanTween.reset();

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

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

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

            // OnStart Speed Test for ignoreTimeScale vs normal timeScale

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

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

            GameObject cubeToTrans = cubeNamed("cubeToTrans");

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

            GameObject cubeDestroy = cubeNamed("cubeDestroy");

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

            GameObject cubeSpline = cubeNamed("cubeSpline");

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

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

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

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

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

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

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

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

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

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

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

            LeanTween.rotateAround(cubeRotateA, Vector3.forward, 90f, 0.3f).setOnComplete(() => {
                LeanTest.expect(cubeRotateA.transform.eulerAngles.z == 90f, "ROTATE AROUND", "expected rotate z:" + 90f + " returned:" + cubeRotateA.transform.eulerAngles.z);
            });
            // Alpha, onUpdate with passing value, onComplete value
            LeanTween.alpha(cubeAlpha1, 0.5f, 0.1f).setOnUpdate((float val) => {
                LeanTest.expect(val != 0f, "ON UPDATE VAL");
            }).setOnCompleteParam("Hi!").setOnComplete((object completeObj) => {
                LeanTest.expect(((string)completeObj) == "Hi!", "ONCOMPLETE OBJECT");
                LeanTest.expect(cubeAlpha1.GetComponent <Renderer>().material.color.a == 0.5f, "ALPHA");
            });
            // Color
            float onStartTime = -1f;

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

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

            Vector3 beforePos2 = cubeAlpha2.transform.localPosition;

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

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

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

            StartCoroutine(timeBasedTesting());
        }