This package allows developers to create engaging, procedurally generated maps similar to those found in the game Slay the Spire in Unity.
The basic generation logic was created by Roican, then modified by me.
- Easily created StS-like maps
- Full control over map layout using
MapConfig - Fully functioning seed system
- Easy use and setup
This repository is installed as a package for Unity.
Open Window>Package Manager.- Click
+. - Select Add Package from git URL.
- Paste
https://github.com/Tramshy/sts-map-generator.git. - Click Add.
NOTE: To do this you need Git installed on your computer.
In order to use this package, you must first create a new script deriving from PointOfInterest. Then you must create a few point of interest (POI) prefabs. A POI is a UI element with an Image component and a component deriving the script PointOfInterest.
You must also create a new MapConfig scriptable object, found under "StS Map Generation/Map Config" of the create asset menu. This new scriptable object will let you fully control map generation using the following settings:
- LayerLayout
- An array of the serializable class
MapLayer. This array allows you to define the length of the map (for example: 5 elements for a length of 5) as well as the layout of each layer on the map.
- An array of the serializable class
- PrefabsForLayerTypes
- An array of the serializable class
POIPrefabs. This array defines what POI's can spawn on the map. The array size matches the availableLayerTypes.
- An array of the serializable class
- ChancePathMiddle
- The chance for a path to spawn in the middle.
- ChancePathSide
- The chance for a path to spawn to the side.
- MultiplicativeSpaceBetweenLines
- The space between path lines.
- MultiplicativeNumberOfMinimumConnections
- The multiplicative minimum allowed connection for a map. This value is multiplied by the map length to determine the minimum number of connections.
- MaxWidth
- The max expected nodes per layer.
- CustomNodeTypes
- An array of string that allows you to easily add custom layer types. Simply add an element and give it a name, you will then find the new custom layer type under PrefabsForLayerTypes.
- AllowPathCrossing
- LayerType
- Determines the nodes that spawn on this layer.
- RandomizePosition
- Multiplier determining how much randomness to add to the position of each node.
- UseRandomRange
- Determines whether or not to use a random range when spawning nodes for this layer.
- _amountOfNodes
- If
UseRandomRangeis false, this value will determine how many nodes to spawn. Set to -1 for total randomness.
- If
- _randomNodeRange
- If
UseRandomRangeis true, this value will determine the random range.
- If
- LayerID
- A string determining which custom layer type for this layer to use. This field is set using a dropdown menu.
- YPaddingFromPreviousLayer
- PointsOfInterestForThisLayerType
- The prefabs to spawn for this layer type.
- _pathPrefab
- The prefab for the path used between nodes on the map. The system can handle both a
LineRendererandUIapproach. This means that if this prefab has aLineRenderercomponent, the path will be created using it, otherwise the system will copy this prefab several times and space out as individual path objects.
- The prefab for the path used between nodes on the map. The system can handle both a
- _xPadding
- The padding between the left and right edges of the map background in pixel units.
- The remaining fields can be ignored.
- _finalLayerHeightPadding
- The extra padding to apply to the final layer of the map in pixel units.
- The remaining fields can be ignored.
Navigate to Tools/StS-Like Generation/Create Basic Setup for Scene in the top menu. This will create a basic setup for you to adjust. You must create a UI EventSystem for this to work. It is also recommended to set the scene's main camera to the Render Camera of the Map Canvas.
This class handles things like hovering over (using the OnHoverEnter and OnHoverExit methods) and selecting a node (using the abstract OnNodeEnter method).
- Awake
- The
Awakemethod is being used by the class to initialize some values. If theAwakemethod is needed, callbase.Awakein the override method, unless you want to handle initialization yourself.
- The
- SetAvailability
- Determines whether or not the node is available to be selected. Simply sets the
isAvailablefield and callsSetAvailabilityVisuals.
- Determines whether or not the node is available to be selected. Simply sets the
- SetAvailabilityVisuals
- By default changes node color based on
isAvailable; however, this can be overridden.
- By default changes node color based on
- OnHoverEnter & OnHoverExit
- Determines behavior when pointer enters and exits the node. By default, it changes scale. Can be overridden.
- OnNodeEnter
- Determines behavior when node is clicked while available. Is
abstractand must be set by the user.
- Determines behavior when node is clicked while available. Is
- rnd
- Field of type
System.Random, created based onsubSeed. Use this for ALL randomness in a node. This will ensure that all random generation is the same on a per-seed basis.
- Field of type
- deactivatedColor & activatedColor
- Colors used for the basic animation if a node is available. Can be completely ignored if the
SetAvailabilitymethod has been overridden and now does not use them.
- Colors used for the basic animation if a node is available. Can be completely ignored if the
- FloorIndex
- The layer the node spawned on.
- subSeed
- The seed created by the master seed during map generation.
- Weight
- A lower value means lower chance for this node to spawn during map generation.
- isAvailable
- A bool describing if a node is available. Set in
SetAvailabilitymethods and used in defaultOnHoverEnterandOnHoverExitimplementation, as well as inOnPointerClickto determine whether or not to let calls pass through. Be sure to set this properly ifSetAvailabilityis overridden.
- A bool describing if a node is available. Set in
- thisImage
This class handles the player's position on the map. This class calls SetAvailability for all relevant nodes. This class is a Singleton
- Awake
- The
Awakemethod is being used by the class to initialize some values and set upSingleton. If theAwakemethod is needed, callbase.Awakein the override method, unless you want to handle initialization yourself.
- The
- OnNewMapGenerated
- Called from
_onMapGeneratedUnityEventfromMapGeneration
- Called from
- UpdateCurrentPOI
- Updates what nodes are selectable by the player by calling
SetAvailabilityon relevant nodes. By default, callsSetAvailabilityof the previous floor to false, before moving up to the next node and callingSetAvailabilityto true for next nodes. By default, callsUpdateCurrentPOIVisualsright after updatingcurrentNode. Can be overridden.
- Updates what nodes are selectable by the player by calling
- UpdateCurrentPOIVisuals
- By default changes the
currentNodesdeactivatedColorto white. This results in a line of white POI's along the selected path. Can be overridden.
- By default changes the
- Instance
- The
Singletoninstance of this class.
- The
- currentNode
- The current POI selected by the player.
This package is licensed under the MIT License. For more information read: LICENSE.