ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
CollectableSpotComponent.cs
1using MPewsey.Common.Mathematics;
2using MPewsey.ManiaMap;
3using UnityEngine;
4
6{
11 {
12 [Header("Collectable Spot:")]
13 [SerializeField] private bool _editId;
17 public bool EditId { get => _editId; set => _editId = value; }
18
19 [SerializeField]
20 private int _id = -1;
24 public int Id { get => _id; set => _id = value; }
25
26 [SerializeField]
27 private CollectableGroup _group;
31 public CollectableGroup Group { get => _group; set => _group = value; }
32
33 [SerializeField]
34 private float _weight = 1;
38 public float Weight { get => _weight; set => _weight = Mathf.Max(value, 0); }
39
40 private void OnValidate()
41 {
42 Weight = Weight;
43 }
44
48 public int CollectableId()
49 {
50 if (Room.RoomLayout.Collectables.TryGetValue(Id, out int value))
51 return value;
52
53 return -1;
54 }
55
59 public bool CollectableExists()
60 {
61 return Room.RoomLayout.Collectables.ContainsKey(Id);
62 }
63
67 public bool IsAcquired()
68 {
69 return Room.RoomState.AcquiredCollectables.Contains(Id);
70 }
71
75 public bool CanAcquire()
76 {
77 return CollectableExists() && !IsAcquired();
78 }
79
85 public bool Acquire()
86 {
87 if (CanAcquire())
88 return Room.RoomState.AcquiredCollectables.Add(Id);
89
90 return false;
91 }
92
96 public override void AutoAssign(RoomComponent room)
97 {
98 base.AutoAssign(room);
100 }
101
105 public CollectableSpot GetMMCollectableSpot()
106 {
107 var position = new Vector2DInt(Row, Column);
108 return new CollectableSpot(position, Group.Name, Weight);
109 }
110 }
111}
An object tied to the cell index of a RoomComponent.
Definition: CellChild.cs:10
RoomComponent Room
The containing room.
Definition: CellChild.cs:37
int Column
The column index.
Definition: CellChild.cs:53
A class for creating groups of CollectableResource.
float Weight
The manual draw weight of the collectable spot.
bool CollectableExists()
True if the collectable spot exists.
CollectableGroup Group
The collectable group.
bool CanAcquire()
Returns true if the collectable can be acquired.
override void AutoAssign(RoomComponent room)
Auto assigns elements to the collectable spot.
bool IsAcquired()
True if the collectable spot is already acquired.
CollectableSpot GetMMCollectableSpot()
Returns new generation data for the collectable spot.
bool Acquire()
If the collectable spot exists and has not already been acquired, adds it to the current layout state...
int CollectableId()
The collectable ID. If the collectable spot does not exist in the layout, returns -1.
bool EditId
If true, the ID can be edited in the inspector.
int Id
The unique location ID, relative to the cell.
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 component for creating a room.
RoomState RoomState
The room state.