Example #1
0
        public override void OnGUI(MazeCreationWorkflowBackEnd backend)
        {
            if (backend.selectedMaze == null && GUILayout.Button("New"))
            {
                CreateNewPlainMaze(backend);
            }

            if (backend.selectedMaze == null)
            {
                return;
            }

            var maze = backend.selectedMaze;

            maze.name = EditorGUILayout.TextField("Name", maze.name);

            maze.MazeWidthInMeter = EditorGUILayout.FloatField("Width", maze.MazeWidthInMeter);

            maze.MazeLengthInMeter = EditorGUILayout.FloatField("Length", maze.MazeLengthInMeter);

            maze.RoomDimension = EditorGUILayout.Vector3Field("Room WxHxL (m):", maze.RoomDimension, null);

            var gridSize = beMobileMaze.CalcGridSize(maze);

            MazeEditorUtil.RebuildGrid(maze);

            EditorGUILayout.Vector2Field("Grid Cols(x) Rows(y):", gridSize, null);

            if (GUILayout.Button("Create"))
            {
                backend.selectedMaze = maze;
            }
        }
Example #2
0
        public override void OnGUI(MazeCreationWorkflowBackEnd backend)
        {
            unitPrefab = EditorGUILayout.ObjectField("Unit Prefab:", unitPrefab, typeof(GameObject), false) as GameObject;

            if (unitPrefab != null)
            {
                var unit = unitPrefab.GetComponent <MazeUnit>();

                if (unit != null)
                {
                    if (unit.Dimension != backend.selectedMaze.RoomDimension)
                    {
                        EditorUtility.DisplayDialog("Wrong Size!", "The selected Prefab has not the correct dimensions!", "Ok");
                        unitPrefab = null;
                    }
                    else
                    {
                        unitDimensions = unit.Dimension;
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Wrong Selection!", "The Selected Prefab is not a MazeUnit!", "Reset");
                    unitPrefab = null;
                }
            }

            unitDimensions = EditorGUILayout.Vector3Field("Cell Size: ", unitDimensions);

            if (unitPrefab == null && GUILayout.Button("Create new Unit"))
            {
                UnitCreator.OpenUnitCreator(backend.selectedMaze.RoomDimension, c => {
                    // get the created Unit prefab automaticaly back to the Editor Window
                    c.onUnitPrefabCreated += prefab =>
                    {
                        var mazeUnit = prefab.GetComponent <MazeUnit>();

                        if (mazeUnit != null)
                        {
                            unitPrefab = prefab;
                        }
                    };
                });
            }

            EditorGUILayout.Space();

            if (unitPrefab == null)
            {
                removeMode = GUILayout.Toggle(removeMode || Event.current.shift, "Remove", "Button");
                return;
            }

            EditorGUILayout.BeginHorizontal();

            addMode    = GUILayout.Toggle(!removeMode, "Add", "Button");
            removeMode = GUILayout.Toggle(!addMode || Event.current.shift, "Remove", "Button");

            EditorGUILayout.EndHorizontal();
        }
Example #3
0
        public override void OnSceneViewGUI(SceneView view, MazeCreationWorkflowBackEnd backend, EditorViewGridVisualisation visual)
        {
            base.OnSceneViewGUI(view, backend, visual);

            if (backend.selectedMaze != null)
            {
                EditorVisualUtils.HandlesDrawGrid(backend.selectedMaze);
            }
        }
Example #4
0
        public override void OnSceneViewGUI(SceneView view, MazeCreationWorkflowBackEnd backend, EditorViewGridVisualisation visual)
        {
            if (pathToEdit == null)
            {
                return;
            }

            tilePositionIsValid = CheckIfTileIsValidPathElement(backend, visual);
        }
Example #5
0
        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;
            }
        }
Example #6
0
        private void AddANewUnit(beMobileMaze maze, Vector2 pos, MazeCreationWorkflowBackEnd backend)
        {
            var unitHost = PrefabUtility.InstantiatePrefab(unitPrefab) as GameObject;

            PrefabUtility.DisconnectPrefabInstance(unitHost);

            var unit = MazeEditorUtil.InitializeUnit(maze, pos, unitFloorOffset, unitHost);

            maze.Grid[(int)pos.x, (int)pos.y] = unit;

            maze.Units.Add(unit);
        }
Example #7
0
        private bool CheckIfTileIsValidPathElement(MazeCreationWorkflowBackEnd backend, EditorViewGridVisualisation visual)
        {
            var tilePosition = visual.currentTilePosition;

            if (!backend.selectedMaze.Units.Any((u) => u.GridID.Equals(tilePosition)))
            {
                return(false);
            }

            if (pathToEdit.PathAsLinkedList != null && pathToEdit.PathAsLinkedList.Count == 0)
            {
                return(true);
            }

            var lastElement = pathToEdit.PathAsLinkedList.Last;

            var gridIdOfLastElement = lastElement.Value.Unit.GridID;

            if (tilePosition == gridIdOfLastElement)
            {
                return(false);
            }

            if (lastElement.Previous != null)
            {
                var gridIdOfPreviousElement = lastElement.Previous.Value.Unit.GridID;

                if (gridIdOfPreviousElement == tilePosition)
                {
                    return(false);
                }
            }

            var deltaBetweenLastAndCurrent = tilePosition - gridIdOfLastElement;
            var absDelta = deltaBetweenLastAndCurrent.SqrMagnitude();

            if (absDelta > 1)
            {
                return(false);
            }

            return(true);
        }
Example #8
0
        public override void OnGUI(MazeCreationWorkflowBackEnd backend)
        {
            if (!CurrentSelection.Any())
            {
                EditorGUILayout.HelpBox("Select Units first", MessageType.None);
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Remove Walls"))
            {
                TryConnectingCurrentSelection();
                backend.indicateChange();
            }

            if (GUILayout.Button("Add Walls"))
            {
                TryDisconnectingCurrentSelection();
                backend.indicateChange();
            }

            EditorGUILayout.EndHorizontal();
        }
Example #9
0
        /// <summary>
        /// Erases a block at the pre-calculated mouse hit position
        /// </summary>
        private void RemoveAUnit(beMobileMaze maze, Vector2 pos, MazeCreationWorkflowBackEnd backend)
        {
            Debug.Log("Remove call...");

            var allÚnits = maze.GetComponentsInChildren <MazeUnit>();

            var selected = allÚnits.Where(u => u.GridID == pos);

            var unitHost = selected.First();

            if (!unitHost)
            {
                Debug.Log("Nothing to erase!");
                return;
            }

            // if a game object was found with the same assetName and it is a child we just destroy it immediately
            if (unitHost != null && unitHost.transform.parent == maze.transform)
            {
                maze.Units.Remove(unitHost);
                maze.Grid[(int)pos.x, (int)pos.y] = null;
                Editor.DestroyImmediate(unitHost.gameObject);
            }
        }
Example #10
0
 internal void CreateNewPlainMaze(MazeCreationWorkflowBackEnd backend)
 {
     backend.selectedMaze = new GameObject().AddComponent <beMobileMaze>();
     backend.selectedMaze.gameObject.AddComponent <PathController>();
 }
Example #11
0
 public override void OnSceneViewGUI(SceneView view, MazeCreationWorkflowBackEnd backend, EditorViewGridVisualisation visual)
 {
     base.OnSceneViewGUI(view, backend, visual);
 }