Moolah60

DynaMazeGen.cs

Aug 23rd, 2018 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. public class DynaMazeGen : MonoBehaviour
  2. {
  3.     private int _mazeSizeX = 8;
  4.     private int _mazeSizeY = 8;
  5.  
  6.     public int MazeSizeX
  7.     {
  8.         get => _mazeSizeX;
  9.         set
  10.         {
  11.             _mazeSizeX = value;
  12.             GenerateMaze();
  13.         }
  14.     }
  15.  
  16.     public int MazeSizeY
  17.     {
  18.         get => _mazeSizeY;
  19.         set
  20.         {
  21.             _mazeSizeY = value;
  22.             GenerateMaze();
  23.         }
  24.     }
  25.  
  26.     public const float GridOffset = 4;
  27.  
  28.     public GameObject Horizontal;
  29.     public GameObject Vertical;
  30.     public GameObject Corner;
  31.     public GameObject Floor;
  32.  
  33.     internal ObjectGrid<GameObject> FloorGrid;
  34.     internal ObjectGrid<GameObject> CornerGrid;
  35.     internal ObjectGrid<GameObject> HorizontalWallGrid;
  36.     internal ObjectGrid<GameObject> VerticalWallGrid;
  37.  
  38.     //Material Definition -- use scriptable objects for material sets ?
  39.     public BoardMaterialSet Theme;
  40.  
  41.     void Start()
  42.     {
  43.         // Floors
  44.         FloorGrid = new ObjectGrid<GameObject>(Floor, transform, MazeSizeX, MazeSizeY, GridOffset, -2, -2,
  45.             SetFloorProperties);
  46.  
  47.         // Corners
  48.         CornerGrid = new ObjectGrid<GameObject>(Corner, transform, MazeSizeX, MazeSizeY, GridOffset, 0, 0,
  49.             SetCornerProperties);
  50.  
  51.         // Horizontal walls
  52.         HorizontalWallGrid = new ObjectGrid<GameObject>(Horizontal, transform, MazeSizeX, MazeSizeY, GridOffset, -2,
  53.             0, SetHorizontalVerticalProperties);
  54.  
  55.         // Vertical walls
  56.         VerticalWallGrid = new ObjectGrid<GameObject>(Vertical, transform, MazeSizeX, MazeSizeY, GridOffset, 0, -2,
  57.             SetHorizontalVerticalProperties);
  58.     }
  59.  
  60.     private void SetCornerProperties(WorldObject<GameObject> worldObject)
  61.     {
  62.         worldObject.Object.GetComponentInChildren<MeshRenderer>().material = Theme.WallMaterial;
  63.         worldObject.Object.tag = Theme.ActiveBoardCornerTag;
  64.     }
  65.  
  66.     private void SetHorizontalVerticalProperties(WorldObject<GameObject> worldObject)
  67.     {
  68.         worldObject.Object.GetComponentInChildren<MeshRenderer>().material = Theme.WallMaterial;
  69.         worldObject.Object.tag = Theme.ActiveBoardWallTag;
  70.     }
  71.  
  72.     private void SetFloorProperties(WorldObject<GameObject> worldObject)
  73.     {
  74.         worldObject.Object.GetComponentInChildren<MeshRenderer>().material = Theme.FloorMaterial;
  75.         worldObject.Object.tag = Theme.ActiveBoardFloorTag;
  76.     }
  77.  
  78.     /// <summary>
  79.     /// Public Call
  80.     /// </summary>
  81.     public void GenerateMaze()
  82.     {
  83.         FloorGrid.UpdateGridSize();
  84.         CornerGrid.UpdateGridSize();
  85.         HorizontalWallGrid.UpdateGridSize();
  86.         VerticalWallGrid.UpdateGridSize();
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment