private void JoystickTouchToDir(JoystickTouch touchDir, ref Vector3 dir) { switch (touchDir) { case JoystickTouch.West: dir.y = 0f; dir.x = -AstarPath.active.astarData.gridGraph.aspectRatio; break; case JoystickTouch.East: dir.y = 0f; dir.x = AstarPath.active.astarData.gridGraph.aspectRatio; break; case JoystickTouch.Nouth: dir.y = 1f; dir.x = 0f; break; case JoystickTouch.South: dir.y = -1f; dir.x = 0f; break; case JoystickTouch.Noutheast: dir.y = 1f; dir.x = AstarPath.active.astarData.gridGraph.aspectRatio; break; case JoystickTouch.Nouthwest: dir.y = 1f; dir.x = -AstarPath.active.astarData.gridGraph.aspectRatio; break; case JoystickTouch.Southwest: dir.y = -1f; dir.x = -AstarPath.active.astarData.gridGraph.aspectRatio; break; case JoystickTouch.Southeast: dir.y = -1f; dir.x = AstarPath.active.astarData.gridGraph.aspectRatio; break; } }
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(); // //} //} }