Exemple #1
0
        public void Update()
        {
            if (mTaskManager == null)
            {
                // Give an error in this case.
                Debug.LogError("Called update on build processor after processor disposal");
                return;
            }

            for (int i = mControllers.Count - 1; i >= 0; i--)
            {
                BuildController controller = mControllers[i];
                NavmeshBuild build = controller.Build;
                NavmeshBuild selected = BuildSelector.Instance.Selected;

                if (!build 
                    || build.BuildType != NavmeshBuildType.Advanced
                    || (build != selected && !controller.BuildIsActive))
                {
                    // Build component has been destroyed, is no longer advanced, or is
                    // inactive and not selected.  Get rid of it.
                    controller.Exit();
                    mControllers.RemoveAt(i);
                }
                else
                    controller.Update();
            }
        }
        public NavmeshBuildHelper(NavmeshBuild build)
        {
            if (!build)
                throw new System.ArgumentNullException();

            this.mBuild = build;
        }
Exemple #3
0
        public void OnGUI(Rect area)
        {
            Validate();

            if (!mSelected)
            {
                return;
            }

            int iOrig = mBuilds.IndexOf(mSelected);
            int iSelected;

            if (mBuilds.Count < 5)
            {
                iSelected = GUI.Toolbar(area, iOrig, mNames);
            }
            else
            {
                GUILayout.BeginArea(area);
                GUILayout.BeginHorizontal();
                iSelected = EditorGUILayout.Popup(iOrig, mNames);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.EndArea();
            }

            if (iSelected != iOrig)
            {
                mSelected = mBuilds[iSelected];
                HandleSelectionChange();
            }
        }
        public MiniInputCompile(ControlContext context)
        {
            mContext = context;

            NavmeshBuild build = context.Build;

            if (!build)
            {
                FinalizeOnFail("The control context's build does not exist.", true);
                return;
            }

            InputBuildOption options = InputBuildOption.ThreadSafeOnly;

            options |= (build.AutoCleanGeometry ? InputBuildOption.AutoCleanGeometry : 0);

            mBuilder = InputBuilder.Create(build.SceneQuery
                                           , build.GetInputProcessors()
                                           , options);

            if (mBuilder == null)
            {
                FinalizeOnFail("Could not create input builder.", true);
                return;
            }

            mState = State.Builder;
        }
        public TileSelection(NavmeshBuild build)
        {
            if (!build)
                throw new System.ArgumentNullException();

            mBuild = build;
        }
        public void Update()
        {
            if (mState == State.Finished)
            {
                // Nothing to do.
                return;
            }

            NavmeshBuild build = mContext.Build;

            if (!build)
            {
                FinalizeOnFail("Build has been deleted.", true);
                return;
            }

            if (mContext.Build.BuildState == NavmeshBuildState.Invalid)
            {
                FinalizeOnFail("Build has become invalid. Discarded input compile", true);
                return;
            }

            if (mState == State.Builder)
            {
                UpdateBuilder();
            }
            else
            {
                UpdateTask();
            }
        }
    static void CreateEmptyAsset()
    {
        NavmeshBuild item = EditorUtil.CreateAsset <NavmeshBuild>(NMBEditorUtil.AssetLabel);

        EditorUtility.FocusProjectWindow();
        Selection.activeObject = item;
    }
 public void OnRenderObject(NavmeshBuild build)
 {
     if (mEnabled && mShow && build && build.HasInputData)
     {
         InputGeometry geom = build.InputGeom;
         DebugDraw.Bounds(geom.BoundsMin.ToUnityVector3(), geom.BoundsMax.ToUnityVector3(), Color.grey);
     }
 }
