/// <summary> /// 跨场景寻路 /// </summary> /// <param name="destMapID">目的地图ID</param> /// <param name="destPosition">目的位置</param> public void StartPathFinder(int destMapID, Vector3 destPosition) { CoreEntry.gEventMgr.RemoveListener(GameEvent.GE_JOYSTICK_DOWN, OnJoyStickDown); bUserMul = false; curMapID = MapMgr.Instance.EnterMapId; targetMapID = destMapID; targetPostion = destPosition; ActorObj ag = CoreEntry.gActorMgr.GetActorByServerID(MainRole.Instance.serverID); if (destMapID == curMapID)//同一个地图直接走过去 { ActorObj actor = CoreEntry.gActorMgr.GetActorByServerID(MainRole.Instance.serverID); actor.MoveToPos(destPosition); ag.ReqRideHorse(); return; } if (AnalysePath(curMapID, destMapID)) { CoreEntry.gEventMgr.AddListener(GameEvent.GE_JOYSTICK_DOWN, OnJoyStickDown);//开始跨场景寻路才需要简体摇杆按下时间,判断是否打断 curIndex = 0; ActorObj actor = CoreEntry.gActorMgr.GetActorByServerID(MainRole.Instance.serverID); SceneEntityConfig curPortal = mPortals[curIndex]; bUserMul = actor.MoveToPos(curPortal.position); ag.ReqRideHorse(); } }
public void LoadWayPoints(int mapID) { wayPointsData = new List <WayPoint>(); List <SceneEntitySet> entities = CoreEntry.gGameDBMgr.GetEnityConfigInfo(mapID); if (null == entities) { return; } for (int i = 0; i < entities.Count; i++) { if (entities[i].type == EntityConfigType.ECT_WAYPOINT) { for (int j = 0; j < entities[i].entityList.Count; j++) { SceneEntityConfig data = entities[i].entityList[j]; WayPoint point = new WayPoint(data.index, data.position, data.neighbours); wayPointsData.Add(point); } } } }
public static List <Vector3> GetSortedEntList(Vector3 pos) { List <Vector3> positions = new List <Vector3>(); List <SceneEntitySet> infos = CoreEntry.gGameDBMgr.GetEnityConfigInfo(MapMgr.Instance.EnterMapId); if (infos == null) { return(positions); } const int MAX_POSITION = 50; for (int i = 0; i < infos.Count && positions.Count < MAX_POSITION; ++i) { SceneEntitySet info = infos[i]; if (info.type == EntityConfigType.ECT_MONSTER) { for (int j = 0; j < info.entityList.Count && positions.Count < MAX_POSITION; ++j) { SceneEntityConfig cfg = info.entityList[j]; positions.Add(cfg.position); } } } //按离指定位置距离进行排序 positions.Sort((a, b) => { return(Vector3.SqrMagnitude(pos - a).CompareTo(Vector3.SqrMagnitude(pos - b))); }); return(positions); }
private void OnSceneLoaded(GameEvent ge, EventParameter paremeter) { if (bUserMul) { curMapID = MapMgr.Instance.EnterMapId; curIndex++; if (curIndex < mPortals.Count)//中间场景,走到传送门位置 { ActorObj actor = CoreEntry.gActorMgr.GetActorByServerID(MainRole.Instance.serverID); if (null != actor) { SceneEntityConfig curPortal = mPortals[curIndex]; bUserMul = actor.MoveToPos(curPortal.position); } } else { if (curMapID == targetMapID)//目的场景,走到终点 { ActorObj actor = CoreEntry.gActorMgr.GetActorByServerID(MainRole.Instance.serverID); if (null != actor) { actor.MoveToPos(targetPostion); } } bUserMul = false; CoreEntry.gEventMgr.RemoveListener(GameEvent.GE_JOYSTICK_DOWN, OnJoyStickDown); } //if (TaskMgr.LastClickTaskID > 0) //{ // AutoAIRunner.Init(); // AutoAIRunner.SetAutoTask(true); //} } }
/// <summary> /// 分析从起始场景到目的场景是否可达 /// </summary> /// <param name="startMapID"></param> /// <param name="destMapID"></param> /// <returns>是否可达</returns> public bool AnalysePath(int startMapID, int destMapID) { HashSet <int> closeMapSet = new HashSet <int>(); List <MapNodeInfo> allNodes = new List <MapNodeInfo>(); Queue <MapNodeInfo> checkNodes = new Queue <MapNodeInfo>(); MapNodeInfo curNode = new MapNodeInfo(); curNode.id = startMapID; curNode.parent = null; curNode.portalCfg = null; allNodes.Add(curNode); checkNodes.Enqueue(curNode); curNode = null; while (checkNodes.Count > 0) { curNode = checkNodes.Dequeue(); closeMapSet.Add(curNode.id); if (curNode.id == destMapID) { break; } SceneEntitySet portals = GetPortalByMapID(curNode.id); if (null != portals) { for (int i = 0; i < portals.entityList.Count; i++) { SceneEntityConfig portal = portals.entityList[i]; LuaTable portalCfg = ConfigManager.Instance.Map.GetPortalConfig(portal.configID); if (null == portalCfg) { continue; } if (closeMapSet.Contains(portalCfg.Get <int>("targetMap"))) { continue; } MapNodeInfo mapNodeInfo = new MapNodeInfo(); mapNodeInfo.id = portalCfg.Get <int>("targetMap"); mapNodeInfo.parent = curNode; mapNodeInfo.portalCfg = portal; checkNodes.Enqueue(mapNodeInfo); allNodes.Add(mapNodeInfo); } } } mMapIDs.Clear(); mPortals.Clear(); if (null != curNode && curNode.id == destMapID) { mMapIDs.Add(curNode.id); mPortals.Add(curNode.portalCfg); MapNodeInfo nextNode = curNode.parent; while (null != nextNode) { mMapIDs.Add(nextNode.id); if (nextNode.portalCfg != null) { mPortals.Add(nextNode.portalCfg); } nextNode = nextNode.parent; } mMapIDs.Reverse(); mPortals.Reverse(); return(true); } return(false); }