public SectorLevelInfo(SectorLevelInfo v) { this.sectorWidth = v.sectorWidth; this.sectorHeight = v.sectorHeight; this.numWidth = v.numWidth; this.numHeight = v.numHeight; }
/// <summary> /// 判断是否相等 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(System.Object obj) { if (obj == null) { return(false); } SectorLevelInfo p = (SectorLevelInfo)obj; if ((System.Object)p == null) { return(false); } return((sectorWidth == p.sectorWidth) && (sectorHeight == p.sectorHeight) && (numWidth == p.numWidth) && (numHeight == p.numHeight)); }
/// <summary> /// 构建地图 /// </summary> private void BuildMap() { // 构建tile tileArray = new MapTile[TileYnum][]; for (short y = 0; y < TileYnum; y++) { tileArray[y] = new MapTile[TileXnum]; for (short x = 0; x < TileXnum; x++) { MapTile tile = new MapTile(); tile.Pos = new IntVector2(x, y); tile.SetSectorIndex(TileXnum, TileYnum, SectorSize); tile.integrationValue = TileHelp.tileResetIntegrationValue; tileArray[y][x] = tile; } } ushort sectorWidth = SectorSize; ushort sectorHeight = SectorSize; // SectorLevelWayPointLink = new Dictionary <MapTile, PathNode> [SectorLevelNum]; lookUpLowerSectors = new SectorIndexList[SectorLevelNum - 1][]; levelDimensions = new SectorLevelInfo[SectorLevelNum]; sectorArray = new MapSector[SectorLevelNum][]; for (ushort level = 0; level < SectorLevelNum; level++) { SectorLevelWayPointLink[level] = new Dictionary <MapTile, PathNode>(); levelDimensions[level] = new SectorLevelInfo(sectorWidth, sectorHeight, (ushort)(Mathf.CeilToInt((TileXnum / (float)sectorWidth))), (ushort)(Mathf.CeilToInt((TileYnum / (float)sectorHeight)))); sectorArray[level] = new MapSector[levelDimensions[level].numWidth * levelDimensions[level].numHeight]; for (short i = 0; i < levelDimensions[level].numHeight; i++) { for (short j = 0; j < levelDimensions[level].numWidth; j++) { int index = (i * levelDimensions[level].numWidth) + j; if (level == 0) { sectorArray[level][index] = new LowSector(); } else { sectorArray[level][index] = new HighSector(); } sectorArray[level][index].Pos = new IntVector2(j, i); sectorArray[level][index].ID = (ushort)index; sectorArray[level][index].level = level; sectorArray[level][index].top = (ushort)(i * levelDimensions[level].sectorWidth); sectorArray[level][index].bottom = (ushort)(i * levelDimensions[level].sectorWidth + levelDimensions[level].sectorWidth - 1); sectorArray[level][index].left = (ushort)(j * levelDimensions[level].sectorHeight); sectorArray[level][index].right = (ushort)(j * levelDimensions[level].sectorHeight + levelDimensions[level].sectorHeight - 1); sectorArray[level][index].tilesInWidth = (ushort)(Mathf.Min(TileXnum - sectorArray[level][index].left, levelDimensions[level].sectorWidth)); sectorArray[level][index].tilesInHeight = (ushort)(Mathf.Min(TileYnum - sectorArray[level][index].top, levelDimensions[level].sectorHeight)); sectorArray[level][index].Init(); } } // hight level 包含更多的格子数 sectorWidth *= SectorlevelScale; sectorHeight *= SectorlevelScale; if (level > 0) { lookUpLowerSectors[level - 1] = new SectorIndexList[sectorArray[level].Length]; } } FillInLookUpLowerSectors(); }