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(); }
private void HandleBuildRequest(bool forceAll) { TileSelection sel = Context.Selection; int w; int d; int ix = 0; int iz = 0; int priority; if (!forceAll && sel.Validate()) { TileZone zone = sel.Zone; w = zone.xmax + 1; d = zone.zmax + 1; ix = zone.xmin; iz = zone.zmin; priority = BuildTaskProcessor.MediumPriority; } else { TileBuildData tdata = Context.Build.BuildData; w = tdata.Width; d = tdata.Depth; priority = BuildTaskProcessor.LowPriority; } // Note: The iteration order appears odd, but it makes for better // progress visualizations. Filling downward. for (int tz = d - 1; tz >= iz; tz--) { for (int tx = ix; tx < w; tx++) { if (!Context.QueueTask(tx, tz, priority--, Logger)) { Logger.PostError(string.Format("Build task failed: ({0},{1})", tx, tz) , Context.Build); } } } }
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; } }
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(); }
protected override void OnGUIMain() { if (mBlackLabel == null) { // Need to initialize shared style. mBlackLabel = new GUIStyle(GUI.skin.label); mBlackLabel.normal.textColor = Color.black; mBlackLabel.fontStyle = FontStyle.Bold; } TileSelection selection = Context.Selection; selection.Validate(); TileBuildData tdata = Context.Build.BuildData; if (tdata == null) { return; } Rect mainArea = Context.MainArea; // The box and shift makes it look better. GUI.Box(mainArea, ""); mainArea.x += MarginSize; mainArea.y += MarginSize; // Draw the status grid. // Note: View is expanded by one grid size in order to minimize // grid/slider overlap. Rect view = new Rect(0, 0, tdata.Width * GridCellSize + GridCellSize , tdata.Depth * GridCellSize + GridCellSize); mScrollPos = GUI.BeginScrollView(mainArea, mScrollPos, view); OnGUIStatusGrid(view.height - GridCellSize); GUI.EndScrollView(); OnGUIMainStandard(); if (IsBaseBusy) { return; } // Handle the mouse, including click selection. Event evt = Event.current; Vector2 mousePos = evt.mousePosition; if (mainArea.Contains(mousePos)) { Vector2 gridPos = mousePos; gridPos.x -= mainArea.xMin - mScrollPos.x; gridPos.y -= mainArea.yMin - mScrollPos.y; int x = Mathf.FloorToInt(gridPos.x / GridCellSize); // For the depth, we need to invert the y-axis. int z = tdata.Depth - Mathf.FloorToInt(gridPos.y / GridCellSize) - 1; if (x < tdata.Width && z >= 0 && z < tdata.Depth) { GUI.Label(new Rect(mousePos.x - 20, mousePos.y - 20, 120, 25) , "(" + x + "," + z + "): " + tdata.GetState(x, z) , mBlackLabel); mMouseX = x; mMouseZ = z; if (evt.type == EventType.MouseDown && evt.button == 0) { if (selection.SelectedX == mMouseX && selection.SelectedZ == mMouseZ) { // Clicked on same tile. Deselect. selection.ClearSelection(); } else { selection.SetSelection(mMouseX, mMouseZ); } } } else { mMouseX = TileSelection.NoSelection; mMouseZ = TileSelection.NoSelection; } } else { mMouseX = TileSelection.NoSelection; mMouseZ = TileSelection.NoSelection; } }
protected override void OnGUIButtons() { DebugContext.SetViews(ViewOption.Grid | ViewOption.Selection | ViewOption.Mesh); NavmeshBuild build = Context.Build; if (!build) { return; } TileBuildData tdata = build.BuildData; if (tdata == null) { return; } TileSelection selection = Context.Selection; bool hasSelection = selection.Validate(); bool needBaking = (tdata.NeedsBakingCount() > 0); int activeCount = Context.TaskCount; int bakeableCount = tdata.BakeableCount(); bool origGUIEnabled = GUI.enabled; bool guiEnabled = !IsBaseBusy; GUI.enabled = guiEnabled; ControlUtil.BeginButtonArea(Context.ButtonArea); if (GUILayout.Button("Build All")) { HandleBuildRequest(true); } GUI.enabled = guiEnabled && hasSelection; if (GUILayout.Button("Build Zone")) { HandleBuildRequest(false); } //////////////////////////////////////////////////////////////////// GUILayout.Space(MarginSize); // Only disable baking if there is nothing at all that can be baked. GUI.enabled = guiEnabled && activeCount == 0 && (bakeableCount > 0); GUIStyle style = (bakeableCount > 0 && activeCount == 0) ? ControlUtil.HighlightedButton : GUI.skin.button; if (GUILayout.Button("Bake All", style)) { HandleBake(); } //////////////////////////////////////////////////////////////////// GUILayout.Space(MarginSize); // Note: Technically only the last condition is needed. But checking the // other conditions first saves processing time. GUI.enabled = guiEnabled && activeCount == 0 && tdata.GetStateCount(TileBuildState.NotBuilt) < tdata.Width * tdata.Depth; if (GUILayout.Button((needBaking ? "Revert Unbaked" : "Clear All"))) { HandleClear(); } GUI.enabled = guiEnabled && (activeCount != 0); if (GUILayout.Button("Abort Builds")) { Context.AbortAllReqests("User requested."); } //////////////////////////////////////////////////////////////////// GUILayout.Space(ControlUtil.MarginSize); GUI.enabled = guiEnabled; if (OnGUIStandardButtons()) { // Special case. Build was discarded. ControlUtil.EndButtonArea(); return; } /////////////////////////////////////////////////////////////////// GUILayout.Space(MarginSize); GUI.enabled = guiEnabled && hasSelection; EditorGUIUtility.LookLikeControls(100); selection.ZoneSize = EditorGUILayout.IntField("Zone Size", selection.ZoneSize); EditorGUIUtility.LookLikeControls(); GUI.enabled = guiEnabled; //////////////////////////////////////////////////////////////////// GUILayout.Space(MarginSize); GUILayout.Label("Bakeable Tiles: " + bakeableCount); ControlUtil.OnGUIStandardButtons(Context, DebugContext, true); ControlUtil.EndButtonArea(); GUI.enabled = origGUIEnabled; }
private void OnGUISelection(float areaHeight) { Vector3 origin; int xSize = GridCellSize; int ySize = GridCellSize; TileSelection selection = Context.Selection; if (selection.Validate()) { // Draw the tile marker. origin = new Vector3(selection.SelectedX * GridCellSize , areaHeight - selection.SelectedZ * GridCellSize); mCellVerts[0] = origin; mCellVerts[1] = origin; mCellVerts[1].x += GridCellSize; mCellVerts[2] = origin; mCellVerts[2].x += GridCellSize; mCellVerts[2].y -= GridCellSize; mCellVerts[3] = origin; mCellVerts[3].y -= GridCellSize; Handles.DrawSolidRectangleWithOutline(mCellVerts , Color.clear , new Color(0.93f, 0.58f, 0.11f)); // Orange. TileZone zone = selection.Zone; origin = new Vector3(zone.xmin * GridCellSize, areaHeight - zone.zmin * GridCellSize); xSize = zone.Width * GridCellSize; ySize = zone.Depth * GridCellSize; } else { origin = new Vector3(0, areaHeight); TileBuildData tdata = Context.Build.BuildData; xSize = tdata.Width * GridCellSize; ySize = tdata.Depth * GridCellSize; } mCellVerts[0] = origin; mCellVerts[1] = origin; mCellVerts[1].x += xSize; mCellVerts[2] = origin; mCellVerts[2].x += xSize; mCellVerts[2].y -= ySize; mCellVerts[3] = origin; mCellVerts[3].y -= ySize; Handles.DrawSolidRectangleWithOutline(mCellVerts , Color.clear , ControlUtil.SelectionColor); }
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; } }