Snippets

Tunc Turel Tutorial for Pro-D: Procedural Dungeon Generator for Unity written by tuncOfGrayLake

Created by Tunç Türel
/* 
* This code has been designed and developed by Gray Lake Studios.
* You may only use this code if you’ve acquired the appropriate license.
* To acquire such licenses you may visit www.graylakestudios.com and/or Unity Asset Store
* For all inquiries you may contact contact@graylakestudios.com
* Copyright © 2012 Gray Lake Studios
*/

/* 
* BARE MINIMUM STEP BY STEP GUIDE!
* This is a tutorial example script tha demonstrates the bare minimum coding necessary for making a map with dungeon using Pro-D
* 1 - Open your scene.
* 2 - Add the following: ProDManager, CameraDragAndZoom, Materializer, InputManager and TutorialManager(this script).
* 3 - Put your camera's Projection on Ortographic, set X-Rotation to 90 and set Y-Position  to 10.
* 4 - Press Play.
*/

using UnityEngine;
using System.Collections;
//Remember to add the namespace ProD
using ProD; 

public class TutorialManager : MonoBehaviour 
{
	//Generic variables we can set for a WorldMap
	#region WorldMap
	private WorldMap worldMap;
	public int worldWidth = 1;
	public int worldHeight = 1;
	#endregion WorldMap

	//Generic variables we can set for a Map
	#region Map
	public string theme = "Terminal Theme";
	public int mapWidth = 45;
	public int mapHeight = 45;
	#endregion Map

	//Specific variables we can set in the Dungeon_Generator
	#region Dungeon
	public int dungeon_room_Min_X = 3;
	public int dungeon_room_Max_X = 11;
	public int dungeon_room_Min_Y = 3;
	public int dungeon_room_Max_Y = 11;
	public int dungeon_room_Freq = 10;
	public int dungeon_room_Retry = 6;
	public int dungeon_doorsPerRoom = 1;
	public int dungeon_repeat = 12;
	public bool dungeon_frameMap = false;
	#endregion Dungeon

	//Generate and Materialize a map for us after pressing play.
	void Start()
	{
		GenerateAndMaterialize();
	}
	
	//A button in the inspector to call Generate()
	public bool RE_GenerateAndMaterialize = false;
	void Update()
	{
		if(RE_GenerateAndMaterialize)
		{
			RE_GenerateAndMaterialize = false;
			GenerateAndMaterialize();
		}
	}

	//Set all necessary properties, generate the world and instantiate it.
	private void GenerateAndMaterialize()
	{
		//If there was an existing map, remove the map first.
		Materializer.Instance.UnmaterializeWorldMap();
		//Set the generic  properties of the dungeon map.
		Generator_Dungeon.SetGenericProperties(mapWidth, mapHeight, theme);
		//Set the specific properties of the dungeon map.
		Generator_Dungeon.SetSpecificProperties(
			"Abyss", "Path", "Wall", 
			dungeon_room_Min_X, 
			dungeon_room_Max_X, 
			dungeon_room_Min_Y, 
			dungeon_room_Max_Y, 
			dungeon_room_Freq, 
			dungeon_room_Retry, 
			dungeon_doorsPerRoom, 
			dungeon_repeat, 
			dungeon_frameMap);
		//Set the asset theme the world will use.
		Generator_Generic_World.theme = theme;
		//Generate the world using the dungeon generator.
		worldMap = Generator_Generic_World.Generate("Dungeon", worldWidth, worldHeight, mapWidth, mapHeight);
		//Materialize the world via instantiating its cells.
		Materializer.Instance.MaterializeWorldMap(worldMap);
	}
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.