/// <summary>Tweens a Rigidbody2D's position to the given value, while also applying a jump effect along the Y axis.
        /// Returns a Sequence instead of a Tweener.
        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations.
        /// <para>IMPORTANT: a rigidbody2D can't be animated in a jump arc using MovePosition, so the tween will directly set the position</para></summary>
        /// <param name="endValue">The end value to reach</param>
        /// <param name="jumpPower">Power of the jump (the max height of the jump is represented by this plus the final Y offset)</param>
        /// <param name="numJumps">Total number of jumps</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
        public static Sequence DOJump(this Rigidbody2D target, Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping = false)
        {
            if (numJumps < 1)
            {
                numJumps = 1;
            }
            float    startPosY  = 0;
            float    offsetY    = -1;
            bool     offsetYSet = false;
            Sequence s          = DOTween.Sequence();
            Tween    yTween     = DOTween.To(() => target.position, x => target.position = x, new Vector2(0, jumpPower), duration / (numJumps * 2))
                                  .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative()
                                  .SetLoops(numJumps * 2, LoopType.Yoyo)
                                  .OnStart(() => startPosY = target.position.y);

            s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector2(endValue.x, 0), duration)
                     .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
                     ).Join(yTween)
            .SetTarget(target).SetEase(DOTween.defaultEaseType);
            yTween.OnUpdate(() =>
            {
                if (!offsetYSet)
                {
                    offsetYSet = true;
                    offsetY    = s.isRelative ? endValue.y : endValue.y - startPosY;
                }
                Vector3 pos = target.position;
                pos.y      += DOVirtual.EasedValue(0, offsetY, yTween.ElapsedPercentage(), Ease.OutQuad);
                target.MovePosition(pos);
            });
            return(s);
        }
예제 #2
0
        public static Sequence DOJump(this Rigidbody target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false)
        {
            if (numJumps < 1)
            {
                numJumps = 1;
            }
            float    startPosY  = 0f;
            float    offsetY    = -1f;
            bool     offsetYSet = false;
            Sequence s          = DOTween.Sequence();
            Tween    yTween     = DOTween.To(() => target.position, target.MovePosition, new Vector3(0f, jumpPower, 0f), duration / (float)(numJumps * 2)).SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad)
                                  .SetRelative()
                                  .SetLoops(numJumps * 2, LoopType.Yoyo)
                                  .OnStart(delegate
            {
                Vector3 position2 = target.position;
                startPosY         = position2.y;
            });

            s.Append(DOTween.To(() => target.position, target.MovePosition, new Vector3(endValue.x, 0f, 0f), duration).SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)).Join(DOTween.To(() => target.position, target.MovePosition, new Vector3(0f, 0f, endValue.z), duration).SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear)).Join(yTween)
            .SetTarget(target)
            .SetEase(DOTween.defaultEaseType);
            yTween.OnUpdate(delegate
            {
                if (!offsetYSet)
                {
                    offsetYSet = true;
                    offsetY    = ((!s.isRelative) ? (endValue.y - startPosY) : endValue.y);
                }
                Vector3 position = target.position;
                position.y      += DOVirtual.EasedValue(0f, offsetY, yTween.ElapsedPercentage(), Ease.OutQuad);
                target.MovePosition(position);
            });
            return(s);
        }
예제 #3
0
    static int ElapsedPercentage(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                DG.Tweening.Tween obj = (DG.Tweening.Tween)ToLua.CheckObject <DG.Tweening.Tween>(L, 1);
                float             o   = obj.ElapsedPercentage();
                LuaDLL.lua_pushnumber(L, o);
                return(1);
            }
            else if (count == 2)
            {
                DG.Tweening.Tween obj = (DG.Tweening.Tween)ToLua.CheckObject <DG.Tweening.Tween>(L, 1);
                bool  arg0            = LuaDLL.luaL_checkboolean(L, 2);
                float o = obj.ElapsedPercentage(arg0);
                LuaDLL.lua_pushnumber(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: DG.Tweening.Tween.ElapsedPercentage"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
예제 #4
0
    static int ElapsedPercentage(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        DG.Tweening.Tween obj = (DG.Tweening.Tween)LuaScriptMgr.GetNetObjectSelf(L, 1, "DG.Tweening.Tween");
        bool  arg0            = LuaScriptMgr.GetBoolean(L, 2);
        float o = obj.ElapsedPercentage(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
예제 #5
0
 static int ElapsedPercentage(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         DG.Tweening.Tween obj = (DG.Tweening.Tween)ToLua.CheckObject(L, 1, typeof(DG.Tweening.Tween));
         bool  arg0            = LuaDLL.luaL_checkboolean(L, 2);
         float o = obj.ElapsedPercentage(arg0);
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }