public override void OnInspectorGUI() { if (labelCaption == null) { initStyle(); } serializedObject.Update(); if (!inited.boolValue) { MethodInfo awakeMethod = mazeEngine.GetType().GetMethod("Awake", BindingFlags.NonPublic | BindingFlags.Instance); awakeMethod.Invoke(mazeEngine, null); } bool errorFound = false; GUI.changed = false; Undo.RecordObject(target, "MazeEngineChnaged"); GUILayout.Space(7); GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { GUILayout.Space(28); GUILayout.Label("Maze Size", labelCaption, GUILayout.Width(94)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUI.DrawTexture(EditorGUILayout.GetControlRect(GUILayout.Width(120), GUILayout.Height(50)), mazeIcon, ScaleMode.ScaleToFit); mazeEngine.setMazeHeight(EditorGUILayout.IntField(mazeEngine.getMazeHeight(), textFieldVC, GUILayout.Height(50), GUILayout.Width(30))); if (mazeEngine.getMazeHeight() < 1) { mazeEngine.setMazeHeight(1); } } GUILayout.EndHorizontal(); mazeEngine.setMazeWidth(EditorGUILayout.IntField(mazeEngine.getMazeWidth(), textFieldHC, GUILayout.Width(97))); if (mazeEngine.getMazeWidth() < 1) { mazeEngine.setMazeWidth(1); } } GUILayout.EndVertical(); GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { GUILayout.Space(28); GUILayout.Label("Piece Size", labelCaption, GUILayout.Width(94)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUI.DrawTexture(EditorGUILayout.GetControlRect(GUILayout.Width(120), GUILayout.Height(50)), pieceIcon, ScaleMode.ScaleToFit); mazeEngine.setMazePieceHeight(EditorGUILayout.FloatField(mazeEngine.getMazePieceHeight(), textFieldVC, GUILayout.Height(50), GUILayout.Width(30))); } GUILayout.EndHorizontal(); mazeEngine.setMazePieceWidth(EditorGUILayout.FloatField(mazeEngine.getMazePieceWidth(), textFieldHC, GUILayout.Width(97))); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); mazeEngine.setMazeScale(EditorGUILayout.FloatField("Maze scale", mazeEngine.getMazeScale(), textFieldHC, GUILayout.Width(200))); GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); mazeEngine.setMazePiecePack((QMazePiecePack)EditorGUILayout.ObjectField("Maze Piece Pack", mazeEngine.getMazePiecePack(), typeof(QMazePiecePack), true)); if (mazeEngine.getMazePiecePack() == null) { EditorGUILayout.HelpBox("Maze Piece Pack is required", MessageType.Warning); errorFound = true; } GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); startFoldout = EditorGUILayout.Foldout(startFoldout, "List Of Start Piece", (!startFoldout && (mazeEngine.getStartPositionList().Count > 0 || mazeEngine.getStartRandomPositionCount() > 0)) ? foldoutBold : EditorStyles.foldout); EditorGUI.indentLevel++; if (startFoldout) { mazeEngine.setStartRandomPosition(EditorGUILayout.Toggle("Random Position", mazeEngine.isStartRandomPosition(), GUILayout.ExpandWidth(true))); if (mazeEngine.isStartRandomPosition()) { mazeEngine.setStartRandomPositionCount(EditorGUILayout.IntField("Count", mazeEngine.getStartRandomPositionCount())); } else { startListFoldout = showVector2IntDirList(mazeEngine.getStartPositionList(), startListFoldout); } } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); finishFoldout = EditorGUILayout.Foldout(finishFoldout, "List Of Finish Piece", (!finishFoldout && (mazeEngine.getFinishPositionList().Count > 0 || mazeEngine.getFinishRandomPositionCount() > 0)) ? foldoutBold : EditorStyles.foldout); EditorGUI.indentLevel++; if (finishFoldout) { mazeEngine.setFinishRandomPosition(EditorGUILayout.Toggle("Random Position", mazeEngine.isFinishRandomPosition(), GUILayout.ExpandWidth(true))); if (mazeEngine.isFinishRandomPosition()) { mazeEngine.setFinishRandomPositionCount(EditorGUILayout.IntField("Count", mazeEngine.getFinishRandomPositionCount())); } else { finishListFoldout = showVector2IntDirList(mazeEngine.getFinishPositionList(), finishListFoldout); } } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); exitFoldout = EditorGUILayout.Foldout(exitFoldout, "List Of Exits", (!exitFoldout && mazeEngine.getExitPositionList().Count > 0 ? foldoutBold : EditorStyles.foldout)); EditorGUI.indentLevel++; if (exitFoldout) { exitListFoldout = showVector2IntDirList(mazeEngine.getExitPositionList(), exitListFoldout); } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); obstacleFoldout = EditorGUILayout.Foldout(obstacleFoldout, "List Of Obstacles", (!obstacleFoldout && mazeEngine.getObstaclePositionList().Count > 0 ? foldoutBold : EditorStyles.foldout)); EditorGUI.indentLevel++; if (obstacleFoldout) { mazeEngine.setObstacleIsNone(EditorGUILayout.Toggle("Use None pieces in areas of obstacles", mazeEngine.isObstacleIsNone(), GUILayout.ExpandWidth(true))); obstacleListFoldout = showVector2IntList(mazeEngine.getObstaclePositionList(), obstacleListFoldout); } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); if (mazeGeneratedEvent == null) { mazeEngine.mazeGeneratedEvent = new QMazeEngine.QMazeGeneratedEvent(); mazeGeneratedEvent = serializedObject.FindProperty("mazeGeneratedEvent"); } if (mazePieceGeneratedEvent == null) { mazeEngine.mazePieceGeneratedEvent = new QMazeEngine.QMazePieceGeneratedEvent(); mazePieceGeneratedEvent = serializedObject.FindProperty("mazePieceGeneratedEvent"); } if (mazeGenerateProgressEvent == null) { mazeEngine.mazeGenerateProgressEvent = new QMazeEngine.QMazeGenerateProgressEvent(); mazeGenerateProgressEvent = serializedObject.FindProperty("mazeGenerateProgressEvent"); } int eventCount = mazeEngine.mazeGeneratedEvent.GetPersistentEventCount() + mazeEngine.mazePieceGeneratedEvent.GetPersistentEventCount() + mazeEngine.mazeGenerateProgressEvent.GetPersistentEventCount(); eventFoldout = EditorGUILayout.Foldout(eventFoldout, "List Of Events", !eventFoldout && eventCount > 0 ? foldoutBold : EditorStyles.foldout); EditorGUI.indentLevel++; if (eventFoldout) { EditorGUILayout.PropertyField(mazeGeneratedEvent); EditorGUILayout.PropertyField(mazePieceGeneratedEvent); EditorGUILayout.PropertyField(mazeGenerateProgressEvent); } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); mazeEngine.setUseSeed(GUILayout.Toggle(mazeEngine.isUseSeed(), "Use seed for generation")); if (mazeEngine.isUseSeed()) { EditorGUI.indentLevel++; mazeEngine.setSeed(EditorGUILayout.IntField("Seed", mazeEngine.getSeed())); EditorGUI.indentLevel--; } GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); mazeEngine.setOnlyPathMode(GUILayout.Toggle(mazeEngine.isOnlyPathMode(), "Generation with the only path")); if (mazeEngine.gameObject.activeInHierarchy) { GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); if (mazeEngine.transform.childCount == 0) { if (errorFound) { GUI.enabled = false; } if (GUILayout.Button("Generate a Maze", GUILayout.ExpandWidth(true))) { mazeEngine.generateMaze(); } GUI.enabled = true; } else { if (GUILayout.Button("Destroy the Maze", GUILayout.ExpandWidth(true))) { mazeEngine.destroyImmediateMazeGeometry(); } } } GUILayout.Space(5); if (GUI.changed) { EditorUtility.SetDirty(mazeEngine); serializedObject.ApplyModifiedProperties(); } }
public override void OnInspectorGUI() { if (labelCaption == null) { initStyle(); } mazeEngineSO.Update(); bool errorFound = false; GUI.changed = false; GUILayout.Space(7); GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { GUILayout.Space(28); GUILayout.Label("Maze Size", labelCaption, GUILayout.Width(94)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUI.DrawTexture(EditorGUILayout.GetControlRect(GUILayout.Width(120), GUILayout.Height(50)), mazeIcon, ScaleMode.ScaleToFit); mazeEngine.mazeHeight = EditorGUILayout.IntField(mazeEngine.mazeHeight, textFieldVC, GUILayout.Height(50), GUILayout.Width(30)); if (mazeEngine.mazeHeight < 1) { mazeEngine.mazeHeight = 1; } } GUILayout.EndHorizontal(); mazeEngine.mazeWidth = EditorGUILayout.IntField(mazeEngine.mazeWidth, textFieldHC, GUILayout.Width(97)); if (mazeEngine.mazeWidth < 1) { mazeEngine.mazeWidth = 1; } } GUILayout.EndVertical(); GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { GUILayout.Space(28); GUILayout.Label("Piece Size", labelCaption, GUILayout.Width(94)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUI.DrawTexture(EditorGUILayout.GetControlRect(GUILayout.Width(120), GUILayout.Height(50)), pieceIcon, ScaleMode.ScaleToFit); mazeEngine.mazePieceHeight = EditorGUILayout.FloatField(mazeEngine.mazePieceHeight, textFieldVC, GUILayout.Height(50), GUILayout.Width(30)); } GUILayout.EndHorizontal(); mazeEngine.mazePieceWidth = EditorGUILayout.FloatField(mazeEngine.mazePieceWidth, textFieldHC, GUILayout.Width(97)); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); mazeEngine.piecePack = (QMazePiecePack)EditorGUILayout.ObjectField("Maze Pieces Pack", mazeEngine.piecePack, typeof(QMazePiecePack), true); if (mazeEngine.piecePack == null) { EditorGUILayout.HelpBox("Maze Pieces Pack is Required", MessageType.Warning); errorFound = true; } mazeEngine.mazeGeometryGenerator = (QMazeGeometryGenerator)EditorGUILayout.ObjectField("Maze Geometry Generator", mazeEngine.mazeGeometryGenerator, typeof(QMazeGeometryGenerator), true); GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); generateStart = GUILayout.Toggle(generateStart, "Generate Start Piece"); EditorGUI.indentLevel++; if (generateStart) { bool generateStartRandomCur = EditorGUILayout.Toggle("Random Position", generateStartRandom, GUILayout.ExpandWidth(true)); if (generateStartRandom != generateStartRandomCur) { generateStartRandom = generateStartRandomCur; mazeEngine.generateStartCount = 0; startPointList.ClearArray(); } if (generateStartRandom) { startPointList.ClearArray(); mazeEngine.startPointList.Clear(); mazeEngine.generateStartCount = EditorGUILayout.IntField("Count", mazeEngine.generateStartCount); } else { generateStartFoldout = showVector2IntList(startPointList, generateStartFoldout); } } else { mazeEngine.generateStartCount = 0; startPointList.ClearArray(); } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); generateFinish = GUILayout.Toggle(generateFinish, "Generate Finish Piece"); EditorGUI.indentLevel++; if (generateFinish) { bool generateFinishRandomCur = EditorGUILayout.Toggle("Random Position", generateFinishRandom, GUILayout.ExpandWidth(true)); if (generateFinishRandom != generateFinishRandomCur) { generateFinishRandom = generateFinishRandomCur; mazeEngine.generateFinishCount = 0; finishPointList.ClearArray(); } if (generateFinishRandom) { finishPointList.ClearArray(); mazeEngine.finishPointList.Clear(); mazeEngine.generateFinishCount = EditorGUILayout.IntField("Count", mazeEngine.generateFinishCount); } else { generateFinishFoldout = showVector2IntList(finishPointList, generateFinishFoldout); } } else { mazeEngine.generateFinishCount = 0; finishPointList.ClearArray(); } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); generateExit = GUILayout.Toggle(generateExit, "Generate Exit"); EditorGUI.indentLevel++; if (generateExit) { generateExitFoldout = showVector2IntList(exitPointList, generateExitFoldout); } else { exitPointList.ClearArray(); } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); generateObstacles = GUILayout.Toggle(generateObstacles, "Obstacles List"); EditorGUI.indentLevel++; if (generateObstacles) { mazeEngine.obstacleIsEmpty = EditorGUILayout.ToggleLeft("Empty Piece in place obstacles", mazeEngine.obstacleIsEmpty, GUILayout.ExpandWidth(true)); generateObstaclesFoldout = showVector2IntList(obstaclePointList, generateObstaclesFoldout); } else { obstaclePointList.ClearArray(); } EditorGUI.indentLevel--; GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); mazeEngine.useSeed = GUILayout.Toggle(mazeEngine.useSeed, "Use seed for generation"); if (mazeEngine.useSeed) { EditorGUI.indentLevel++; mazeEngine.seed = EditorGUILayout.IntField("Seed", mazeEngine.seed); EditorGUI.indentLevel--; } GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); mazeEngine.onlyWay = GUILayout.Toggle(mazeEngine.onlyWay, "Generating with the only path"); if (mazeEngine.gameObject.activeInHierarchy) { GUILayout.Space(5); GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); GUILayout.Space(5); if (mazeEngine.transform.childCount == 0) { if (errorFound) { GUI.enabled = false; } if (GUILayout.Button("Generate a Maze", GUILayout.ExpandWidth(true))) { mazeEngine.generateMaze(true, false); } GUI.enabled = true; } else { if (GUILayout.Button("Destroy the Maze", GUILayout.ExpandWidth(true))) { mazeEngine.clear(); } } } GUILayout.Space(5); mazeEngineSO.ApplyModifiedProperties(); if (GUI.changed) { EditorUtility.SetDirty(mazeEngine); } }