private void InitMapAsset(Vector3 pos) { mapKey = (int)pos.x / MapDefine.MAPITEMTOTALSIZE + "" + (int)pos.z / MapDefine.MAPITEMTOTALSIZE; if (mapAsset != null) { Dictionary <string, MapElement> tempElementDic = new Dictionary <string, MapElement>(); for (int index = 0; index < mapAsset.elementList.Count; index++) { MapElement tempElement = mapAsset.elementList[index]; tempElementDic[tempElement.elementKey] = tempElement; } AllMapElementDic[mapKey] = tempElementDic; Dictionary <string, MapElementGrid> tempElementGridDic = new Dictionary <string, MapElementGrid>(); for (int index = 0; index < mapAsset.ElementGrids.Count; index++) { MapElementGrid tempElementGrid = mapAsset.ElementGrids[index]; tempElementGridDic[tempElementGrid.gridKey] = tempElementGrid; } AllElemtGridDic[mapKey] = tempElementGridDic; } else { Debug.LogError("MapAsset is null!!"); } }
private List <string> ParsedGrid = new List <string>();//已解析grid //获取大地图元素网格数据并生成对应小地图元素 private void ParseMapElementGrid(MapElementGrid gridData, string bigMapKey) { bool isNeedParse = !ParsedGrid.Contains(gridData.gridKey); if (isNeedParse) { ParsedGrid.Add(gridData.gridKey); } List <string> tempElementKeyList = gridData.elementKeyList; for (int index = 0; index < tempElementKeyList.Count; index++) { MapElement element; Dictionary <string, MapElement> tempElementDic; if (AllMapElementDic.TryGetValue(bigMapKey, out tempElementDic)) { if (tempElementDic.TryGetValue(tempElementKeyList[index], out element)) { bool isLittleElement = element.elementType.Contains("_Little_"); if (!isLittleElement && !curBigGridElementDic.ContainsKey(element.elementKey)) { curBigGridElementDic[element.elementKey] = element; } if (isLittleElement && isNeedParse) { if (!littleElementGridDic.ContainsKey(bigMapKey))//小地图元素数据根据大地图元素数据生成 { littleElementGridDic[bigMapKey] = new Dictionary <string, MapElementGrid>(); } string littleGridKey = Mathf.FloorToInt(element.elementInfo.Pos.x / MapDefine.MapLittleElementSize) + "_" + Mathf.FloorToInt(element.elementInfo.Pos.z / MapDefine.MapLittleElementSize); if (!littleElementGridDic[bigMapKey].ContainsKey(littleGridKey)) { MapElementGrid tempGrid = new MapElementGrid(); tempGrid.gridKey = littleGridKey; littleElementGridDic[bigMapKey][littleGridKey] = tempGrid; } littleElementGridDic[bigMapKey][littleGridKey].elementKeyList.Add(tempElementKeyList[index]); } } } } }
public void AddMapElementGridItem(string gridKey, string elementKey) { int index = ElementGrids.FindIndex(a => a.gridKey.Equals(gridKey)); if (index < 0) { MapElementGrid grid = new MapElementGrid(); grid.gridKey = gridKey; grid.elementKeyList.Add(elementKey); ElementGrids.Add(grid); } else { List <string> elementKeys = ElementGrids[index].elementKeyList; int tempIndex = elementKeys.FindIndex(a => a.Equals(elementKey)); if (tempIndex < 0) { elementKeys.Add(elementKey); } } }
//地图建筑数据 private void InitData() { if (mapAsset != null) { Dictionary <string, MapElement> tempElementDic = new Dictionary <string, MapElement>(); for (int index = 0; index < mapAsset.elementList.Count; index++) { MapElement tempElement = mapAsset.elementList[index]; tempElementDic[tempElement.elementKey] = tempElement; } AllMapElementDic[mapKey] = tempElementDic; Dictionary <string, MapElementGrid> tempElementGridDic = new Dictionary <string, MapElementGrid>(); for (int index = 0; index < mapAsset.ElementGrids.Count; index++) { MapElementGrid tempElementGrid = mapAsset.ElementGrids[index]; tempElementGridDic[tempElementGrid.gridKey] = tempElementGrid; } AllMapElementGridDic[mapKey] = tempElementGridDic; } else { Debug.LogError("MapAsset is null!!"); } }