ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
TemplateGroupEntry.cs
1using MPewsey.ManiaMap;
2using System.Collections.Generic;
3using UnityEngine;
4
6{
10 [System.Serializable]
11 public class TemplateGroupEntry
12 {
13 [SerializeField]
14 private RoomTemplateResource _template;
18 public RoomTemplateResource Template { get => _template; set => _template = value; }
19
20 [SerializeField]
21 private int _minQuantity;
25 public int MinQuantity
26 {
27 get => _minQuantity;
28 set => _minQuantity = Mathf.Max(value, 0);
29 }
30
31 [SerializeField]
32 private int _maxQuantity = int.MaxValue;
36 public int MaxQuantity
37 {
38 get => _maxQuantity;
39 set => _maxQuantity = Mathf.Max(value, 0);
40 }
41
42 public void OnValidate()
43 {
46 }
47
53 {
54 Template = template;
55 }
56
63 public TemplateGroupEntry(RoomTemplateResource template, int minQuantity, int maxQuantity)
64 {
65 Template = template;
66 MinQuantity = minQuantity;
67 MaxQuantity = maxQuantity;
68 }
69
73 public TemplateGroupsEntry GetMMTemplateGroupsEntry(Dictionary<RoomTemplateResource, RoomTemplate> templateCache)
74 {
75 if (!templateCache.TryGetValue(Template, out var template))
76 {
77 template = Template.GetMMRoomTemplate();
78 templateCache.Add(Template, template);
79 }
80
81 return new TemplateGroupsEntry(template, MinQuantity, MaxQuantity);
82 }
83 }
84}
A container for storing a serialized room template.
RoomTemplate GetMMRoomTemplate()
Creates a new Mania Map room template from the serialized text and returns it.
A TemplateGroup entry.
int MaxQuantity
The maximum number of times this entry is used in a layout.
TemplateGroupEntry(RoomTemplateResource template, int minQuantity, int maxQuantity)
Initializes a new entry with quantity constraints.
RoomTemplateResource Template
The room template.
TemplateGroupsEntry GetMMTemplateGroupsEntry(Dictionary< RoomTemplateResource, RoomTemplate > templateCache)
Returns a new generation template group entry.
int MinQuantity
The minimum number of times this entry is used in a layout.
TemplateGroupEntry(RoomTemplateResource template)
Initializes a new entry with no quantity constraints.