예제 #1
0
    /// <summary>
    /// 8方向检索所有相邻格子数据
    /// </summary>
    /// <param name="ljGridDict"></param>
    /// <param name="searchCellDict"></param>
    private static void SearchRangePositions(LJMapObjDict ljGridDict, Dictionary <SerVector2Int, int> searchCellDict)
    {
        while (MapUtil.CheckSearchCellDictHaveNoneSearch(searchCellDict))
        {
            List <KeyValuePair <SerVector2Int, int> > tempList = new
                                                                 List <KeyValuePair <SerVector2Int, int> >(); //仅用于搜索一遍没搜索过的格子的列表
            foreach (KeyValuePair <SerVector2Int, int> kvp in searchCellDict)                                 // 将所有未搜索过的格子加入待搜索列表
            {
                if (kvp.Value == LJMapConst.MAP_SEARCH_STATE.OK)
                {
                    continue;
                }
                tempList.Add(kvp);
            }

            for (int i = 0, imax = tempList.Count; i < imax; i++)
            {
                SerVector2Int serVector2Int = tempList[i].Key;
                for (int j = 0, jmax = MapUtil.GRID_POSITION_OFFSETS.Length; j < jmax; j++)
                {
                    SerVector2Int offsetSerVector2Int = new SerVector2Int(serVector2Int.X + MapUtil.GRID_POSITION_OFFSETS[j].x,
                                                                          serVector2Int.Y + MapUtil.GRID_POSITION_OFFSETS[j].y
                                                                          );


                    if (!ljGridDict.ContainsKey(offsetSerVector2Int))
                    { // 没有这个格子 不做处理
                        continue;
                    }

                    //有格子数据 不做处理
                    if (searchCellDict.ContainsKey(offsetSerVector2Int))
                    {
                        continue;
                    }
                    searchCellDict.Add(offsetSerVector2Int, LJMapConst.MAP_SEARCH_STATE.NONE);
                }

                searchCellDict[serVector2Int] = LJMapConst.MAP_SEARCH_STATE.OK;
            }
        }
        //搜索完毕
    }