Ejemplo n.º 1
0
        private bool M_Check()
        {
            if (isMoving)
            {
                return(false);
            }

            if (m_lastToNode != m_toNode)
            {
                Vector3 v = transform.position;
                v.z = 0;

                Vector3 dirVector = m_toNode - v;
                m_distance   = dirVector.magnitude;
                m_lastToNode = m_toNode;
                if (!GameUtils.EqualZero(m_distance) && m_distance > 0)
                {
                    isMoving = true;
                    PlayerAniConifg.directionStatus nowDirection = PlayerAniConifg.getDirection(dirVector.x, dirVector.y);
                    bool isChange = false;
                    isChange |= aniCtrl.SetDirection((int)nowDirection);
                    isChange |= aniCtrl.SetAction((int)PlayerAniConifg.actionStatus.WALK);
                    if (isChange)
                    {
                        aniCtrl.playAllAnimation();
                    }

                    m_speed = _speed * dirVector.normalized;
                    switch (nowDirection)
                    {
                    case PlayerAniConifg.directionStatus.EAST:
                    case PlayerAniConifg.directionStatus.WEST:
                        m_speed *= AstarPath.active.astarData.gridGraph.aspectRatio;
                        break;

                    case PlayerAniConifg.directionStatus.NORTHEAST:
                    case PlayerAniConifg.directionStatus.NORTHWEST:
                    case PlayerAniConifg.directionStatus.SOUTHEAST:
                    case PlayerAniConifg.directionStatus.SOUTHWEST:
                        m_speed *= Mathf.Sqrt(AstarPath.active.astarData.gridGraph.aspectRatio * AstarPath.active.astarData.gridGraph.aspectRatio + 1f);
                        break;

                    default:
                        break;
                    }
                    return(true);
                }
                else
                {
                    m_distance = 0;
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
    void CheckRotation(string name, PlayerAniConifg.directionStatus direction, tk2dSpriteAnimator animator)
    {
        Vector3 scale      = animator.Sprite.scale;
        bool    isNegative = PlayerAniConifg.isNativeDirection(direction);

        if ((scale.x < 0 && !isNegative) || (scale.x > 0 && isNegative))
        {
            scale.x = -scale.x;
            animator.Sprite.scale = scale;
        }
    }
Ejemplo n.º 3
0
    public bool SetDirection(int dir)
    {
        if (action == PlayerAniConifg.actionStatus.DIE)
        {
            return(false);
        }

        bool changed = false;

        PlayerAniConifg.directionStatus newDir = (PlayerAniConifg.directionStatus)dir;
        changed   = newDir != direction;
        direction = newDir;
        return(changed);
    }
Ejemplo n.º 4
0
    string GetClipName(PlayerAniConifg.directionStatus direction, PlayerAniConifg.actionStatus act, bool isRiding)
    {
        string dirName = PlayerAniConifg.getSceneDirectionRes(direction);

        if (act == PlayerAniConifg.actionStatus.IDEL && isRiding)
        {
            act = PlayerAniConifg.actionStatus.RIDEIDEL;
        }
        else if (act == PlayerAniConifg.actionStatus.WALK && isRiding)
        {
            act = PlayerAniConifg.actionStatus.RIDEWALK;
        }

        string actName  = PlayerAniConifg.getActionStatusToString(act);
        string clipName = dirName + "_" + actName;

        return(clipName);
    }
Ejemplo n.º 5
0
    void Update()
    {
        if (MapSceneDataManage.Instance().isChangingScene)
        {
            _toNode   = null;
            _distance = 0;
            return;
        }

        if (_distance > 0)
        {
            Vector3 moveSegment = _speed * Time.deltaTime;
            AILerp.me.transform.position += moveSegment;
            _distance -= moveSegment.magnitude;
            if (_distance <= 0)
            {
                if (null != AILerp.me.playerAniControl.doSkill)
                {
                    AILerp.me.playerAniControl.doSkill();
                    AILerp.me.playerAniControl.doSkill = null;
                }

                if (!_joystickStarted)
                {
                    _Stop();
                }
            }
        }
        else if (_joystickEnded)
        {
            _Stop();
            _joystickEnded = false;
        }

        if (AILerp.me && AILerp.me.canMove && (CheckKey() || _joystickStarted))
        {
            //   if (_moveDir.magnitude < 0.2f || _distance > 0) return;
            if (_distance <= 0)
            {
                dispatch(TOUCH_E_TOUCH, null, Vector3.zero);
                JoystickTouch touchDir = _vectorToDir(_moveDir);
                Vector3       vec      = AILerp.me.transform.position;
                vec.z = 0f;
                Pathfinding.NNInfo nodeInfo = AstarPath.active.GetNearest(vec);

                _toNode = null;
                for (int i = 0; i < m_refindList[touchDir].Count; i++)
                {
                    Pathfinding.GridNode node = AstarPath.active.astarData.gridGraph.GetNodeConnection((Pathfinding.GridNode)nodeInfo, (int)(m_refindList[touchDir][i]));
                    if (node != null && node.Walkable)
                    {
                        _toNode  = node;
                        touchDir = m_refindList[touchDir][i];
                        break;
                    }
                }

                JoystickTouchToDir(touchDir, ref _dirVector);
                float angle = Mathf.Atan2(_dirVector.x, -_dirVector.y) * Mathf.Rad2Deg + 180;
                PlayerAniConifg.directionStatus nowDirection = PlayerAniConifg.getDirection(_dirVector.x, _dirVector.y);
                if (null != AILerp.me.playerAniControl)
                {
                    bool isChanged = false;
                    isChanged |= AILerp.me.playerAniControl.SetDirection((int)nowDirection);
                    if (isChanged)
                    {
                        AILerp.me.directionStatus = nowDirection;
                        if (AILerp.me.moveDirectionCallBack != null)
                        {
                            AILerp.me.moveDirectionCallBack.Call(AILerp.me.gameObject, angle);
                        }
                    }

                    isChanged |= AILerp.me.playerAniControl.SetAction((int)PlayerAniConifg.actionStatus.WALK);
                    if (isChanged)
                    {
                        AILerp.me.playerAniControl.playAllAnimation();
                    }
                }

                //_toNode = AstarPath.active.astarData.gridGraph.GetNodeConnection((Pathfinding.GridNode)nodeInfo, (int)touchDir);
                if (null != _toNode && _toNode.Walkable)
                {
                    AILerp.me.StepCallBak(((Pathfinding.GridNode)_toNode).Cell);

                    Vector3 toPos = (Vector3)_toNode.position;
                    toPos.z = 0f;

                    _distance = Vector3.Distance(toPos, vec);
                    if (touchDir == JoystickTouch.South || touchDir == JoystickTouch.Nouth)
                    {
                        _speed = AILerp.me.speed * _dirVector.normalized;
                    }
                    else if (touchDir == JoystickTouch.East || touchDir == JoystickTouch.West)
                    {
                        _speed = AILerp.me.speed * _dirVector.normalized * AstarPath.active.astarData.gridGraph.aspectRatio;
                    }
                    else
                    {
                        _speed = AILerp.me.speed * _dirVector.normalized * Mathf.Sqrt(AstarPath.active.astarData.gridGraph.aspectRatio * AstarPath.active.astarData.gridGraph.aspectRatio + 1f);
                    }

                    _speed.z = 0f;
                }
                else
                {
                    _toNode = null;
                }
            }
        }

        multiTouchChecker();

        //if (CheckGuiRaycastObjects(_canvasJoystick)) return;

        //if (_fDelayEnableTouchTime < 0f)
        //{
        //    // 做个优化 最多锁屏几秒钟 防止各种情况下锁死
        //    _fDelayEnableTouchTime = Mathf.Min(0f, _fDelayEnableTouchTime + Time.deltaTime);
        //    if (_fDelayEnableTouchTime == 0f)
        //    {
        //        //UIUtil.SetUICameraTouchEnable(true);
        //    }
        //    return;
        //}
        //if (_fDelayEnableTouchTime > 0f)
        //{
        //    _fDelayEnableTouchTime = Mathf.Max(0f, _fDelayEnableTouchTime - Time.deltaTime);
        //    // Debug.LogWarning("Wait for lock ......");
        //    return;
        //}

        // 进行判定
        //{
        //    Vector3 touchPos = Vector3.zero;
        //    if (Input.GetMouseButtonDown(0))
        //    {
        //        touchPos = Input.mousePosition;
        //        touchChecker(touchPos);
        //    }
        //    //else if (Input.multiTouchEnabled)
        //    //{
        //    //    multiTouchChecker();
        //    //}
        //}
    }