private void DrawOutline(SceneView sceneView) { if (target == null || PrefabStageUtility.GetCurrentPrefabStage() == null) { RemoveOnSceneGUIDelegate(); return; } try { var roomTemplate = (RoomTemplateSettings)target; var outline = roomTemplate.GetOutline(); if (outline == null) { return; } var points = outline.GetPoints(); var grid = roomTemplate.GetComponentInChildren <Grid>(); for (int i = 0; i < points.Count; i++) { GridUtils.DrawRectangleOutline(grid, points[i].ToUnityIntVector3(), points[(i + 1) % points.Count].ToUnityIntVector3(), Color.yellow); } } catch (ArgumentException) { } }
private void HandleSimpleMode() { var doors = target as Doors; var gameObject = doors.transform.gameObject; var grid = gameObject.GetComponentInChildren <Grid>(); try { var polygon = RoomTemplatesLoader.GetPolygonFromRoomTemplate(doors.gameObject); if (polygon == null) { return; } foreach (var line in polygon.GetLines()) { if (line.Length - 2 * doors.DistanceFromCorners < doors.DoorLength - 1) { continue; } var doorLine = line.Shrink(doors.DistanceFromCorners); var from = doorLine.From; var to = doorLine.To; GridUtils.DrawRectangleOutline(grid, from.ToUnityIntVector3(), to.ToUnityIntVector3(), Color.red, new Vector2(0.1f, 0.1f)); } } catch (ArgumentException) { } }
public static void DrawDoorLine(DoorLineGrid2D doorLine, Grid grid, Color color, string label = null) { var line = new OrthogonalLineGrid2D(doorLine.From.ToCustomIntVector2(), doorLine.To.ToCustomIntVector2()); var fromSolid = line.From; var toSolid = line.From; if (line.Length > 0) { toSolid += (doorLine.Length - 1) * line.GetDirectionVector(); } var toDotted = line.To; var doorsCount = line.Length - doorLine.Length + 2; if (doorsCount > 0) { var finalLabel = $"{doorsCount} door{(doorsCount != 1 ? "s" : "")}\nSize {doorLine.Length}"; if (label != null) { finalLabel += $"\n{label}"; } GridUtils.DrawRectangleOutline(grid, fromSolid.ToUnityIntVector3(), toSolid.ToUnityIntVector3(), color, new Vector2(0.1f, 0.1f), label: finalLabel); GridUtils.DrawRectangleOutline(grid, fromSolid.ToUnityIntVector3(), toDotted.ToUnityIntVector3(), color, new Vector2(0.1f, 0.1f), isDotted: true); } else { GridUtils.DrawRectangleOutline(grid, fromSolid.ToUnityIntVector3(), toDotted.ToUnityIntVector3(), color, new Vector2(0.1f, 0.1f), isDotted: true, label: "Too\nsmall"); } }
public void OnSceneGUITest(SceneView sceneView) { if (target == null) { #if UNITY_2019_1_OR_NEWER SceneView.duringSceneGui -= OnSceneGUITest; #else SceneView.onSceneGUIDelegate -= OnSceneGUITest; #endif return; } if (UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() == null) { #if UNITY_2019_1_OR_NEWER SceneView.duringSceneGui -= OnSceneGUITest; #else SceneView.onSceneGUIDelegate -= OnSceneGUITest; #endif return; } try { var roomTemplate = (RoomTemplateSettings)target; var outline = roomTemplate.GetOutline(); if (outline == null) { return; } var points = outline.GetPoints(); var grid = roomTemplate.GetComponentInChildren <Grid>(); for (int i = 0; i < points.Count; i++) { GridUtils.DrawRectangleOutline(grid, points[i].ToUnityIntVector3(), points[(i + 1) % points.Count].ToUnityIntVector3(), Color.yellow); } } catch (ArgumentException) { } }
private void HandleManualMode() { var doors = target as Doors; var grid = doors.gameObject.GetComponentInChildren <Grid>(); // Draw all doors foreach (var door in doors.DoorsList) { GridUtils.DrawRectangleOutline(grid, door.From.RoundToUnityIntVector3(), door.To.RoundToUnityIntVector3(), Color.red, new Vector2(0.1f, 0.1f), true); } switch (currentMode) { case Mode.AddDoors: HandleAddDoors(); break; case Mode.DeleteDoors: HandleDeleteDoors(); break; } }
private void HandleAddDoors() { var doors = target as Doors; var gameObject = doors.transform.gameObject; var e = Event.current; var grid = gameObject.GetComponentInChildren <Grid>(); // Make sure that the current active object in the inspector is not deselected Selection.activeGameObject = gameObject; var controlId = GUIUtility.GetControlID(FocusType.Passive); HandleUtility.AddDefaultControl(controlId); // Compute tile position below the mouse cursor var tilePosition = GetCurrentTilePosition(); switch (e.type) { case EventType.MouseDown: if (e.button == 0) { firstPoint = tilePosition; hasFirstTile = true; hasSecondTile = false; e.Use(); } break; case EventType.MouseUp: if (e.button == 0) { if (hasFirstTile) { hasSecondTile = true; } e.Use(); } break; } // If we have the first tile, we can show how would the door look like if we released the mouse button if (hasFirstTile) { var from = firstPoint; var to = tilePosition; if (from.x != to.x && from.y != to.y) { to.x = from.x; } GridUtils.DrawRectangleOutline(grid, from, to, Color.red, new Vector2(0.1f, 0.1f)); // If we also have the second tile, we can complete the door if (hasSecondTile) { hasFirstTile = false; hasSecondTile = false; var newDoorInfo = new DoorInfoEditor() { From = from, To = to, }; if (!doors.DoorsList.Contains(newDoorInfo)) { Undo.RecordObject(target, "Added door position"); doors.DoorsList.Add(newDoorInfo); EditorUtility.SetDirty(target); } } SceneView.RepaintAll(); } }