Esempio n. 1
0
 public void CreateTileTypesFromGraph()
 {
     RecastGraph.NavmeshTile[] tiles = this.graph.GetTiles();
     if (tiles == null || tiles.Length != this.graph.tileXCount * this.graph.tileZCount)
     {
         throw new InvalidOperationException("Graph tiles are invalid (either null or number of tiles is not equal to width*depth of the graph");
     }
     for (int i = 0; i < this.graph.tileZCount; i++)
     {
         for (int j = 0; j < this.graph.tileXCount; j++)
         {
             RecastGraph.NavmeshTile navmeshTile = tiles[j + i * this.graph.tileXCount];
             Int3 vInt     = (Int3)this.graph.GetTileBounds(j, i, 1, 1).min;
             Int3 tileSize = new Int3(this.graph.tileSizeX, 1, this.graph.tileSizeZ) * (1000f * this.graph.cellSize);
             vInt += new Int3(tileSize.x * navmeshTile.w / 2, 0, tileSize.z * navmeshTile.d / 2);
             vInt  = -vInt;
             MyTileHandler.TileType tileType = new MyTileHandler.TileType(navmeshTile.verts, navmeshTile.tris, tileSize, vInt, navmeshTile.w, navmeshTile.d);
             this.tileTypes.Add(tileType);
             int num = j + i * this.graph.tileXCount;
             this.activeTileTypes[num]     = tileType;
             this.activeTileRotations[num] = 0;
             this.activeTileOffsets[num]   = 0;
         }
     }
 }
Esempio n. 2
0
        public void LoadTile(List <NavmeshCut> navmeshCuts, MyTileHandler.TileType tile, int x, int z, int rotation, int yoffset)
        {
            if (tile == null)
            {
                throw new ArgumentNullException("tile");
            }
            int num = x + z * this.graph.tileXCount;

            rotation %= 4;
            if (this.isBatching && this.reloadedInBatch[num] && this.activeTileOffsets[num] == yoffset && this.activeTileRotations[num] == rotation && this.activeTileTypes[num] == tile)
            {
                return;
            }
            if (this.isBatching)
            {
                this.reloadedInBatch[num] = true;
            }
            this.activeTileOffsets[num]   = yoffset;
            this.activeTileRotations[num] = rotation;
            this.activeTileTypes[num]     = tile;
            if (this.activeTileOffsets[num] != yoffset || this.activeTileRotations[num] != rotation || this.activeTileTypes[num] != tile)
            {
                return;
            }
            GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate);
            Int3[] verts;
            int[]  tris;
            tile.Load(out verts, out tris, rotation, yoffset);
            Bounds tileBounds = this.graph.GetTileBounds(x, z, tile.Width, tile.Depth);
            Int3   vInt       = (Int3)tileBounds.min;

            vInt = -vInt;
            Int3[] array  = null;
            int[]  array2 = null;
            int    num2;
            int    num3;

            this.CutPoly(navmeshCuts, verts, tris, ref array, ref array2, out num2, out num3, null, vInt, tileBounds, (MyTileHandler.CutMode) 3, 0);
            this.DelaunayRefinement(array, array2, ref num2, ref num3, true, false, -vInt);
            if (num3 != array2.Length)
            {
                array2 = MyTileHandler.ShrinkArray <int>(array2, num3);
            }
            if (num2 != array.Length)
            {
                array = MyTileHandler.ShrinkArray <Int3>(array, num2);
            }
            int w = (rotation % 2 != 0) ? tile.Depth : tile.Width;
            int d = (rotation % 2 != 0) ? tile.Width : tile.Depth;

            this.graph.ReplaceTile(x, z, w, d, array, array2, false);
            GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
        }
Esempio n. 3
0
 public MyTileHandler.TileType RegisterTileType(Mesh source, Int3 centerOffset, int width = 1, int depth = 1)
 {
     MyTileHandler.TileType tileType = new MyTileHandler.TileType(source, new Int3(this.graph.tileSizeX, 1, this.graph.tileSizeZ) * (1000f * this.graph.cellSize), centerOffset, width, depth);
     this.tileTypes.Add(tileType);
     return(tileType);
 }