Ejemplo n.º 1
0
    private static int OnUpdate(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 2);
            TweenParams   tweenParams = (TweenParams)ToLua.CheckObject(L, 1, typeof(TweenParams));
            LuaTypes      luaTypes    = LuaDLL.lua_type(L, 2);
            TweenCallback action;
            if (luaTypes != LuaTypes.LUA_TFUNCTION)
            {
                action = (TweenCallback)ToLua.CheckObject(L, 2, typeof(TweenCallback));
            }
            else
            {
                LuaFunction func = ToLua.ToLuaFunction(L, 2);
                action = (DelegateFactory.CreateDelegate(typeof(TweenCallback), func) as TweenCallback);
            }
            TweenParams o = tweenParams.OnUpdate(action);
            ToLua.PushObject(L, o);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Ejemplo n.º 2
0
        //creates a new tween with given arguments that moves along the path
        private void CreateTween()
        {
            //prepare DOTween's parameters, you can look them up here
            //http://dotween.demigiant.com/documentation.php

            TweenParams parms = new TweenParams();

            //differ between speed or time based tweening
            if (timeValue == TimeValue.speed)
            {
                parms.SetSpeedBased();
            }
            if (loopType == LoopType.yoyo)
            {
                parms.SetLoops(-1, DG.Tweening.LoopType.Yoyo);
            }

            //apply ease type or animation curve
            if (easeType == DG.Tweening.Ease.Unset)
            {
                parms.SetEase(animEaseType);
            }
            else
            {
                parms.SetEase(easeType);
            }

            if (moveToPath)
            {
                parms.OnWaypointChange(OnWaypointReached);
            }
            else
            {
                //on looptype random initialize random order of waypoints
                if (loopType == LoopType.random)
                {
                    RandomizeWaypoints();
                }
                else if (loopType == LoopType.yoyo)
                {
                    parms.OnStepComplete(ReachedEnd);
                }

                Vector3 startPos = wpPos[0];
                if (local)
                {
                    startPos = pathContainer.transform.TransformPoint(startPos);
                }
                transform.position = startPos;

                parms.OnWaypointChange(OnWaypointChange);
                parms.OnComplete(ReachedEnd);
            }

            if (pathMode == DG.Tweening.PathMode.Ignore &&
                waypointRotation != RotationType.none)
            {
                if (rotationTarget == null)
                {
                    rotationTarget = transform;
                }
                parms.OnUpdate(OnWaypointRotation);
            }

            if (local)
            {
                tween = transform.DOLocalPath(wpPos, originSpeed, pathType, pathMode)
                        .SetAs(parms)
                        .SetOptions(closeLoop, lockPosition, lockRotation)
                        .SetLookAt(lookAhead);
            }
            else
            {
                tween = transform.DOPath(wpPos, originSpeed, pathType, pathMode)
                        .SetAs(parms)
                        .SetOptions(closeLoop, lockPosition, lockRotation)
                        .SetLookAt(lookAhead);
            }

            if (!moveToPath && startPoint > 0)
            {
                GoToWaypoint(startPoint);
                startPoint = 0;
            }

            //continue new tween with adjusted speed if it was changed before
            if (originSpeed != speed)
            {
                ChangeSpeed(speed);
            }
        }
Ejemplo n.º 3
0
    public void BeginMoveByPos(
        Vector3 fromPosition,
        bool isUIPos,
        Vector3 targetPos,
        int easeType,
        float speed,
        Action onEnd
        )
    {
        this.mEnd = onEnd;
        var parent = this.transform.parent as RectTransform;

        Vector3 fromScreenPosition;

        if (isUIPos)
        {
            fromScreenPosition = RectTransformUtility.WorldToScreenPoint(null, fromPosition);
        }
        else
        {
            fromScreenPosition = Camera.main.WorldToScreenPoint(fromPosition);
        }
        // var cameraViewPostion = Camera.main.WorldToViewportPoint(fromPosition);
        mFromLocalPosition = Vector2.zero;
        RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, fromScreenPosition, null, out mFromLocalPosition);
        // Debug.LogError("cameraViewPostion" + cameraViewPostion+  "cameraFromPostion" + cameraFromPostion +  "fromPosition" + fromPosition + "fromScreenPostion " + fromScreenPostion + " fromLocalPosition: "+ fromLocalPosition);
        var toScreenPostion  = RectTransformUtility.WorldToScreenPoint(null, targetPos);
        var cameraToPosition = Camera.main.WorldToScreenPoint(targetPos);

        mToLocalPosition = Vector2.zero;
        RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, toScreenPostion, null, out mToLocalPosition);
        //Debug.LogError("cameraToPosition"+ cameraToPosition+" toScreenPostion " + toScreenPostion + " toLocalPosition: " + toLocalPosition);
        List <Vector3> listBoPint = new List <Vector3>();
        //  Vector2 range = UnityEngine.Random.insideUnitCircle;
        int factor = -1;// UnityEngine.Random.Range(0, 1) > 0.5f?1:-1;
        var length = (mFromLocalPosition + mToLocalPosition).magnitude;

        listBoPint.Add(mFromLocalPosition);
        //  listBoPint.Add(fromLocalPosition+ new Vector2(factor* length * 0.05f, factor*  length * 0.05f));
        var temp   = (mFromLocalPosition - mToLocalPosition).normalized;
        var normal = new Vector2(temp.y, -temp.x) * factor;

        listBoPint.Add(mFromLocalPosition + (mToLocalPosition - mFromLocalPosition) * 0.25f + normal * length * 0.05f);
        listBoPint.Add((mFromLocalPosition + mToLocalPosition) * 0.5f + normal * length * 0.075f);
        listBoPint.Add(mFromLocalPosition + (mToLocalPosition - mFromLocalPosition) * 0.75f + normal * length * 0.05f);
        // listBoPint.Add((fromPosition + ToPosition) / 3f + new Vector3(range.x * 50, range.y * 50, 0));
        // listBoPint.Add((fromPosition + ToPosition) * 2 / 3f + new Vector3(range.x * 50, range.y * 50, 0));
        listBoPint.Add(mToLocalPosition);
        Vector3[]   path  = GeneralPath(listBoPint);
        TweenParams parms = new TweenParams();

        parms.SetSpeedBased();
        parms.SetEase((Ease)easeType);
        parms.OnStepComplete(OnReachEnd);
        parms.OnUpdate(onMoveUpdate);
        transform.localPosition = mFromLocalPosition;
        mTween = transform.DOLocalPath(path, speed, DG.Tweening.PathType.CatmullRom, DG.Tweening.PathMode.Ignore)
                 .SetAs(parms);
        // .SetOptions(false, DG.Tweening.AxisConstraint.None, DG.Tweening.AxisConstraint.None)
        // .SetLookAt(0, Vector3.forward, Vector3.up);
        transform.localScale = Vector3.one;
        mTotalLength         = (mFromLocalPosition - mToLocalPosition).magnitude;
        mTween.Play();
    }