| | |
| | | {
|
| | | public int npcID;
|
| | | public int sid;
|
| | | public bool directTransfer;
|
| | | }
|
| | |
|
| | | public void MoveToNPC(int _npcID, int _sid = 0)
|
| | | public void MoveToNPC(int _npcID, int _sid = 0, bool direct = false)
|
| | | {
|
| | | #if UNITY_EDITOR
|
| | | Debug.LogFormat("想要切换至目标npc: {0}", _npcID);
|
| | |
| | | var _data = new MoveToData
|
| | | {
|
| | | npcID = _npcID,
|
| | | sid = _sid
|
| | | sid = _sid,
|
| | | directTransfer = direct
|
| | | };
|
| | | StartCoroutine("CoMoveToNPC", _data);
|
| | | }
|
| | |
| | | // 判断是否在同一张地图中
|
| | | if (_npcLocation.mapId != PlayerDatas.Instance.baseData.MapID)
|
| | | {
|
| | | int _idx1 = m_TransMapLine.IndexOf(PlayerDatas.Instance.baseData.MapID);
|
| | | int _idx2 = m_TransMapLine.IndexOf(_npcLocation.mapId);
|
| | | bool _valid = true;
|
| | | if (_idx1 == -1)
|
| | | if (data.directTransfer)
|
| | | {
|
| | | _valid = false;
|
| | | Debug.LogErrorFormat("寻找的地图ID不在线路中: {0}", PlayerDatas.Instance.baseData.MapID);
|
| | | _MoveToNPC(NpcID, sid);
|
| | | }
|
| | | if (_idx2 == -1)
|
| | | else
|
| | | {
|
| | | _valid = false;
|
| | | Debug.LogErrorFormat("寻找的地图ID不在线路中: {0}", _npcLocation.mapId);
|
| | | }
|
| | | if (_valid)
|
| | | {
|
| | | int _nextMapID = -1;
|
| | | // 顺序
|
| | | if (_idx2 > _idx1)
|
| | | int _idx1 = m_TransMapLine.IndexOf(PlayerDatas.Instance.baseData.MapID);
|
| | | int _idx2 = m_TransMapLine.IndexOf(_npcLocation.mapId);
|
| | | bool _valid = true;
|
| | | if (_idx1 == -1)
|
| | | {
|
| | | _nextMapID = m_TransMapLine[_idx1 + 1];
|
| | | _valid = false;
|
| | | Debug.LogErrorFormat("寻找的地图ID不在线路中: {0}", PlayerDatas.Instance.baseData.MapID);
|
| | | }
|
| | | // 逆序
|
| | | else
|
| | | if (_idx2 == -1)
|
| | | {
|
| | | _nextMapID = m_TransMapLine[_idx1 - 1];
|
| | | _valid = false;
|
| | | Debug.LogErrorFormat("寻找的地图ID不在线路中: {0}", _npcLocation.mapId);
|
| | | }
|
| | |
|
| | | // 先寻找传送点
|
| | | int _transportID = GetNextTransportID(PlayerDatas.Instance.baseData.MapID,
|
| | | _nextMapID);
|
| | | if (_transportID != -1)
|
| | | if (_valid)
|
| | | {
|
| | | if (_curStage)
|
| | | int _nextMapID = -1;
|
| | | // 顺序
|
| | | if (_idx2 > _idx1)
|
| | | {
|
| | | Vector3 _moveToPos;
|
| | | if (_curStage.TryGetTransportPosition(_transportID, out _moveToPos))
|
| | | _nextMapID = m_TransMapLine[_idx1 + 1];
|
| | | }
|
| | | // 逆序
|
| | | else
|
| | | {
|
| | | _nextMapID = m_TransMapLine[_idx1 - 1];
|
| | | }
|
| | |
|
| | | // 先寻找传送点
|
| | | int _transportID = GetNextTransportID(PlayerDatas.Instance.baseData.MapID,
|
| | | _nextMapID);
|
| | | if (_transportID != -1)
|
| | | {
|
| | | if (_curStage)
|
| | | {
|
| | | while (true)
|
| | | Vector3 _moveToPos;
|
| | | if (_curStage.TryGetTransportPosition(_transportID, out _moveToPos))
|
| | | {
|
| | | if (PathFinder.WalkAble(_hero.Pos, _moveToPos))
|
| | | while (true)
|
| | | {
|
| | | break;
|
| | | if (PathFinder.WalkAble(_hero.Pos, _moveToPos))
|
| | | {
|
| | | break;
|
| | | }
|
| | | var _nextPos = ClientSceneManager.Instance.GetTransPoint(_hero.Pos, _moveToPos);
|
| | | // 如果找到的下一个点
|
| | | if (!PathFinder.WalkAble(_hero.Pos, _nextPos)
|
| | | || _nextPos == Vector3.zero)
|
| | | {
|
| | | Debug.LogErrorFormat("移动至NPC: {0} 时找不到任何跳跃点", NpcID);
|
| | | break;
|
| | | }
|
| | | float _dis = MathUtility.DistanceSqrtXZ(_hero.Pos, _nextPos);
|
| | | while (_dis > 0.01f)
|
| | | {
|
| | | _dis = MathUtility.DistanceSqrtXZ(_hero.Pos, _nextPos);
|
| | | _hero.MoveToPosition(_nextPos);
|
| | | yield return null;
|
| | | }
|
| | | while (!GA_Hero.s_Flying)
|
| | | {
|
| | | yield return null;
|
| | | }
|
| | | while (GA_Hero.s_Flying)
|
| | | {
|
| | | yield return null;
|
| | | }
|
| | | }
|
| | | var _nextPos = ClientSceneManager.Instance.GetTransPoint(_hero.Pos, _moveToPos);
|
| | | // 如果找到的下一个点
|
| | | if (!PathFinder.WalkAble(_hero.Pos, _nextPos)
|
| | | || _nextPos == Vector3.zero)
|
| | | {
|
| | | Debug.LogErrorFormat("移动至NPC: {0} 时找不到任何跳跃点", NpcID);
|
| | | break;
|
| | | }
|
| | | float _dis = MathUtility.DistanceSqrtXZ(_hero.Pos, _nextPos);
|
| | | while (_dis > 0.01f)
|
| | | {
|
| | | _dis = MathUtility.DistanceSqrtXZ(_hero.Pos, _nextPos);
|
| | | _hero.MoveToPosition(_nextPos);
|
| | | yield return null;
|
| | | }
|
| | | while (!GA_Hero.s_Flying)
|
| | | {
|
| | | yield return null;
|
| | | }
|
| | | while (GA_Hero.s_Flying)
|
| | | {
|
| | | yield return null;
|
| | | }
|
| | | _hero.MoveToPosition(_moveToPos);
|
| | | yield break;
|
| | | }
|
| | | _hero.MoveToPosition(_moveToPos);
|
| | | yield break;
|
| | | }
|
| | | }
|
| | | }
|
| | | _MoveToNPC(NpcID, sid);
|
| | | }
|
| | | _MoveToNPC(NpcID, sid);
|
| | | yield break;
|
| | | }
|
| | | _destPostion = new Vector3(_npcLocation.position.x, 0, _npcLocation.position.y);
|