Example #1
0
 public static MapSceneDataManage Instance()
 {
     if (instance == null)
     {
         instance = new MapSceneDataManage();
     }
     return(instance);
 }
Example #2
0
 void Update()
 {
     count++;
     if (count >= 3 && lastPos != transform.position)
     {
         count = 0;
         SetCover(MapSceneDataManage.Instance().IsCover(transform.position));
         lastPos = transform.position;
         //Pathfinding.NNInfo nodeInfo = AstarPath.active.GetNearest(lastPos);
         //if (null != nodeInfo.node)
         //{
         //    SetCover(((Pathfinding.GridNode)nodeInfo).IsCover);
         //}
     }
 }
Example #3
0
 private void touchChecker(Vector3 touchPos)
 {
     if (!touchPos.Equals(Vector3.zero))
     {
         if (MapSceneDataManage.Instance().onlyCheckMap)
         {
             FindTouchObj(touchPos, _MapLayerMask);
         }
         else
         {
             bool isFinded = FindTouchObj(touchPos, _PlayerLayerMask);
             if (!isFinded)
             {
                 isFinded = FindTouchObj(touchPos, _ItemLayerMask);
             }
             if (!isFinded)
             {
                 isFinded = FindTouchObj(touchPos, _MapLayerMask);
             }
         }
     }
 }
Example #4
0
    private void multiTouchChecker()
    {
        if (null == EventSystem.current)
        {
            return;
        }

        m_listVec.Clear();

        if (UnityEngine.Application.platform != RuntimePlatform.Android && UnityEngine.Application.platform != RuntimePlatform.IPhonePlayer)
        {
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }

            m_listVec.Add(Input.mousePosition);
        }
        else
        {
            // 仅允许双点触控
            if (Input.touches == null || Input.touches.Length <= 0 || Input.touches.Length > 2)
            {
                return;
            }

            for (int i = 0; i < Input.touches.Length; i++)
            {
                if (Input.touches[i].phase == TouchPhase.Began)
                {
                    m_listVec.Add(Input.GetTouch(i).position);
                }
            }
        }

        touchJoyStick = false;
        findPlayer    = null;
        findGround    = null;

        for (int i = 0; i < m_listVec.Count; i++)
        {
            Vector3 touchPos = m_listVec[i];

            if (M_TouchUI(touchPos))
            {
                dispatch(TOUCH_UI, null, Vector3.zero);
                return;
            }

            if (!touchJoyStick && M_TouchJoystick(touchPos))
            {
                touchJoyStick = true;
                return;
            }

            if (!MapSceneDataManage.Instance().onlyCheckMap&& null == findPlayer)
            {
                findPlayer = M_FindTouchOBJ(touchPos, _NpcLayerMask);
                playerPos  = touchPos;
            }

            if (!MapSceneDataManage.Instance().onlyCheckMap&& null == findPlayer)
            {
                findPlayer = M_FindTouchOBJ(touchPos, _PlayerLayerMask);
                playerPos  = touchPos;
            }

            if (null == findPlayer && null == findGround)
            {
                findGround = M_FindTouchOBJ(touchPos, _MapLayerMask);
                groundPos  = touchPos;
            }
        }

        if (null != findPlayer)
        {
            dispatch(TOUCH_PLAYER, findPlayer, playerPos);
        }
        else if (null != findGround)
        {
            dispatch(TOUCH_GROUND, findGround, groundPos);
        }
    }
Example #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();
        //    //}
        //}
    }