Exemple #9
0
 public void OnRenderObject(NavmeshBuild build)
 {
     if (mEnabled && mShow && build && build.HasInputData)
     {
         InputGeometry geom = build.InputGeom;
         DebugDraw.Bounds(geom.BoundsMin, geom.BoundsMax, Color.grey);
     }
 }
        public void OnRenderObject(NavmeshBuild build, TileSelection selection)
        {
            if (!build)
            {
                return;
            }

            TileSetDefinition tdef = build.TileSetDefinition;

            if (!mShow || !mEnabled || build != selection.Build || tdef == null)
            {
                return;
            }

            Color color = ControlUtil.SelectionColor;

            DebugDraw.SimpleMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            GL.Color(color);

            if (selection.Validate())
            {
                Vector3 bmin;
                Vector3 bmax;
                Vector3 trash;

                TileZone zone = selection.Zone;

                tdef.GetTileBounds(zone.xmin, zone.zmin, true, out bmin, out trash);
                tdef.GetTileBounds(zone.xmax, zone.zmax, true, out trash, out bmax);

                DebugDraw.AppendBounds(bmin, bmax);

                if (mIncludeRootTile)
                {
                    GL.Color(new Color(0.93f, 0.58f, 0.11f)); // Orange

                    tdef.GetTileBounds(selection.SelectedX, selection.SelectedZ, true
                                       , out bmin, out bmax);

                    DebugDraw.AppendBounds(bmin, bmax);
                }
            }
            else
            {
                Vector3 bmax     = tdef.BoundsMin;
                float   tileSize = build.Config.TileWorldSize;
                bmax.x += tileSize * tdef.Width;
                bmax.y  = tdef.BoundsMax.y;
                bmax.z += tileSize * tdef.Depth;

                DebugDraw.AppendBounds(tdef.BoundsMin, bmax);
            }

            GL.End();
        }
Exemple #11
0
        public NavmeshBuildHelper(NavmeshBuild build)
        {
            if (!build)
            {
                throw new System.ArgumentNullException();
            }

            this.mBuild = build;
        }
Exemple #12
0
        public TileSelection(NavmeshBuild build)
        {
            if (!build)
            {
                throw new System.ArgumentNullException();
            }

            mBuild = build;
        }
        public static void OnGUIButtons(NavmeshBuild build
                                        , NMGenConfig config
                                        , bool isInspector)
        {
            if (!build)
            {
                return;
            }

            if (build.HasBuildData)
            {
                // Not an option if the build is in progress.
                return;
            }

            if (isInspector)
            {
                EditorGUILayout.BeginHorizontal();
            }

            if (GUILayout.Button("Clean"))
            {
                config.Clean();
                config.ApplyDecimalLimits();
                GUI.changed = true;
            }

            if (GUILayout.Button("Reset"))
            {
                config.Reset();
                GUI.changed = true;
            }

            if (!isInspector)
            {
                GUILayout.Space(2 * MarginSize);
            }

            if (build.HasInputData)
            {
                if (GUILayout.Button("Derive"))
                {
                    InputGeometry geom = build.InputGeom;

                    config.Derive(geom.BoundsMin, geom.BoundsMax);
                    config.ApplyDecimalLimits();

                    GUI.changed = true;
                }
            }

            if (isInspector)
            {
                EditorGUILayout.EndHorizontal();
            }
        }
Exemple #14
0
        public ControlContext(NavmeshBuild build, BuildTaskProcessor manager)
        {
            if (!build || manager == null)
                throw new System.ArgumentNullException();

            mTaskProcessor = manager;

            mBuild = build;
            mSelection = new TileSelection(build);
        }
Exemple #15
0
        public BuildController(NavmeshBuild build, BuildTaskProcessor manager)
        {
            if (!build || manager == null)
                throw new System.ArgumentNullException();

            mContext = new ControlContext(build, manager);
            mDebugContext = new DebugViewContext(build, mContext.Selection);

            mInputCon = new InputCompileControl();
            mConfigCon = new NMGenConfigControl();
        }
        public void OnRenderObject(NavmeshBuild build, TileSelection selection)
        {
            if (!build)
                return;

            TileSetDefinition tdef = build.TileSetDefinition;

            if (!mShow || !mEnabled || build != selection.Build || tdef == null)
                return;

            Color color = ControlUtil.SelectionColor;

            DebugDraw.SimpleMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            GL.Color(color);

            if (selection.Validate())
            {
                Vector3 bmin;
                Vector3 bmax;
                Vector3 trash;

                TileZone zone = selection.Zone;

                tdef.GetTileBounds(zone.xmin, zone.zmin, true, out bmin, out trash);
                tdef.GetTileBounds(zone.xmax, zone.zmax, true, out trash, out bmax);

                DebugDraw.AppendBounds(bmin, bmax);

                if (mIncludeRootTile)
                {
                    GL.Color(new Color(0.93f, 0.58f, 0.11f)); // Orange

                    tdef.GetTileBounds(selection.SelectedX, selection.SelectedZ, true
                        , out bmin, out bmax);

                    DebugDraw.AppendBounds(bmin, bmax);
                }
            }
            else
            {
                Vector3 bmax = tdef.BoundsMin;
                float tileSize = build.Config.TileWorldSize;
                bmax.x += tileSize * tdef.Width;
                bmax.y = tdef.BoundsMax.y;
                bmax.z += tileSize * tdef.Depth;

                DebugDraw.AppendBounds(tdef.BoundsMin, bmax);
            }

            GL.End();
        }
