ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
CollectableGroup.cs
1using System.Collections.Generic;
2using UnityEngine;
3
5{
19 [CreateAssetMenu(menuName = "Mania Map/Collectable Group")]
20 public class CollectableGroup : ScriptableObject
21 {
22 [SerializeField]
23 private string _name = "<None>";
27 public string Name { get => _name; set => _name = value; }
28
29 [SerializeField]
30 private List<CollectableGroupEntry> _collectables = new List<CollectableGroupEntry>();
34 public List<CollectableGroupEntry> Collectables { get => _collectables; set => _collectables = value; }
35
39 public List<int> GetCollectableIds()
40 {
41 var result = new List<int>();
42
43 foreach (var entry in Collectables)
44 {
45 for (int i = 0; i < entry.Quantity; i++)
46 {
47 result.Add(entry.Collectable.Id);
48 }
49 }
50
51 return result;
52 }
53
59 public bool AddCollectable(CollectableResource collectable)
60 {
61 if (collectable != null && !ContainsCollectable(collectable))
62 {
63 Collectables.Add(new CollectableGroupEntry(collectable, 0));
64 return true;
65 }
66
67 return false;
68 }
69
75 {
76 foreach (var entry in Collectables)
77 {
78 if (entry.Collectable == collectable)
79 return true;
80 }
81
82 return false;
83 }
84 }
85}
A class for creating groups of CollectableResource.
bool ContainsCollectable(CollectableResource collectable)
Returns true if the group contains the collectable.
List< int > GetCollectableIds()
Returns a list of collectable ID's in the quantity specified by the entries.
List< CollectableGroupEntry > Collectables
A list of collectables.
bool AddCollectable(CollectableResource collectable)
Adds the collectable to the group if it is valid and doesn't already exist. Returns true if it is add...
An object representing a collectable with a unique ID.
A structure containing a collectable and a quantity.