Ejemplo n.º 1
0
 //LeanTween.alpha (RectTransform)
 public static LTDescr LeanAlpha(this RectTransform rectTransform, float to, float time, bool useRecursion)
 {
     return(LeanTween.Alpha(rectTransform, to, time, useRecursion));
 }
Ejemplo n.º 2
0
        private void BuildTween(LeanTweenItem item, float delayAdd, bool generateCode, bool resetPath)
        {
            item.recursive = false; // Don't use recursive
            float delay = item.delay + delayAdd;
            bool  code  = generateCode;
            float d     = item.duration;

            if (isSimulating)
            {
                code = false;
                if (item.loopCount < 1)
                {
                    item.loopCount = defaultLoopCount;
                    itensWithInfiniteLoops.Add(item);
                }
            }

            if (item.actionStr == null)
            {
                item.actionStr = "Move";
            }
            item.action = (TweenAction)Enum.Parse(typeof(TweenAction), item.actionStr, true);

            // Debug.Log("item.gameObject:"+item.gameObject+" name:"+item.gameObject.transform.name);
            if (item.gameObject == null)
            {
                item.gameObject = gameObject;
            }

            switch (item.action)
            {
            case TweenAction.Move:
                tween = code ? Append("Move", item.to, d) : LeanTween.move(item.gameObject, item.to, d);
                break;

            case TweenAction.MoveX:
                tween = code ? Append("MoveX", item.to.x, d) : LeanTween.MoveX(item.gameObject, item.to.x, d);
                break;

            case TweenAction.MoveY:
                tween = code ? Append("MoveY", item.to.x, d) : LeanTween.moveY(item.gameObject, item.to.x, d);
                break;

            case TweenAction.MoveZ:
                tween = code ? Append("MoveZ", item.to.x, d) : LeanTween.moveZ(item.gameObject, item.to.x, d);
                break;

            case TweenAction.MoveLocal:
                tween = code ? Append("MoveLocal", item.to, d) : LeanTween.moveLocal(item.gameObject, item.to, d);
                break;

            case TweenAction.MoveLocalX:
                tween = code ? Append("MoveLocalX", item.to.x, d) : LeanTween.MoveLocalX(item.gameObject, item.to.x, d);
                break;

            case TweenAction.MoveLocalY:
                tween = code ? Append("MoveLocalY", item.to.x, d) : LeanTween.MoveLocalY(item.gameObject, item.to.x, d);
                break;

            case TweenAction.MoveLocalZ:
                tween = code ? Append("MoveLocalZ", item.to.x, d) : LeanTween.MoveLocalZ(item.gameObject, item.to.x, d);
                break;

            case TweenAction.MoveAdd:
                tween = code ? Append("MoveAdd", item.to, d) : LeanTween.MoveAdd(item.gameObject, item.to, d);
                break;

            case TweenAction.MoveBezier:
                tween = code ? append("Move", item.bezierPath ? item.bezierPath.vec3 : null, d) : LeanTween.Move(item.gameObject, item.bezierPath, d, resetPath);
                if (item.orientToPath)
                {
                    if (code)
                    {
                        codeBuild.Append(".SetOrientToPath(" + item.orientToPath.ToString().ToLower() + ")");
                    }
                    else
                    {
                        tween.SetOrientToPath(item.orientToPath);
                    }
                }
                if (item.isPath2d)
                {
                    if (code)
                    {
                        codeBuild.Append(".SetOrientToPath2d(true)");
                    }
                    else
                    {
                        tween.setOrientToPath2d(item.isPath2d);
                    }
                }
                break;

            case TweenAction.MoveBezierLocal:
                tween = code ? append("MoveLocal", item.bezierPath ? item.bezierPath.vec3 : null, d) : LeanTween.MoveLocal(item.gameObject, item.bezierPath, d, resetPath, item.alignToPath);
                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);
                    }
                }
                break;

            case TweenAction.MoveSpline:
                tween = code ? append("MoveSpline", item.splinePath ? item.splinePath.splineVector() : null, d) : LeanTween.MoveSpline(item.gameObject, item.splinePath, d, resetPath);
                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);
                    }
                }
                break;

            case TweenAction.MoveSplineLocal:
                tween = code ? append("MoveSplineLocal", item.splinePath ? item.splinePath.splineVector() : null, d) : LeanTween.MoveSplineLocal(item.gameObject, item.splinePath, d, resetPath, item.alignToPath);
                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);
                    }
                }
                break;

            case TweenAction.CanvasMove:
                tween = code ? AppendRect("Move", item.to, d) : LeanTween.Move(item.gameObject.GetComponent <RectTransform>(), item.to, d);
                break;

            case TweenAction.CanvasMoveX:
                tween = code ? AppendRect("MoveX", item.to.x, d) : LeanTween.MoveX(item.gameObject.GetComponent <RectTransform>(), item.to.x, d);
                break;

            case TweenAction.CanvasMoveY:
                tween = code ? AppendRect("MoveY", item.to.x, d) : LeanTween.MoveY(item.gameObject.GetComponent <RectTransform>(), item.to.x, d);
                break;

            case TweenAction.CanvasMoveZ:
                tween = code ? AppendRect("MoveZ", item.to.x, d) : LeanTween.MoveZ(item.gameObject.GetComponent <RectTransform>(), item.to.x, d);
                break;

            case TweenAction.CanvasMoveAdd:
                tween = code ? AppendRect("MoveAdd", item.to, d) : LeanTween.MoveAdd(item.gameObject.GetComponent <RectTransform>(), item.to, d);
                break;

            case TweenAction.CanvasMoveBezier:
                tween = code ? AppendRect("Move", item.bezierPath ? item.bezierPath.vec3 : null, d) : LeanTween.Move(item.gameObject.GetComponent <RectTransform>(), item.bezierPath, d, resetPath);
                if (item.orientToPath)
                {
                    if (code)
                    {
                        codeBuild.Append(".SetOrientToPath(" + item.orientToPath.ToString().ToLower() + ")");
                    }
                    else
                    {
                        tween.SetOrientToPath(item.orientToPath);
                    }
                }
                if (item.isPath2d)
                {
                    if (code)
                    {
                        codeBuild.Append(".SetOrientToPath2d(true)");
                    }
                    else
                    {
                        tween.setOrientToPath2d(item.isPath2d);
                    }
                }
                break;

            case TweenAction.CanvasMoveBezierLocal:
                tween = code ? AppendRect("MoveLocal", item.bezierPath ? item.bezierPath.vec3 : null, d) : LeanTween.MoveLocal(item.gameObject.GetComponent <RectTransform>(), item.bezierPath, d, resetPath, item.alignToPath);
                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);
                    }
                }
                break;

            case TweenAction.Rotate:
                tween = code ? Append("Rotate", item.to, d) : LeanTween.Rotate(item.gameObject, item.to, d);
                break;

            case TweenAction.RotateLocal:
                tween = code ? Append("RotateLocal", item.to, d) : LeanTween.RotateLocal(item.gameObject, item.to, d);
                break;

            case TweenAction.RotateX:
                tween = code ? Append("RotateX", item.to.x, d) : LeanTween.RotateX(item.gameObject, item.to.x, d);
                break;

            case TweenAction.RotateY:
                tween = code ? Append("RotateY", item.to.x, d) : LeanTween.RotateY(item.gameObject, item.to.x, d);
                break;

            case TweenAction.RotateZ:
                tween = code ? Append("RotateZ", item.to.x, d) : LeanTween.RotateZ(item.gameObject, item.to.x, d);
                break;

            case TweenAction.RotateAdd:
                tween = code ? Append("RotateAdd", item.to, d) : LeanTween.RotateAdd(item.gameObject, item.to, d);
                break;

            case TweenAction.CanvasRotate:
                tween = code ? AppendRect("Rotate", item.to, d) : LeanTween.Rotate(item.gameObject.GetComponent <RectTransform>(), item.to, d);
                break;

            case TweenAction.CanvasRotateLocal:
                tween = code ? AppendRect("RotateLocal", item.to, d) : LeanTween.RotateLocal(item.gameObject.GetComponent <RectTransform>(), item.to, d);
                break;

            case TweenAction.CanvasRotateAdd:
                tween = code ? AppendRect("RotateAdd", item.to, d) : LeanTween.RotateAdd(item.gameObject.GetComponent <RectTransform>(), item.to, d);
                break;

            case TweenAction.Scale:
                tween = code ? Append("Scale", item.to, d) : LeanTween.Scale(item.gameObject, item.to, d);
                break;

            case TweenAction.ScaleX:
                tween = code ? Append("ScaleX", item.to.x, d) : LeanTween.ScaleX(item.gameObject, item.to.x, d);
                break;

            case TweenAction.ScaleY:
                tween = code ? Append("ScaleY", item.to.x, d) : LeanTween.ScaleY(item.gameObject, item.to.x, d);
                break;

            case TweenAction.ScaleZ:
                tween = code ? Append("ScaleZ", item.to.x, d) : LeanTween.ScaleZ(item.gameObject, item.to.x, d);
                break;

            case TweenAction.ScaleAdd:
                tween = code ? Append("ScaleAdd", item.to, d) : LeanTween.ScaleAdd(item.gameObject, item.to, d);
                break;

            case TweenAction.CanvasScale:
                tween = code ? AppendRect("Scale", item.to, d) : LeanTween.Scale(item.gameObject.GetComponent <RectTransform>(), item.to, d);
                break;

            case TweenAction.CanvasScaleAdd:
                tween = code ? AppendRect("ScaleAdd", item.to, d) : LeanTween.ScaleAdd(item.gameObject.GetComponent <RectTransform>(), item.to, d);
                break;

            case TweenAction.CanvasSize:
                Vector2 to = new Vector2(item.to.x, item.to.y);
                tween = code ? appendRect("Size", to, d) : LeanTween.Size(item.gameObject.GetComponent <RectTransform>(), to, d);
                break;

            case TweenAction.CanvasSizeAdd:
                to    = new Vector2(item.to.x, item.to.y);
                tween = code ? appendRect("SizeAdd", to, d) : LeanTween.SizeAdd(item.gameObject.GetComponent <RectTransform>(), to, d);
                break;

            case TweenAction.Color:
                tween = code ? Append("Color", item.colorTo, d, item.recursive) : LeanTween.Color(item.gameObject, item.colorTo, d, item.recursive);
                break;

            case TweenAction.ColorGroup:
                tween = code ? Append("ColorGroup", item.colorTo, d) : LeanTween.ColorGroup(item.gameObject, item.colorTo, d);
                break;

            case TweenAction.Alpha:
                tween = code ? Append("Alpha", item.to.x, d, item.recursive) : LeanTween.Alpha(item.gameObject, item.to.x, d, item.recursive);
                break;

            case TweenAction.AlphaGroup:
                tween = code ? Append("AlphaGroup", item.to.x, d) : LeanTween.AlphaGroup(item.gameObject, item.to.x, d);
                break;

            case TweenAction.AlphaVertex:
                tween = code ? Append("AlphaVertex", item.to.x, d, item.recursive) : LeanTween.AlphaVertex(item.gameObject, item.to.x, d, item.recursive);
                break;

            case TweenAction.CanvasPlaySprite:
                if (generateCode)
                {
                    codeBuild.Append(tabs + "LeanTween.Play(GetComponent<RectTransform>(), new UnityEngine.Sprite[" + item.sprites.Length + "]).setFrameRate(" + item.frameRate + "f)");
                }
                else if (item.sprites != null)
                {
                    if (item.sprites.Length > 0)
                    {
                        tween = LeanTween.Play(item.gameObject.GetComponent <RectTransform>(), item.sprites).setFrameRate(item.frameRate);
                    }
                    else
                    {
                        Debug.LogError("Sprite list lenght == 0.");
                        return;
                    }
                }
                else
                {
                    Debug.LogError("Sprite list == null.");
                    return;
                }
                break;

            case TweenAction.CanvasAlpha:
                tween = code ? AppendRect("Alpha", item.to.x, d, item.recursive) : LeanTween.Alpha(item.gameObject.GetComponent <RectTransform>(), item.to.x, d, item.recursive);
                break;

            case TweenAction.CanvasTextAlpha:
                tween = code ? AppendRect("TextAlpha", item.to.x, d, item.recursive) : LeanTween.TextAlpha(item.gameObject.GetComponent <RectTransform>(), item.to.x, d, item.recursive);
                break;

            case TweenAction.CanvasGroupAlpha:
                tween = code ? AppendRect("CanvasGroup", item.to.x, d) : LeanTween.CanvasGroupAlpha(item.gameObject.GetComponent <RectTransform>(), item.to.x, d);
                break;

            case TweenAction.CanvasColor:
                tween = code ? AppendRect("Color", item.colorTo, d, item.recursive) : LeanTween.Color(item.gameObject.GetComponent <RectTransform>(), item.colorTo, d, item.recursive);
                break;

            case TweenAction.CanvasTextColor:
                tween = code ? AppendRect("TextColor", item.colorTo, d, item.recursive) : LeanTween.TextColor(item.gameObject.GetComponent <RectTransform>(), item.colorTo, d, item.recursive);
                break;

            case TweenAction.DelayedSound:
                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);
                }
                break;

            default:
                tween = null;
                Debug.Log("The tween '" + item.action.ToString() + "' has not been implemented. info item:" + item);
                return;
            }

            if (item.onCompleteItem.GetPersistentEventCount() > 0)
            {
                LeanTween.DelayedCall(gameObject, GetItemTotalTime(item), item.CallOnCompleteItem);
            }
            if (item.onCompleteLoop.GetPersistentEventCount() > 0)
            {
                float timeToWait = item.duration + item.delay;
                for (int i = 0; i < item.loopCount; i++)
                {
                    LeanTween.DelayedCall(gameObject, timeToWait, item.CallOnCompleteLoop);

                    timeToWait += item.loopDelay + item.duration;
                }
            }

            // 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(" + vecToStr(item.from) + ")");
                }
                else
                {
                    tween.SetFrom(item.from);
                }
            }
            if (item.doesLoop)
            {
                if (generateCode)
                {
                    codeBuild.Append(".SetRepeat(" + item.loopCount + ")");
                    codeBuild.Append(".SetLoopDelay(" + item.loopDelay + "f)");
                }
                else
                {
                    tween.SetLoopDelay(item.loopDelay);
                    tween.SetRepeat(item.loopCount);
                }

                if (item.loopType == LoopType.PingPong)
                {
                    if (generateCode)
                    {
                        codeBuild.Append(".SetLoopPingPong()");
                    }
                    else
                    {
                        tween.SetLoopPingPong();
                    }
                }
                else if (item.loopType == LoopType.Add)
                {
                    if (generateCode)
                    {
                        codeBuild.Append(".SetLoopAdd()");
                    }
                    else
                    {
                        tween.SetLoopAdd();
                    }
                }
            }
            if (generateCode)
            {
                if (item.useSpeed)
                {
                    codeBuild.Append(".SetSpeed(" + item.speed + "f)");
                }
            }
            else
            {
                if (item.useSpeed)
                {
                    tween.SetSpeed(item.speed);
                }
            }
            if (generateCode)
            {
                codeBuild.Append(";\n");
            }
        }
Ejemplo n.º 3
0
 //LeanTween.addListener
 //LeanTween.alpha
 public static LTDescr LeanAlpha(this GameObject gameObject, float to, float time, bool useRecursion)
 {
     return(LeanTween.Alpha(gameObject, to, time, useRecursion));
 }