Ejemplo n.º 1
0
        private void HandleBake()
        {
            const string Category = "Bake To Target";

            NavmeshBuild  build = Context.Build; // Caller checks for null.
            TileBuildData tdata = build.BuildData;

            // Double check.
            if (tdata.BakeableCount() == 0)
            {
                Debug.LogWarning(Category + ": No tiles were produced.  (All tiles empty?)", build);
                return;
            }

            if (Context.TaskCount > 0)
            {
                Debug.LogWarning(Category + ": There are in-progress background builds."
                                 + " The tiles associated with these builds will not be baked."
                                 + " In-progress builds: " + Context.TaskCount
                                 , build);
            }

            NavmeshParams nconfig;

            NavmeshTileData[] tiles;

            bool success = tdata.GetMeshBuildData(build.TileSetDefinition.BoundsMin
                                                  , build.TileSetDefinition.TileWorldSize
                                                  , out nconfig, out tiles);

            if (!success)
            {
                Logger.PostError("Bake to target: Error creating navigation mesh from build data."
                                 , Context.Build);
                return;
            }

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

            if ((status & NavStatus.Failure) == 0)
            {
                build.BuildData.SetAsBaked();
                EditorUtility.SetDirty((Object)build.BuildTarget);
            }
            else
            {
                Logger.PostError("Bake to target: Target reported failure."
                                 , (Object)Context.Build.BuildTarget);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        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();
            }
        }