예제 #1
0
        public override void Update()
        {
            base.Update();

            if (Context == null || mInputCompile == null)
            {
                return;
            }

            mInputCompile.Update();

            if (!mInputCompile.IsFinished)
            {
                return;
            }

            NavmeshBuild build = Context.Build;

            if (!build)
            {
                return;
            }

            UnityBuildContext mLogger = new UnityBuildContext();

            if (mInputCompile.HasData)
            {
                if (!build.SetInputData(mLogger, mInputCompile.Geometry
                                        , mInputCompile.Info, mInputCompile.Processors, mInputCompile.Connections
                                        , true))
                {
                    mLogger.PostError("Could not apply input data.", build);
                }
            }
            else
            {
                mLogger.PostError("Input compile did not produce anything.", build);
            }

            mInputCompile = null;
        }
예제 #2
0
        private void FinalizeOnFail(string message, bool postError)
        {
            if (mTask != null)
            {
                mTask.Abort(message);
                mTask = null;
            }

            if (postError)
            {
                mLogger.PostError(message, mContext.Build);
            }

            mBuilder  = null;
            mGeometry = null;
            mAssets   = new InputAssets();
            mState    = State.Finished;
        }
예제 #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();
            }
        }
예제 #4
0
        private void ManageNMGenRequests()
        {
            mLogger.ResetLog();

            TileBuildData tdata = mContext.Build.BuildData;

            // Due to concurrency with the input build, this method
            // does not log things via the context.

            List <NMGenTask> requests = mContext.NMGenTasks;

            for (int i = requests.Count - 1; i >= 0; i--)
            {
                NMGenTask item = requests[i];

                if (item.IsFinished)
                {
                    requests.RemoveAt(i);

                    NavmeshBuild build = mContext.Build;

                    if (!build)
                    {
                        // Asset was deleted.
                        continue;
                    }

                    string tileText = string.Format("({0},{1})", item.TileX, item.TileZ);

                    switch (item.TaskState)
                    {
                    case BuildTaskState.Aborted:

                        mLogger.Log(item.Messages);
                        mLogger.PostError("Tile build failed: " + tileText, build);

                        tdata.SetAsFailed(item.TileX, item.TileZ);

                        break;

                    case BuildTaskState.Complete:

                        NMGenAssets r = item.Result;

                        if (r.NoResult)
                        {
                            mLogger.PostTrace("NMGen build complete. Tile is empty: " + tileText
                                              , item.Messages, build);

                            tdata.SetAsEmpty(r.TileX, r.TileZ);
                        }
                        else
                        {
                            tdata.SetWorkingData(r.TileX, r.TileZ, r.PolyMesh, r.DetailMesh);

                            mLogger.PostTrace("NMGen build complete: " + tileText
                                              , item.Messages, build);

                            mContext.QueueTask(mLogger, r.TileX, r.TileZ
                                               , r.PolyMesh, r.DetailMesh
                                               , (build.Config.BuildFlags & NMGenBuildFlag.BVTreeEnabled) != 0
                                               , item.Priority);
                        }

                        break;
                    }
                }
                else if (item.TaskState == BuildTaskState.InProgress &&
                         tdata.GetState(item.TileX, item.TileZ) != TileBuildState.InProgress)
                {
                    // Transition to the in-progress state.
                    tdata.SetAsInProgress(item.TileX, item.TileZ);
                }
            }
        }
예제 #5
0
        public override void Update()
        {
            base.Update();

            if (Context == null || mInputCompile == null)
                return;

            mInputCompile.Update();

            if (!mInputCompile.IsFinished)
                return;

            NavmeshBuild build = Context.Build;

            if (!build)
                return;

            UnityBuildContext mLogger = new UnityBuildContext();

            if (mInputCompile.HasData)
            {
                if (!build.SetInputData(mLogger, mInputCompile.Geometry
                    , mInputCompile.Info, mInputCompile.Processors, mInputCompile.Connections
                    , true))
                {
                   mLogger.PostError("Could not apply input data.", build);
                }
            }
            else
                mLogger.PostError("Input compile did not produce anything.", build);

            mInputCompile = null;
        }