Exemple #17
0
        private bool Contains(NavmeshBuild build)
        {
            if (!build)
                return false;

            foreach (BuildController controller in mControllers)
            {
                if (controller.Build == build)
                    return true;
            }
            return false;
        }
Exemple #18
0
        private void HandleOnSelect(NavmeshBuild build)
        {
            if (!build || Contains(build))
                return;

            BuildController controller = new BuildController(build, mTaskManager);

            if (controller.Enter())
                mControllers.Add(controller);
            else
                Debug.LogError("Failed to add controller for build: " + build);
        }
Exemple #19
0
        public ControlContext(NavmeshBuild build, BuildTaskProcessor manager)
        {
            if (!build || manager == null)
            {
                throw new System.ArgumentNullException();
            }

            mTaskProcessor = manager;

            mBuild     = build;
            mSelection = new TileSelection(build);
        }
Exemple #20
0
        public void Add(NavmeshBuild build)
        {
            if (!build || mBuilds.Contains(build))
            {
                return;
            }

            mBuilds.Add(build);
            mBuilds.Sort(mComparer);
            RefreshNames();

            Validate();
        }
        public DebugViewContext(NavmeshBuild build, TileSelection selection) 
        {
            if (!build || selection == null)
                throw new System.ArgumentNullException();

            mSelectionView = new SelectionDebugView();
            mSelectionView.Enabled = true;
            mSelectionView.Show = true;
            mSelectionView.IncludeRootTile = true;

            mBuild = build;
            mSelection = selection;
        }
Exemple #22
0
        public BuildController(NavmeshBuild build, BuildTaskProcessor manager)
        {
            if (!build || manager == null)
            {
                throw new System.ArgumentNullException();
            }

            mContext      = new ControlContext(build, manager);
            mDebugContext = new DebugViewContext(build, mContext.Selection);

            mInputCon  = new InputCompileControl();
            mConfigCon = new NMGenConfigControl();
        }
Exemple #23
0
        public DebugViewContext(NavmeshBuild build, TileSelection selection) 
        {
            if (!build || selection == null)
                throw new System.ArgumentNullException();

            mSelectionView = new SelectionDebugView();
            mSelectionView.Enabled = true;
            mSelectionView.Show = true;
            mSelectionView.IncludeRootTile = true;

            mBuild = build;
            mSelection = selection;
        }
        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);
            }
        }
        private void ApplyData()
        {
            NavmeshBuild build = Context.Build;  // Caller checks for null.

            if (!build.SetInputData(Logger, mCompiler.Geometry
                                    , mCompiler.Info, mCompiler.Processors, mCompiler.Connections
                                    , true))
            {
                Logger.PostError("Could not apply input data.", build);
                return;  // Let the compiler persist so user can review it.
            }

            mCompiler = null;
        }
        public void OnRenderObject(NavmeshBuild build)
        {
            if (!build || !(mEnabled && mShow && build.HasInputData))
            {
                return;
            }

            Vector3 whd;
            Vector3 origin;
            int     gridWidth;
            int     gridDepth;

            float             tileWorldSize = build.Config.TileWorldSize;
            TileSetDefinition tdef          = build.TileSetDefinition;

            if (tdef != null)
            {
                // Use the real grid.
                origin    = tdef.BoundsMin;
                whd       = tdef.BoundsMax - tdef.BoundsMin;
                gridWidth = tdef.Width;
                gridDepth = tdef.Depth;
            }
            else if (build.HasInputData)
            {
                // Estimate from the input geometry.
                InputGeometry geom = build.InputGeom;
                origin    = geom.BoundsMin;
                whd       = geom.BoundsMax - geom.BoundsMin;
                gridWidth = Mathf.CeilToInt(whd.x / tileWorldSize);
                gridDepth = Mathf.CeilToInt(whd.z / tileWorldSize);
            }
            else
            {
                // Don't have the needed data.
                return;
            }

            origin.y += whd.y * mYOffset;

            if (build.Config.TileSize >= NavmeshBuild.MinAllowedTileSize)
            {
                DebugDraw.Grid(origin, tileWorldSize, gridWidth, gridDepth, Color.gray);
            }
            else
            {
                // Single tile.
                DebugDraw.Rect(origin, whd.x, whd.z, Color.gray, false);
            }
        }
