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)
            {
            }
        }
Exemple #2
0
        public void OnSceneGUITest(SceneView sceneView)
        {
            if (target == null)
            {
#if UNITY_2019_1_OR_NEWER
                SceneView.duringSceneGui -= OnSceneGUITest;
#else
                SceneView.onSceneGUIDelegate -= OnSceneGUITest;
#endif
                return;
            }

            if (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();
            }
        }