Esempio n. 1
0
    void Start()
    {
        // collider bound내에 외곽 노드 추출
        if (_collider2D == null)
        {
            return;
        }

        var nodesInRegion = AstarPath.active.data.gridGraph.GetNodesInRegion(_collider2D.bounds);

        for (int nodeIndex = 0; nodeIndex < nodesInRegion.Count; ++nodeIndex)
        {
            Pathfinding.GridNode gridNode = (Pathfinding.GridNode)nodesInRegion[nodeIndex];
            if (gridNode.Walkable == false)
            {
                _nodes.Add(gridNode);
            }
        }
    }
Esempio n. 2
0
    private void _Stop()
    {
        if (null != AILerp.me)
        {
            if (AILerp.me.playerAniControl.action != PlayerAniConifg.actionStatus.ATTACK)
            {
                AILerp.me.playerAniControl.SetAction((int)PlayerAniConifg.actionStatus.IDEL);
                AILerp.me.playerAniControl.playAllAnimation();
            }

            if (null != _toNode)
            {
                //Vector3 pos = (Vector3)_toNode.position;
                //pos.z = AILerp.me.transform.position.z;
                //AILerp.me.transform.position = pos;
                AILerp.me.ArriveCallBack(_toNode.Cell);
                _toNode = null;
            }

            AILerp.me.playerAniControl.isJoystickMove = false;
        }
    }
Esempio n. 3
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();
        //    //}
        //}
    }