Exemple #27
0
        public void Select(NavmeshBuild build)
        {
            Validate();

            // Note: Can't set to null.
            if (!build || build == mSelected || !mBuilds.Contains(build))
            {
                return;
            }

            mSelected = build;

            HandleSelectionChange();
        }
        protected override void OnGUIMain()
        {
            NavmeshBuild build = Context.Build;

            if (mBoxStyle == null)
            {
                mBoxStyle           = new GUIStyle(EditorUtil.ErrorStyle);
                mBoxStyle.alignment = TextAnchor.MiddleCenter;
            }

            GUI.Box(Context.MainArea
                    , (build ? build.name : "Unknown build") + " is not ready to build!\n"
                    + "Issue(s) must be corrected before a build can be started."
                    , mBoxStyle);
        }
Exemple #29
0
        public bool Enter()
        {
            // Note: Never returns false. Displays a failure control instead.

            if (mIsActive)
            {
                return(true);
            }

            NavmeshBuild build = mContext.Build;

            if (!build)
            {
                SetCriticalFailure("The build object has been deleted.");
                return(true);
            }

            build.CleanBuild();

            if (build.HasBuildData)
            {
                Debug.LogWarning("Build component contains intermediate build data."
                                 + " Potential causes:\n"
                                 + "Editor reset or entered play mode in the middle of a build.\n"
                                 + "User forgot to exit the build.\n"
                                 + "User keeping the data around for later use.\n"
                                 , build);
            }

            if (build.BuildState == NavmeshBuildState.NeedsRecovery)
            {
                // Special handling is needed since the normal state transition
                // never expects this state.
                if (SetInputControl(true))
                {
                    SetConfigControl(true);
                }
                mSelectedControl = ControlType.Input;
                mLastBuildState  = NavmeshBuildState.NeedsRecovery;
            }
            else
            {
                PerformStateTransition();
            }

            mIsActive = true;
            return(true);
        }
Exemple #30
0
        public void OnSceneGUI()
        {
            NavmeshBuild build = BuildSelector.Instance.Selected;

            if (!build)
                return;

            foreach (BuildController controller in mControllers)
            {
                if (controller.Build == build)
                {
                    controller.OnSceneGUI();
                    return;
                }
            }
        }
