void OnRenderObject() { if (!mDebugEnabled) { return; } INavmeshData data = NavmeshData; if (!mNavmeshData || !data.HasNavmesh) { mDebugMesh = null; return; } if (mDebugMesh == null || data.Version != mDebugVersion) { mDebugMesh = data.GetNavmesh(); mDebugVersion = data.Version; if (mDebugMesh == null) { return; } } NavDebug.Draw(mDebugMesh, false); }
/// <summary> /// Disable the visualization. /// </summary> public void Hide() { if (mDelegate != null) { SceneView.onSceneGUIDelegate -= mDelegate; SceneView.RepaintAll(); } mNavmeshData = null; mDataVersion = -1; mNavmesh = null; mDelegate = null; }
/// <summary> /// Displays an object field that will only accept ScriptableObjects that implement /// the <see cref="INavmeshData"/> interface. /// </summary> /// <remarks> /// <para> /// Handles error logging when an invalid object is selected. /// </para> /// </remarks> /// <param name="label">The label for the object field.</param> /// <param name="item">The ScriptableObject the field shows.</param> /// <returns>The ScriptableObject selected by the user.</returns> public static INavmeshData OnGUINavmeshDataField(string label, INavmeshData item) { ScriptableObject so = (ScriptableObject)item; ScriptableObject nso = (ScriptableObject)EditorGUILayout.ObjectField(label , so, typeof(ScriptableObject), false); if (nso is INavmeshData || !nso) // Null OK. return (INavmeshData)nso; Debug.LogError( string.Format("{0} does not implement {1}.", nso.name, typeof(INavmeshData).Name)); return item; }
/// <summary> /// Show the visualization for the object. /// </summary> /// <param name="data">The object to visualize.</param> public void Show(INavmeshData data) { Hide(); if (!(ScriptableObject)data) { return; } mNavmeshData = data; mDelegate = new SceneView.OnSceneFunc(OnSceneGUI); SceneView.onSceneGUIDelegate += mDelegate; SceneView.RepaintAll(); }
/// <summary> /// Displays an object field that will only accept ScriptableObjects that implement /// the <see cref="INavmeshData"/> interface. /// </summary> /// <remarks> /// <para> /// Handles error logging when an invalid object is selected. /// </para> /// </remarks> /// <param name="label">The label for the object field.</param> /// <param name="item">The ScriptableObject the field shows.</param> /// <returns>The ScriptableObject selected by the user.</returns> public static INavmeshData OnGUINavmeshDataField(string label, INavmeshData item) { ScriptableObject so = (ScriptableObject)item; ScriptableObject nso = (ScriptableObject)EditorGUILayout.ObjectField(label , so, typeof(ScriptableObject), false); if (nso is INavmeshData || !nso) // Null OK. { return((INavmeshData)nso); } Debug.LogError( string.Format("{0} does not implement {1}.", nso.name, typeof(INavmeshData).Name)); return(item); }
public void OnGUIMeshDisplayOptions() { if (!mBuild || !mMeshView.Enabled) return; bool guiEnabled = GUI.enabled; MeshDebugView meshView = mMeshView; INavmeshData bnm = mBuild.BuildTarget; NavmeshSceneDraw sceneDraw = NavmeshSceneDraw.Instance; bool showBaked = false; if (bnm != null) { showBaked = sceneDraw.OnGUI(bnm, "Baked Navmesh", false, false); if (showBaked) meshView.Show = MeshDebugOption.None; } if (GUILayout.Toggle(meshView.Show == MeshDebugOption.WorkingMesh , "Working Navmesh")) { meshView.Show = MeshDebugOption.WorkingMesh; showBaked = false; } else if (meshView.Show == MeshDebugOption.WorkingMesh) meshView.Show = MeshDebugOption.None; GUI.enabled = guiEnabled && meshView.Show == MeshDebugOption.WorkingMesh || showBaked; bool orig = sceneDraw.ColorByArea; sceneDraw.ColorByArea = GUILayout.Toggle(sceneDraw.ColorByArea, "Color by Area"); if (sceneDraw.ColorByArea != orig) mNeedsRepaint = true; GUILayout.Space(ControlUtil.MarginSize); GUI.enabled = guiEnabled && (mSelection.HasSelection || !mBuild.BuildData.IsTiled); if (GUILayout.Toggle(meshView.Show == MeshDebugOption.PolyMesh , "PolyMesh")) { meshView.Show = MeshDebugOption.PolyMesh; showBaked = false; } else if (meshView.Show == MeshDebugOption.PolyMesh) meshView.Show = MeshDebugOption.None; if (GUILayout.Toggle(meshView.Show == MeshDebugOption.Detailmesh , "Detail Mesh")) { meshView.Show = MeshDebugOption.Detailmesh; showBaked = false; } else if (meshView.Show == MeshDebugOption.Detailmesh) meshView.Show = MeshDebugOption.None; if (mBuild.TileSetDefinition != null) { if (GUILayout.Toggle(meshView.Show == MeshDebugOption.InputGeometry , mShowInputLabel)) { meshView.Show = MeshDebugOption.InputGeometry; showBaked = false; } else if (meshView.Show == MeshDebugOption.InputGeometry) meshView.Show = MeshDebugOption.None; } GUI.enabled = guiEnabled; if (showBaked) meshView.Show = MeshDebugOption.None; else sceneDraw.Hide(); }
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; }
/// <summary> /// True if the object is currently assigned for visualization. /// </summary> /// <param name="data">The object to visualize.</param> /// <returns>True if the object is currently assigned for visualization.</returns> public bool IsShown(INavmeshData data) { return((ScriptableObject)data && data == mNavmeshData); }
/// <summary> /// Provides a standard Editor GUI for managing scene drawing. /// </summary> /// <param name="target">The object being managed by the GUI.</param> /// <param name="label">The label of the 'show' toggle.</param> /// <param name="isInspector">True if the inspector format should be used.</param> /// <param name="includeAreaOption"> /// True if the option to color by area should be displayed. /// </param> /// <returns>True the display of the target has been toggled on.</returns> public bool OnGUI(INavmeshData target , string label , bool isInspector , bool includeAreaOption) { if (!(ScriptableObject)target) { return(false); } bool guiEnabled = GUI.enabled; bool origChanged = GUI.changed; GUI.changed = false; bool orig = IsShown(target); bool curr; if (isInspector) { curr = EditorGUILayout.Toggle(label, orig); GUI.enabled = guiEnabled && curr; if (includeAreaOption) { mColorByArea = EditorGUILayout.Toggle("Color by area", mColorByArea); } } else { curr = GUILayout.Toggle(orig, label); GUI.enabled = guiEnabled && curr; if (includeAreaOption) { mColorByArea = GUILayout.Toggle(mColorByArea, "Color by area"); } } GUI.enabled = guiEnabled; if (orig != curr) { if (curr) { Show(target); } else { Hide(); } } if (GUI.changed) { SceneView.RepaintAll(); } GUI.changed = origChanged; return(curr); }
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; } }
internal bool CanLoadFromTarget(BuildContext context, bool fullCheck) { INavmeshData target = BuildTarget; if (target == null || !target.HasNavmesh) { if (context != null) { context.LogError("Build target does not have an existing navigation mesh.", this); } return(false); } NavmeshBuildInfo targetConfig = target.BuildInfo; // Note: The tile size is checked since the original builder // may have supported a tile size not supported by the the standard build. if (targetConfig == null || targetConfig.tileSize >= 0 && targetConfig.tileSize < MinAllowedTileSize) { if (context != null) { context.LogError("Unavailable or unsupported build target configuration.", this); } return(false); } if (!fullCheck) { return(true); } Navmesh nm = target.GetNavmesh(); if (nm == null) { if (context != null) { context.LogError( "Build target does not have an existing navigation mesh. (It lied.)", this); } return(false); } NavmeshParams nmConfig = nm.GetConfig(); if (nmConfig.maxTiles < 2) { if (context != null) { context.LogError("Target navigation mesh is not tiled.", this); } return(false); } int tileCount = 0; for (int i = 0; i < nmConfig.maxTiles; i++) { NavmeshTile tile = nm.GetTile(i); if (tile == null) { continue; } NavmeshTileHeader header = tile.GetHeader(); if (header.polyCount == 0) { continue; } tileCount++; if (header.layer > 0) { if (context != null) { context.LogError( "Target navigation mesh contains layered tiles. (Not supported.)", this); } return(false); } } if (tileCount < 2) { if (context != null) { context.LogError( "Target navigation mesh is either not tiled or has no tiles loaded.", this); } return(false); } return(true); }
/// <summary> /// Show the visualization for the object. /// </summary> /// <param name="data">The object to visualize.</param> public void Show(INavmeshData data) { Hide(); if (!(ScriptableObject)data) return; mNavmeshData = data; mDelegate = new SceneView.OnSceneFunc(OnSceneGUI); SceneView.onSceneGUIDelegate += mDelegate; SceneView.RepaintAll(); }
/// <summary> /// True if the object is currently assigned for visualization. /// </summary> /// <param name="data">The object to visualize.</param> /// <returns>True if the object is currently assigned for visualization.</returns> public bool IsShown(INavmeshData data) { return ((ScriptableObject)data && data == mNavmeshData); }
/// <summary> /// Provides a standard Editor GUI for managing scene drawing. /// </summary> /// <param name="target">The object being managed by the GUI.</param> /// <param name="label">The label of the 'show' toggle.</param> /// <param name="isInspector">True if the inspector format should be used.</param> /// <param name="includeAreaOption"> /// True if the option to color by area should be displayed. /// </param> /// <returns>True the display of the target has been toggled on.</returns> public bool OnGUI(INavmeshData target , string label , bool isInspector , bool includeAreaOption) { if (!(ScriptableObject)target) return false; bool guiEnabled = GUI.enabled; bool origChanged = GUI.changed; GUI.changed = false; bool orig = IsShown(target); bool curr; if (isInspector) { curr = EditorGUILayout.Toggle(label, orig); GUI.enabled = guiEnabled && curr; if (includeAreaOption) mColorByArea = EditorGUILayout.Toggle("Color by area", mColorByArea); } else { curr = GUILayout.Toggle(orig, label); GUI.enabled = guiEnabled && curr; if (includeAreaOption) mColorByArea = GUILayout.Toggle(mColorByArea, "Color by area"); } GUI.enabled = guiEnabled; if (orig != curr) { if (curr) Show(target); else Hide(); } if (GUI.changed) { SceneView.RepaintAll(); } GUI.changed = origChanged; return curr; }
/// <summary> /// Controls behavior of the inspector. /// </summary> public override void OnInspectorGUI() { NavManagerProvider targ = (NavManagerProvider)target; INavmeshData navmeshData = targ.NavmeshData; string msg = ""; if (navmeshData == null || !navmeshData.HasNavmesh) { msg = "No navigation mesh.\n"; } if (!targ.AvoidanceSet) { msg += "No avoidance set.\n"; } if (!targ.AgentGroups) { msg += "No agent groups.\n"; } if (msg.Length > 0) { GUILayout.Box(msg.Trim(), EditorUtil.ErrorStyle, GUILayout.ExpandWidth(true)); } EditorGUILayout.Separator(); bool bv = EditorGUILayout.Toggle("Show Mesh", targ.DebugEnabled); if (bv != targ.DebugEnabled) { if (bv) { // Turn off asset draw. org.critterai.nav.u3d.editor.NavmeshSceneDraw.Instance.Hide(); } targ.DebugEnabled = bv; } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Navigation Settings"); EditorGUILayout.Separator(); targ.NavmeshData = NavEditorUtil.OnGUINavmeshDataField("Navmesh Data", targ.NavmeshData); targ.AgentGroups = (AgentGroupSettings)EditorGUILayout.ObjectField( "Agent Groups", targ.AgentGroups, typeof(AgentGroupSettings), false); EditorGUILayout.Separator(); targ.MaxQueryNodes = EditorGUILayout.IntField("Max Query Nodes", targ.MaxQueryNodes); targ.MaxPathSize = EditorGUILayout.IntField("Max Path Size", targ.MaxPathSize); targ.MaxStraightPathSize = EditorGUILayout.IntField("Max Straight Path", targ.MaxStraightPathSize); targ.MaxAgents = EditorGUILayout.IntField("Max Nav Agents", targ.MaxAgents); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Crowd Settings"); EditorGUILayout.Separator(); targ.MaxCrowdAgents = EditorGUILayout.IntField("Max Crowd Agents", targ.MaxCrowdAgents); targ.MaxAgentRadius = EditorGUILayout.FloatField("Max Agent Radius", targ.MaxAgentRadius); EditorGUILayout.Separator(); targ.AvoidanceSet = (CrowdAvoidanceSet)EditorGUILayout.ObjectField( "Avoidance Set", targ.AvoidanceSet, typeof(CrowdAvoidanceSet), false); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Accuracy Settings"); EditorGUILayout.Separator(); targ.Extents = EditorGUILayout.Vector3Field("Extents", targ.Extents); targ.WideExtents = EditorGUILayout.Vector3Field("Wide Extents", targ.WideExtents); EditorGUILayout.Separator(); targ.RadiusAt = EditorGUILayout.FloatField("Radius At", targ.RadiusAt); targ.RadiusNear = EditorGUILayout.FloatField("Radius Near", targ.RadiusNear); targ.HeightTolerance = EditorGUILayout.FloatField("Height Tolerance", targ.HeightTolerance); EditorGUILayout.Separator(); targ.TurnThreshold = EditorGUILayout.FloatField("Turn Threshold", targ.TurnThreshold); targ.AngleAt = EditorGUILayout.FloatField("Angle At", targ.AngleAt); EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (GUI.changed) { EditorUtility.SetDirty(target); } }