public override void OnInspectorGUI() { instance = target as PathInMaze; if (instance != null) { var maze = instance.GetComponent <beMobileMaze>(); if (maze == null) { throw new MissingComponentException(string.Format("The Path Controller should be attached to a {0} instance", typeof(beMobileMaze).Name)); } } EditorGUILayout.BeginVertical(); showElements = EditorGUILayout.Foldout(showElements, "Show Elements"); if (showElements) { RenderElements(); } if (GUILayout.Button("Reverse Path")) { instance.InvertPath(); } EditorGUILayout.Separator(); EditorGUILayout.EndVertical(); }
public override void OnGUI(MazeCreationWorkflowBackEnd backend) { var selectedMaze = backend.selectedMaze; var pathController = selectedMaze.GetComponent <PathController>(); if (pathController == null) { pathController = selectedMaze.gameObject.AddComponent <PathController>(); } var pathIds = pathController.GetAvailablePathIDs(); if (pathIds.Any()) { var options = pathIds.Select(i => string.Format("{0} - Path", i)).ToArray(); selected = EditorGUILayout.Popup(selected, options); pathToEdit = pathController.Paths.First(p => p.ID == pathIds[selected]); pathToEdit = EditorGUILayout.ObjectField("Edit: ", pathToEdit, typeof(PathInMaze), allowSceneObjects: true) as PathInMaze; pathToEdit.ID = EditorGUILayout.IntField("ID: ", pathToEdit.ID); } if (GUILayout.Button("Add new Path")) { var newPath = selectedMaze.gameObject.AddComponent <PathInMaze>(); if (pathController.Paths.Count() > 0) { var availableIds = pathController.GetAvailablePathIDs(); newPath.ID = availableIds.Max() + 1; } else { newPath.ID = 0; } pathController.Paths.Add(newPath); } if (backend.selectedMazeHasAPrefab() && GUILayout.Button("Save Path")) { backend.indicateChange(); } if (GUILayout.Button("Remove Selected Path")) { pathController.Paths.Remove(pathToEdit); Editor.DestroyImmediate(pathToEdit); pathToEdit = null; selected = 0; } }
private StringBuilder AppendPathWithMatrix(beMobileMaze maze, PathInMaze path) { StringBuilder pathAsTextMatrix = new StringBuilder(); var pathID = string.Format("Path: {0} matlab path matrix:\t", path.ID); var pathElements = path.PathAsLinkedList.ToList(); pathAsTextMatrix.Append(pathID); pathAsTextMatrix.Append(" [ "); var grid = new MazeGridTraversal(maze); grid.travers( s => { string content = "0"; pathAsTextMatrix.Append(content); if (s.ColumnsLeft > 0) { pathAsTextMatrix.Append(", "); } if (s.ColumnsLeft == 0) { pathAsTextMatrix.Append("; "); } }, (u, s) => { var currentUnitIsPathElement = pathElements.Any( e => e.Unit.GridID == new Vector2(s.Column, s.Row)); if (currentUnitIsPathElement) { pathAsTextMatrix.Append("2"); } else { pathAsTextMatrix.Append("1"); } if (s.ColumnsLeft > 0) { pathAsTextMatrix.Append(", "); } if (s.ColumnsLeft == 0) { pathAsTextMatrix.Append("; "); } } ); #region //for (int y_i = 0; y_i < maze.Rows; y_i++) //{ // StringBuilder rowAsLine = new StringBuilder(); // for (int x_i = 0; x_i < maze.Columns; x_i++) // { // var currentUnitIsPathElement = pathElements.Any(e => e.Unit.GridID == new UnityEngine.Vector2(x_i, y_i)); // if (maze[x_i, y_i] == null) // { // rowAsLine.Append("0"); // } // else if (currentUnitIsPathElement) // { // rowAsLine.Append("2"); // } // else // { // rowAsLine.Append("1"); // } // if (x_i != maze.Columns - 1) // rowAsLine.Append(", "); // } // if (y_i != maze.Rows - 1) // { // rowAsLine.Append("; "); // } // pathAsTextMatrix.Append(rowAsLine.ToString()); //} #endregion original pathAsTextMatrix.Append(" ] "); return(pathAsTextMatrix); }
/// <summary> /// TODO: Local position must be used when matrix has been set to maze.transform.localToWorldMatrix /// </summary> /// <param name="maze"></param> /// <param name="instance"></param> /// <param name="drawingOffset"></param> /// <param name="color"></param> public static void RenderPathElements(beMobileMaze maze, PathInMaze instance, Vector3 drawingOffset, Color color) { var tempGizmoColor = Gizmos.color; if (instance.PathAsLinkedList != null && instance.PathAsLinkedList.Count > 0) { var start = instance.PathAsLinkedList.First.Value.Unit.transform; Gizmos.color = color; Gizmos.DrawCube(start.localPosition + drawingOffset, Vector3.one * 0.3f); var iterator = instance.PathAsLinkedList.GetEnumerator(); MazeUnit last = null; while (iterator.MoveNext()) { if (last == null) { last = iterator.Current.Unit; continue; } if (last == null || iterator.Current.Unit == null) { last = iterator.Current.Unit; continue; } Gizmos.DrawLine(last.transform.localPosition + drawingOffset, iterator.Current.Unit.transform.localPosition + drawingOffset); last = iterator.Current.Unit; } var lastElement = instance.PathAsLinkedList.Last.Value.Unit; var endTransform = lastElement.transform; var coneRotation = start.localRotation; switch (lastElement.WaysOpen) { case OpenDirections.None: break; case OpenDirections.North: coneRotation.SetLookRotation(-endTransform.forward); break; case OpenDirections.South: coneRotation.SetLookRotation(endTransform.forward); break; case OpenDirections.East: coneRotation.SetLookRotation(-endTransform.right); break; case OpenDirections.West: coneRotation.SetLookRotation(endTransform.right); break; case OpenDirections.All: break; default: break; } Gizmos.DrawSphere(endTransform.localPosition + drawingOffset, 0.15f); Gizmos.color = tempGizmoColor; } }