Exemple #31
0
        private bool Contains(NavmeshBuild build)
        {
            if (!build)
            {
                return(false);
            }

            foreach (BuildController controller in mControllers)
            {
                if (controller.Build == build)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #32
0
        public BuildProcessor()
        {
            mControllers = new List<BuildController>(3);

            mTaskManager = new BuildTaskProcessor(MaxConcurrency);
            Thread t = new Thread(new ThreadStart(mTaskManager.Run));
            t.Start();

            BuildSelector b = BuildSelector.Instance;

            b.OnSelect += HandleOnSelect;

            NavmeshBuild selected = b.Selected;
            if (selected)
                HandleOnSelect(selected);
        }
        public override bool Enter(ControlContext context, DebugViewContext debug)
        {
            if (base.Enter(context, debug))
            {
                NavmeshBuild build = context.Build;

                if (build.TileSetDefinition != null || build.Config.TileSize > 0)
                {
                    Debug.LogError(typeof(SingleTileBuildControl) + ": The build is tiled.", build);
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Exemple #34
0
        public void OnGUI(Rect area, bool includeMain)
        {
            NavmeshBuild build = BuildSelector.Instance.Selected;

            if (!build)
                return;

            foreach (BuildController controller in mControllers)
            {
                if (controller.Build == build)
                {
                    controller.OnGUI(area, includeMain);
                    return;
                }
            }
        }
Exemple #35
0
        public void Remove(NavmeshBuild build)
        {
            if (!build || !mBuilds.Contains(build))
            {
                return;
            }

            Validate();
            mBuilds.Remove(build);
            RefreshNames();

            if (mSelected == build)
            {
                mSelected = (mBuilds.Count > 0 ? mBuilds[0] : null);
                HandleSelectionChange();
            }
        }
        public override bool Enter(ControlContext context, DebugViewContext debug)
        {
            if (base.Enter(context, debug))
            {
                NavmeshBuild build = context.Build;

                if (build.TileSetDefinition == null)
                {
                    Debug.LogError(typeof(MultiTileBuildControl)
                                   + ": Build data has not been initialized, or not a tiled build.");
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Exemple #37
0
    void OnSelectionChange()
    {
        Object selection = Selection.activeObject;

        if (!selection || !(selection is NavmeshBuild))
        {
            return;
        }

        NavmeshBuild build = (NavmeshBuild)selection;

        if (build.BuildType != NavmeshBuildType.Advanced)
        {
            return;
        }

        BuildSelector.Instance.Select(build);
    }
        public void OnRenderObject(NavmeshBuild build)
        {
            if (!build || !(mEnabled && mShow && build.HasInputData))
                return;

            Vector3 whd;
            Vector3 origin;
            int gridWidth;
            int gridDepth;

            float tileWorldSize = build.Config.TileWorldSize;
            TileSetDefinition tdef = build.TileSetDefinition;

            if (tdef != null)
            {
                // Use the real grid.
                origin = tdef.BoundsMin;
                whd = tdef.BoundsMax - tdef.BoundsMin;
                gridWidth = tdef.Width;
                gridDepth = tdef.Depth;
            }
            else if (build.HasInputData)
            {
                // Estimate from the input geometry.
                InputGeometry geom = build.InputGeom;
                origin = geom.BoundsMin;
                whd = geom.BoundsMax - geom.BoundsMin;
                gridWidth = Mathf.CeilToInt(whd.x / tileWorldSize);
                gridDepth = Mathf.CeilToInt(whd.z / tileWorldSize);
            }
            else
                // Don't have the needed data.
                return;

            origin.y += whd.y * mYOffset;

            if (build.Config.TileSize >= NavmeshBuild.MinAllowedTileSize)
                DebugDraw.Grid(origin, tileWorldSize, gridWidth, gridDepth, Color.gray);
            else
                // Single tile.
                DebugDraw.Rect(origin, whd.x, whd.z, Color.gray, false);
        }
        internal static NavmeshBuildInfo GetConfig(NavmeshBuild build)
        {
            if (!build)
                return null;

            NMGenParams config = build.Config.GetConfig();

            NavmeshBuildInfo result = new NavmeshBuildInfo();

            result.tileSize = config.TileSize;
            result.walkableHeight = config.WalkableHeight;
            result.walkableRadius = config.WalkableRadius;
            result.walkableStep = config.WalkableStep;
            result.xzCellSize = config.XZCellSize;
            result.yCellSize = config.YCellSize;
            result.borderSize = config.BorderSize;
            result.inputScene = EditorApplication.currentScene;

            return result;
        }
Exemple #40
0
        private void HandleInputGeom(NavmeshBuild build, int tx, int tz)
        {
            if (build.InputGeom != mLastGeom)
            {
                // Input geometry has changed.  Clear debug object.
                mLastGeom = build.InputGeom;
                mDebugObject = null;
            }

            if (build.InputGeom == null)
                return;

            if (mDebugObject == null)
            {
                TileSetDefinition tdef = build.TileSetDefinition;

                Vector3 bmin;
                Vector3 bmax;

                tdef.GetTileBounds(tx, tz, true, out bmin, out bmax);

                Geom geom = new Geom();

                geom.mesh = 
                    build.InputGeom.ExtractMesh(bmin.x, bmin.z, bmax.x, bmax.z, out geom.areas);

                mDebugObject = geom;
            }

            if (mDebugObject != null)
            {
                Geom geom = (Geom)mDebugObject;
                if (geom.mesh.triCount > 0)
                {
                    DebugDraw.TriangleMesh(geom.mesh.verts
                        , geom.mesh.tris, geom.areas, geom.mesh.triCount
                        , true, 0.25f);
                }
            }
        }
    private static void OnGUIState(NavmeshBuild build)
    {
        INavmeshData btarget = build.BuildTarget;
        NavmeshBuildInfo binfo = (btarget == null ? null : btarget.BuildInfo);

        EditorGUILayout.Separator();

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        if (build.BuildState == NavmeshBuildState.Invalid)
        {

            if (!(ScriptableObject)btarget)
                 sb.AppendLine("No build target.");

            if (build.inputProcessors.Count == 0)
                sb.AppendLine("No input processors.");

            GUILayout.Label(sb.ToString().Trim()
                , EditorUtil.ErrorStyle, GUILayout.ExpandWidth(true));

            return;
        }

        sb.AppendLine("Input Scene: " + NavEditorUtil.SceneDisplayName(binfo));

        if (build.SceneQuery == null)
            sb.AppendLine("Search scope: Entire scene");

        if (build.TargetHasNavmesh)
            sb.AppendLine("Target has existing navmesh.");
        else
            sb.AppendLine("Target does not have a navmesh.");

        if (build.BuildType == NavmeshBuildType.Advanced)
        {
            TileBuildData tdata = build.BuildData;
            sb.AppendLine("Build state: " + build.BuildState);
            sb.AppendLine("Active builds: " 
                + (tdata == null ? 0 : build.BuildData.GetActive()));
        }

        GUILayout.Label(sb.ToString().Trim()
            , EditorUtil.HelpStyle
            , GUILayout.ExpandWidth(true));


        if (NavEditorUtil.SceneMismatch(binfo))
        {
            GUILayout.Box("Current scene does not match last input scene."
                , EditorUtil.WarningStyle
                , GUILayout.ExpandWidth(true));
        }

        EditorGUILayout.Separator();

        GUI.enabled = (btarget != null);

        NavmeshSceneDraw.Instance.OnGUI(build.BuildTarget, "Show Mesh", true, true);

        GUI.enabled = true;

        return;
    }
        public static void OnGUIButtons(NavmeshBuild build
            , NMGenConfig config
            , bool isInspector)
        {
            if (!build)
                return;

            if (build.HasBuildData)
                // Not an option if the build is in progress.
                return;

            if (isInspector)
                EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Clean"))
            {
                config.Clean();
                config.ApplyDecimalLimits();
                GUI.changed = true;
            }

            if (GUILayout.Button("Reset"))
            {
                config.Reset();
                GUI.changed = true;
            }

            if (!isInspector)
                GUILayout.Space(2 * MarginSize);

            if (build.HasInputData)
            {
                if (GUILayout.Button("Derive"))
                {
                    InputGeometry geom = build.InputGeom;

                    config.Derive(geom.BoundsMin, geom.BoundsMax);
                    config.ApplyDecimalLimits();

                    GUI.changed = true;
                }
            }

            if (isInspector)
                EditorGUILayout.EndHorizontal();

        }
    private static void OnGUIAdvanced(NavmeshBuild build)
    {
        EditorGUILayout.Separator();

        if (GUILayout.Button("Manage Build"))
            NavmeshBuildManager.OpenWindow();

        //// Only allow a reset when not in the buildable state.
        if (build.BuildState != NavmeshBuildState.Inactive)
        {
            GUI.enabled = true;
            EditorGUILayout.Separator();
            if (GUILayout.Button("Reset Build"))
                build.ResetBuild();
        }
    }
        public static void OnGUIPrimary(NavmeshBuild build
            , NMGenConfig config
            , bool includeSlope)
        {
            if (!build)
                return;

            bool guiEnabled = GUI.enabled;

            EditorGUIUtility.LookLikeControls(155);

            float xz = config.XZCellSize;
            float y = config.YCellSize;
            float a = xz * xz;
            float effective;

            //////////////////////////////////////////////////////////////

            GUILayout.Label("Agent Settings");
            GUILayout.Space(MarginSize);

            TileBuildData tdata = build.BuildData;

            GUI.enabled = guiEnabled && (tdata == null);

            effective = (float)Mathf.Ceil(config.WalkableHeight / y) * y;

            config.WalkableHeight = EditorGUILayout.FloatField(
                NMGenConfig.HeightLabel + Effective(effective)
                , config.WalkableHeight);


            effective = (float)Mathf.Floor(config.WalkableStep / y) * y;
            config.WalkableStep = EditorGUILayout.FloatField(
                NMGenConfig.StepLabel + Effective(effective)
                , config.WalkableStep);

            effective = (float)Mathf.Ceil(config.WalkableRadius / xz) * xz;
            config.WalkableRadius = EditorGUILayout.FloatField(
                NMGenConfig.RadiusLabel + Effective(effective)
                , config.WalkableRadius);

            GUI.enabled = guiEnabled;

            if (includeSlope)
            {
                config.WalkableSlope = EditorGUILayout.FloatField(
                    NMGenConfig.SlopeLabel
                    , config.WalkableSlope);
            }

            /////////////////////////////////////////////////////////////////

            GUILayout.Space(2 * MarginSize);
            GUILayout.Label("Resolution and Tile Settings");
            GUILayout.Space(MarginSize);

            GUI.enabled = guiEnabled && (tdata == null);

            config.XZCellSize = EditorGUILayout.FloatField(
                NMGenConfig.XZSizeLabel
                , config.XZCellSize);

            config.YCellSize = EditorGUILayout.FloatField(
                NMGenConfig.YSizeLabel
                , config.YCellSize);

            config.TileSize = EditorGUILayout.IntField(
                NMGenConfig.TileSizeLabel
                    + " (" + config.TileSize * config.XZCellSize + ")"
                , config.TileSize);


            config.BorderSize = EditorGUILayout.IntField(
                NMGenConfig.HFBorderLabel
                , config.BorderSize);

            GUI.enabled = guiEnabled;

            int derBorderSize = NMGenConfig.DeriveBorderSize(config);
            float derXZ = NMGenConfig.DeriveXZCellSize(config);
            float derY = NMGenConfig.DeriveYCellSize(config);

            if ((config.TileSize == 0 && config.BorderSize != derBorderSize)
                || config.BorderSize < derBorderSize
                || config.XZCellSize > derXZ
                || config.YCellSize > derY)
            {
                GUILayout.Space(MarginSize);

                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                sb.AppendLine("Recommendations:");

                if (config.XZCellSize > derXZ)
                    sb.AppendLine(NMGenConfig.XZSizeLabel + " of " + derXZ + " or less.");

                if (config.YCellSize > derY)
                    sb.AppendLine(NMGenConfig.YSizeLabel + " of " + derY + " or less.");

                if (config.TileSize == 0 && config.BorderSize != derBorderSize)
                    sb.AppendLine("Border Size of " + derBorderSize + ".");
                else if (config.BorderSize < derBorderSize)
                    sb.AppendLine("Border Size of " + derBorderSize + " or higher.");

                GUILayout.Box(sb.ToString().Trim(), EditorUtil.HelpStyle, GUILayout.ExpandWidth(true));
            }

            if (build.HasInputData)
            {
                InputGeometry geom = build.InputGeom;

                Vector3 bmin = geom.BoundsMin;
                Vector3 bmax = geom.BoundsMax;

                float w = bmax.x - bmin.x;
                float d = bmax.z - bmin.z;

                GUILayout.Space(MarginSize);

                int tw = Mathf.CeilToInt(w / xz);
                int td = Mathf.CeilToInt(d / xz);
                GUILayout.Label(string.Format("Cells: {0:N0} ({1:N0} x {2:N0})"
                    , tw * td, tw, td));

                if (config.TileSize > 0)
                {
                    tw = Mathf.Max(1, Mathf.CeilToInt((float)tw / config.TileSize));
                    td = Mathf.Max(1, Mathf.CeilToInt((float)td / config.TileSize));
                }
                else
                {
                    tw = 1;
                    td = 1;
                }
                GUILayout.Label(string.Format("Tiles: {0:N0} ({1:N0} x {2:N0})"
                    , tw * td, tw, td));
            }

            /////////////////////////////////////////////////////////////////

            GUILayout.Space(2 * MarginSize);
            GUILayout.Label("Miscellaneous Settings");
            GUILayout.Space(MarginSize);

            config.DetailSampleDistance = EditorGUILayout.FloatField(
                NMGenConfig.DetailSampleLabel
                , config.DetailSampleDistance);

            config.DetailMaxDeviation = EditorGUILayout.FloatField(
                NMGenConfig.DetailDevLabel
                , config.DetailMaxDeviation);

            effective = Mathf.Ceil(config.MinRegionArea / a) * a;
            config.MinRegionArea = EditorGUILayout.FloatField(
                NMGenConfig.IslandRegionLabel + Effective(effective)
                , config.MinRegionArea);
        }
Exemple #45
0
        public void HandleDetailMesh(NavmeshBuild build, int tx, int tz)
        {
            if (!build)
                return;

            if (mDebugObject == null)
            {
                PolyMeshDetail mesh = build.BuildData.GetDetailMesh(tx, tz);

                if (mesh != null)
                    mDebugObject = mesh.GetData(false);
            }

            if (mDebugObject != null)
                NMGenDebug.Draw((PolyMeshDetailData)mDebugObject);
        }
Exemple #46
0
        public void OnRenderObject(NavmeshBuild build, TileSelection selection)
        {
            if (!build)
                return;

            TileBuildData tdata = build.BuildData;

            if (!mEnabled
                || mShow == MeshDebugOption.None
                || tdata == null  // This restriction is appropriate.
                || build != selection.Build)  // Important error check.
            {
                return;
            }

            INavmeshData target = build.BuildTarget;

            if (target != null && target.HasNavmesh && NavmeshSceneDraw.Instance.IsShown(target))
                // Don't overdraw the target mesh's display.  It has priority.
                return;

            if (tdata.Version != mLastVersion)
            {
                // Build data has changed.  Clear debug object.
                mLastVersion = tdata.Version;
                mDebugObject = null;
            }

            int tx = 0;
            int tz = 0;
            int size = 0;

            if (tdata.IsTiled)
            {
                tx = selection.SelectedX;
                tz = selection.SelectedZ;
                size = selection.ZoneSize;
            }

            if (mLastX != tx || mLastZ != tz || mLastSize != size)
            {
                // Change in selection.  Clear debug object.
                mLastX = tx;
                mLastZ = tz;
                mLastSize = size;
                mDebugObject = null;
                // Debug.Log("Clear debug on selection change.");
            }

            if (mShow == MeshDebugOption.WorkingMesh)
            {
                HandleWorkingNavmesh(selection);
                return;
            }
            else if (tdata.IsTiled && !selection.Validate())
            {
                // The mesh is tiled with no valid selection.
                // Can't display any of the other meshes.
                mLastX = -1;
                mLastZ = -1;
                mLastSize = -1;
                return;
            }

            // Can only display a single tile for all other display options.
            // Choose the tile to display.

            switch (mShow)
            {
                case MeshDebugOption.PolyMesh:

                    HandlePolyMesh(build, tx, tz);
                    break;

                case MeshDebugOption.Detailmesh:

                    HandleDetailMesh(build, tx, tz);
                    break;

                case MeshDebugOption.InputGeometry:

                    if (build.TileSetDefinition != null)
                        HandleInputGeom(build, tx, tz);
                    break;
            }
        }
    private static void OnGUIStandard(NavmeshBuild build)
    {
        EditorGUILayout.Separator();

        GUI.enabled = (build.BuildState != NavmeshBuildState.Invalid);

        if (GUILayout.Button("Build & Bake"))
        {
            NavmeshBuildHelper helper = new NavmeshBuildHelper(build);
            helper.Build();
        }

        EditorGUILayout.Separator();

        bool origChanged = GUI.changed;

        UnityBuildContext.TraceEnabled = 
            EditorGUILayout.Toggle("Trace", UnityBuildContext.TraceEnabled);

        GUI.changed = origChanged;

        EditorGUILayout.Separator();

        GUI.enabled = true;

        bool orig = mShowNMGenConfig;
        mShowNMGenConfig = EditorGUILayout.Foldout(mShowNMGenConfig, "NMGen Configuration");
        if (orig != mShowNMGenConfig)
            EditorPrefs.SetBool(ShowNMGenKey, mShowNMGenConfig);

        if (mShowNMGenConfig)
        {
            EditorGUILayout.Separator();

            NMGenConfig config = build.Config;

            EditorGUILayout.Separator();

            NMGenConfigControl.OnGUIButtons(build, config, true);

            GUI.enabled = (build.BuildState != NavmeshBuildState.Invalid);

            if (GUILayout.Button("Derive"))
            {
                NavmeshBuildHelper helper = new NavmeshBuildHelper(build);

                InputAssets assets = helper.BuildInput();

                if (assets.geometry != null)
                {
                    TriangleMesh m = assets.geometry;

                    Vector3 bmin;
                    Vector3 bmax;

                    m.GetBounds(out bmin, out bmax);

                    config.Derive(bmin, bmax);
                    config.ApplyDecimalLimits();

                    GUI.changed = true;
                }
            }

            GUI.enabled = true;

            EditorGUILayout.Separator();

            orig = mShowPrimaryConfig;
            mShowPrimaryConfig = EditorGUILayout.Foldout(mShowPrimaryConfig, "Primary");
            if (orig != mShowPrimaryConfig)
                EditorPrefs.SetBool(ShowNMGenPriKey, mShowPrimaryConfig);

            if (mShowPrimaryConfig)
                NMGenConfigControl.OnGUIPrimary(build, config, true);

            EditorGUILayout.Separator();

            orig = mShowAdvancedConfig;
            mShowAdvancedConfig =
                EditorGUILayout.Foldout(mShowAdvancedConfig, "Advanced");
            if (orig != mShowAdvancedConfig)
                EditorPrefs.SetBool(ShowNMGenAdvKey, mShowAdvancedConfig);

            if (mShowAdvancedConfig)
                NMGenConfigControl.OnGUIAdvanced(config, true);

            if (GUI.changed)
                build.IsDirty = true;
        }
    }