Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sinbad/UnityMarchingSquares
https://github.com/sinbad/UnityMarchingSquares
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sinbad/UnityMarchingSquares
- Owner: sinbad
- Archived: true
- Created: 2020-09-08T09:28:00.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-08T09:50:51.000Z (over 4 years ago)
- Last Synced: 2024-08-03T05:14:19.709Z (5 months ago)
- Language: C#
- Size: 19.5 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Unity Marching Squares Implementation
I pulled this marching squares implementation out of an old prototype Thrust-a-like game I made for Unity in 2017
in order to share it, since I think it's quite generic and probably useful for others. It was built for Unity 2017
but the code is pretty generic.## Features:
* Given a 2D array of "densities"
* Building a background mesh for the solid areas
* Building line renderers for the edges
* Building EdgeColliders* Procedurally generating density maps where all areas are reachable
## Classes:
* Map: Holder for all the data structures for a single map.
* IMapSource: An interface for providing a 2D array of density data to Map. This can be manually authored or generated.
* MeshGenerator: Builds the background mesh for Map, builds colliders, and communicates with the edge generator
* MapEdgeGfx: Builds line renderers for the edges of the solid areas
* MapGenerator: Procedurally generates a map of density data which is always traversable, is an IMapSource
## How to use
1. Create a GameObject in your level
2. Add the Map and MeshGenerator components to it
3. Add a MeshFilter component (this will hold the mesh)
4. Add an IMapSource component, e.g. a MapGenerator for a procedural map
5. Call Map.RefreshMap
You'll want to tweak materials etc but everything is standard Unity.