コード例 #1
0
        private void HandleBake()
        {
            NavmeshBuild build = Context.Build;

            NavmeshTileData[] tiles = new NavmeshTileData[1]
            {
                build.BuildData.GetTileData(0, 0)
            };

            NavmeshParams nconfig = NavUtil.DeriveConfig(tiles[0]);

            NavStatus status = build.BuildTarget.Load(nconfig, tiles, NMBEditorUtil.GetConfig(build));

            if ((status & NavStatus.Failure) == 0)
            {
                EditorUtility.SetDirty((Object)build.BuildTarget);
                // build.BuildData.SetAsBaked();
                build.BuildData.Reset(0, 0);  // Don't need to keep the data.
            }
            else
            {
                Logger.PostError("Bake to target: Target reported failure.", (Object)build.BuildTarget);
            }
        }
コード例 #2
0
ファイル: NavmeshBuildHelper.cs プロジェクト: zwong91/Titan
        public void Build()
        {
            if (!mBuild)
            {
                return;
            }

            mBuild.ResetBuild();

            // Note: The 'finally' takes care of all cleanup.

            try
            {
                EditorUtility.DisplayCancelableProgressBar("Build & Bake"
                                                           , "Preparing..."
                                                           , 0);

                // Prepare the build.

                if (!CompileInput())
                {
                    return;
                }

                if (!InitializeBuild())
                {
                    return;
                }

                // Build the tiles.
                NavmeshParams     nconfig = null;
                NavmeshTileData[] tiles   = null;
                bool success = true;

                if (mBuild.TileSetDefinition == null)
                {
                    if (!BuildSingleTile())
                    {
                        return;
                    }

                    tiles = new NavmeshTileData[1] {
                        mBuild.BuildData.GetTileData(0, 0)
                    };

                    nconfig = NavUtil.DeriveConfig(tiles[0]);
                }
                else if (BuildMultiTiled())
                {
                    success = mBuild.BuildData.GetMeshBuildData(mBuild.TileSetDefinition.BoundsMin
                                                                , mBuild.TileSetDefinition.TileWorldSize
                                                                , out nconfig, out tiles);
                }
                else
                {
                    return;
                }

                if (!success)
                {
                    mContext.PostError("Navigation mesh creation failed.", mBuild);
                    return;
                }

                // Bake the mesh.

                NavStatus nstatus =
                    mBuild.BuildTarget.Load(nconfig, tiles, NMBEditorUtil.GetConfig(mBuild));

                if ((nstatus & NavStatus.Sucess) == 0)
                {
                    mContext.PostError("Bake to target: Target reported failure.", mBuild);
                }
                else
                {
                    EditorUtility.SetDirty((Object)mBuild.BuildTarget);
                }
            }
            finally
            {
                mBuild.ResetBuild();
                EditorUtility.ClearProgressBar();
            }
        }
コード例 #3
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.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);
            }
        }