private void HandleWorkingNavmesh(TileSelection selection)
        {
            NavmeshBuild  build = selection.Build;
            TileBuildData tdata = build.BuildData;

            if (mDebugObject == null)
            {
                Navmesh navmesh = null;

                if (tdata.BakeableCount() == 0)
                {
                    // Nothing to display.
                    return;
                }

                bool success = true;

                TileSetDefinition tdef = build.TileSetDefinition;

                NavmeshParams     nconfig;
                NavmeshTileData[] tiles;

                if (tdef == null)
                {
                    tiles = new NavmeshTileData[1] {
                        tdata.GetTileData(0, 0)
                    };
                    nconfig = NavUtil.DeriveConfig(tiles[0]);
                }
                else
                {
                    TileZone zone;

                    if (selection.HasSelection)
                    {
                        zone = selection.Zone;
                    }
                    else
                    {
                        zone = new TileZone(0, 0, tdef.Width - 1, tdef.Depth - 1);
                    }

                    success = tdata.GetMeshBuildData(tdef.BoundsMin.ToUnityVector3(), tdef.TileWorldSize, zone
                                                     , out nconfig, out tiles);
                }

                NavStatus status = NavStatus.Sucess;

                if (success)
                {
                    status = Navmesh.Create(nconfig, out navmesh);

                    if ((status & NavStatus.Failure) == 0)
                    {
                        foreach (NavmeshTileData tile in tiles)
                        {
                            uint trash;
                            status = navmesh.AddTile(tile, Navmesh.NullTile, out trash);

                            if ((status & NavStatus.Sucess) == 0)
                            {
                                navmesh = null;
                                break;
                            }
                        }
                    }
                }

                if ((status & NavStatus.Sucess) == 0)
                {
                    Show = MeshDebugOption.None;                      // Use property.
                    Debug.LogError("Mesh Debug View: Error creating working navigation mesh: "
                                   + status + ". Disabled display.", build);
                }
                else
                {
                    mDebugObject = navmesh;
                }
            }

            if (mDebugObject != null)
            {
                Navmesh nm = ( Navmesh )mDebugObject;
                NavDebug.Draw(nm, NavmeshSceneDraw.Instance.ColorByArea);
            }
        }
Exemple #2
0
        private void HandleWorkingNavmesh(TileSelection selection)
        {
            NavmeshBuild build = selection.Build;
            TileBuildData tdata = build.BuildData;

            if (mDebugObject == null)
            {
                Navmesh navmesh = null;

                if (tdata.BakeableCount() == 0)
                    // Nothing to display.
                    return;

                bool success = true;

                TileSetDefinition tdef = build.TileSetDefinition;

                NavmeshParams nconfig;
                NavmeshTileData[] tiles;

                if (tdef == null)
                {
                    tiles = new NavmeshTileData[1] { tdata.GetTileData(0, 0) };
                    nconfig = NavUtil.DeriveConfig(tiles[0]);
                }
                else
                {
                    TileZone zone;

                    if (selection.HasSelection)
                        zone = selection.Zone;
                    else
                        zone = new TileZone(0, 0, tdef.Width - 1, tdef.Depth - 1);

                    success = tdata.GetMeshBuildData(tdef.BoundsMin, tdef.TileWorldSize, zone
                        , out nconfig, out tiles);
                }

                NavStatus status = NavStatus.Sucess;

                if (success)
                {
                    status = Navmesh.Create(nconfig, out navmesh);

                    if ((status & NavStatus.Failure) == 0)
                    {
                        foreach (NavmeshTileData tile in tiles)
                        {
                            uint trash;
                            status = navmesh.AddTile(tile, Navmesh.NullTile, out trash);

                            if ((status & NavStatus.Sucess) == 0)
                            {
                                navmesh = null;
                                break;
                            }
                        }
                    }
                }

                if ((status & NavStatus.Sucess) == 0)
                {
                    Show = MeshDebugOption.None;  // Use property.
                    Debug.LogError("Mesh Debug View: Error creating working navigation mesh: "
                            + status + ". Disabled display.", build);
                }
                else
                    mDebugObject = navmesh;
            }

            if (mDebugObject != null)
            {
                Navmesh nm = (Navmesh)mDebugObject;
                NavDebug.Draw(nm, NavmeshSceneDraw.Instance.ColorByArea);
            }

        }