From e0e134be9bcbf8cd5499237099715337aed7a3bc Mon Sep 17 00:00:00 2001 From: Jacob-Allebach Date: Mon, 12 Feb 2024 00:13:25 -0500 Subject: [PATCH] Finish part 1 of methods --- thesis.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/thesis.md b/thesis.md index 4a8c4e4..e9f07d3 100644 --- a/thesis.md +++ b/thesis.md @@ -438,6 +438,91 @@ actively mitigated or considered these issues. script, the process of making a room, and adding all of the necessary game objects and data to the map generator itself + To begin the explanation of the plugin's inner workings, it's important to understand +how the plugin functions from the Unity interface. The intention of this project was to make +it so that the user would never need to directly access or edit the code within the scripts, +so the interface within Unity is a crucial part of its success. The core of the plugin is the +two scripts `MapGenerator.cs` and `RoomDataContainer.cs`. When these scripts are attached to +a Game Object as a component, the user will be able to see several variables that they can +adjust to make the generator function as they'd like. + +![A view of the `MapGenerator.cs` script in the inspector when it is attached to a Game Object in Unity](images/MapGeneratorScript.PNG) + + For the Map Generator script, the Game Object it's attached to should be placed within a +scene in order for it to function properly. The first significant variable within the Map +Generator script is the Map Container, which acts as the main object in a scene to hold the +rest of the rooms that get placed down as a result of generation. Each time a new room or +hallway is created during generation, it is set as a child of the Map Container object. This +is meant to keep a scene's hierarchy more organized so that it isn't too messy for the +developer while testing out a scene. Typically, the Map Container object will be the same +object that the Map Generator script is attached to. Another variable that the user will have +control over is the Number of Rooms, which determines how many rooms will be generated by the +map generator before finishing the process. Something that's important to note about the +Number of Rooms is that the larger this value is, the longer the plugin will take to fully +generate a map as there are many more permutations it will be trying out per extra room +added. For a reasonable generation time, it's recommended to limit the Number of Rooms to +20 or less. For the Vertical Hallway Sprite and Horizontal Hallway Sprite variables, the user +just needs to input the two sprites they want to use for each type of hallway respectively. +These are extremely important to provide to the program as they determine how far away rooms +are placed as well as how each one will be connected to each other. The last variable in the +Map Generator script is the list of Rooms. This variable can take as many rooms as the user +would like to provide and will use these to randomly generate the map. Each room that is put +into this Rooms list needs to be a prefab that's been constructed according to the specific +guidelines for room creation. + +![The prefab view of the demonstration tile `TileA`, with its Sprite Renderer and Polygon Collider 2D visible in the inspector view](images/PolygonCollider.PNG) + + The process of room creation requires several components to be attached to a Game Object +in Unity with several of them needing a bit of setup to function properly. The first +component needed for a room is a Sprite Renderer as that will be what visually displays the +room in a scene. Once it is attached, the user should put the corresponding sprite for the +room in the `Sprite` variable slot within the sprite renderer component. The second component +needed is a Polygon Collider 2D, as this will outline the exact bounds of the room to check +for collisions during generation. Once attached, the user will need to open the prefab +view by clicking the `Open` button in the top right of the inspector tab within Unity. This +makes it so that the prefab is visible in the main scene view and can be easily edited. +A specific reason to do this is that Polygon Collider 2D is given an option that says +`Edit Collider` with a button to the right of it. When this button is clicked, the green +outline around the sprite from the Sprite Renderer becomes interactive, allowing new points +to be created and deleted from the Polygon Collider 2D, changing its shape. This collider's +shape then needs to be edited to tightly encapsulate the sprite that was provided in the +previous step. Lining up the collider's shape with the sprite's shape is very important so +that any potential collisions between rooms are properly detected while generating the map. +Once the collider is properly spaced around the sprite, the user must click the button next +to `Edit Collider` again to confirm the placement of the collider's new vertices. The next +component that should be added is the Rigidbody 2D, which is important to have in order for +the Polygon Collider 2D to function properly. The only setting that needs to be changed on +the Rigidbody 2D is the Body Type, which should be switched to Static instead of the default +Dynamic. This will make the room itself unaffected by gravity when it's active in a scene. + +![The prefab view of the demonstration tile `TileA`, with its Sprite Renderer and Polygon Collider 2D visible in the inspector view](images/RoomDataContainerScript.PNG) + + The last component that needs to be added to each room prefab is the Room Data Container +script. While this script doesn't do anything by itself, it serves the very important role +of holding data about the room, specifically the locations that the user wants the room to +be able to connect to other rooms with a hallway. In order for these locations to be +specified, each connecting point must be placed somewhere on the room and put into the +corresponding list within the Room Data Container script. This can be done when in the +prefab view of the room by creating a new empty Game Object as a child of the prefab that +is currently being edited. Then, this empty Game Object should be moved around in the prefab +view or have its X and Y coordinates edited so that it is positioned somewhere at the edge +of the room's sprite where the user wants another room to be connected to it with a hallway. +The placement of these empty Game Objects, which are referred to as connector nodes in the +plugin, is very important that they are precisely on the edge of the room so that it will +connect with the hallway visually and physically in the engine during runtime. Additionally, +after a connector node has been properly positioned, it should be added to the corresponding +list within the Room Data Container script according to which direction the wall it's on is +facing. This means that if the node is positioned on a wall that's facing upward, the node +should be inserted into the Top Nodes list. The same applies for nodes on left, right, and +downward facing walls, which should be placed into the Left Nodes, Right Nodes, and Bottom +Nodes lists respectively. Once all of the desired nodes are placed into their corresponding +lists in the Room Data Container script, that room is complete and its prefab can be placed +into the Rooms list in the Map Generator script. After completing this process for as many +rooms as the user wants to make, the Map Generator is fully ready to run by just hitting the +play button in a scene with the Map Generator object inside it. As long as all the steps were +performed properly, the script will generate a full map with connected rooms according to the +user specifications. + ## Part 2: The Algorithm Behind the Interface * This section is going over exactly what's going on within the scripts and how it's all