ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
RoomTemplateResource.cs
1using MPewsey.Common.Serialization;
2using MPewsey.ManiaMap;
4using UnityEngine;
5using UnityEngine.AddressableAssets;
6
8{
12 public class RoomTemplateResource : ScriptableObject
13 {
14 [SerializeField]
15 private bool _editId;
19 public bool EditId { get => _editId; set => _editId = value; }
20
21 [SerializeField]
22 private int _id = -1;
26 public int Id { get => _id; set => _id = value; }
27
28 [SerializeField]
29 private string _name = "<None>";
33 public string Name { get => _name; set => _name = value; }
34
35 [SerializeField]
36 private string _prefabGuid;
40 public string PrefabGuid { get => _prefabGuid; private set => _prefabGuid = value; }
41
42 [SerializeField]
43 private string _prefabPath;
47 public string PrefabPath { get => _prefabPath; private set => _prefabPath = value; }
48
49 [SerializeField]
50 [TextArea(3, int.MaxValue)]
51 private string _serializedText;
55 public string SerializedText { get => _serializedText; private set => _serializedText = value; }
56
57 private void OnValidate()
58 {
60 }
61
68 public void Initialize(RoomTemplate template, string prefabGuid, string prefabPath)
69 {
70 SerializedText = JsonSerialization.GetJsonString(template, new JsonWriterSettings());
71 PrefabGuid = prefabGuid;
72 PrefabPath = prefabPath;
73 }
74
79 public RoomTemplate GetMMRoomTemplate()
80 {
81 if (string.IsNullOrWhiteSpace(SerializedText))
82 throw new RoomTemplateNotInitializedException($"Serialized text has not been assigned: {this}");
83
84 return JsonSerialization.LoadJsonString<RoomTemplate>(SerializedText);
85 }
86
90 public AssetReferenceGameObject GetAssetReference()
91 {
92 return new AssetReferenceGameObject(PrefabGuid);
93 }
94 }
95}
Contains methods for creating random ID's.
Definition: Rand.cs:9
static int AutoAssignId(int id)
If the specified ID is greater than zero, returns the ID. Otherwise, returns a random positive intege...
Definition: Rand.cs:15
A container for storing a serialized room template.
string SerializedText
The serialized text for the template.
AssetReferenceGameObject GetAssetReference()
Returns the asset reference based on the assigned prefab GUID.
RoomTemplate GetMMRoomTemplate()
Creates a new Mania Map room template from the serialized text and returns it.
void Initialize(RoomTemplate template, string prefabGuid, string prefabPath)
Sets the properties for the room template.
bool EditId
If true, the ID can be edited in the inspector.
string PrefabPath
The path of the prefab from the project root when the template was last updated.