Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        /// <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);
        }