Game.Prefabs.ActivityMask
Assembly: Assembly-CSharp (typical Unity game assembly)
Namespace: Game.Prefabs
Type: public struct
Base: System.ValueType
Summary:
A lightweight bitmask wrapper used to represent a single ActivityType as a bit in a 32-bit mask. The struct stores a uint where a bit corresponding to (type - 1) is set for non-None ActivityType values; ActivityType.None results in a zero mask. This is useful for compactly encoding activities and combining masks with bitwise operations.
Fields
public uint m_Mask
Holds the bitmask value. If constructed with ActivityType.None this will be 0. For any other ActivityType the mask will have a single bit set at position ((int)type - 1). Be cautious if ActivityType can exceed 32 distinct values — left-shifting beyond 31 is undefined for 32-bit uints. The field is public for direct, efficient access and for use in bitwise operations (AND/OR/XOR).
Properties
- This struct defines no properties. Use the public field m_Mask for reading or modifying the mask.
Constructors
public ActivityMask(ActivityType type)
Initializes the mask for a single ActivityType. If type == ActivityType.None, m_Mask is set to 0. Otherwise the mask is set to (1u << ((int)type - 1)). This encodes the provided activity as a single-bit flag.
Methods
- This struct defines no methods. It is intended to be a small value type manipulated via its m_Mask field and bitwise operations.
Usage Example
// Create a mask for no activity
ActivityMask noneMask = new ActivityMask(ActivityType.None); // m_Mask == 0
// Create a mask for a specific activity
ActivityMask workMask = new ActivityMask(ActivityType.Work); // m_Mask has bit (Work-1) set
// Combine masks (e.g., allow Work or Shopping)
ActivityMask shopMask = new ActivityMask(ActivityType.Shopping);
uint combined = workMask.m_Mask | shopMask.m_Mask;
// Test whether a mask contains a specific activity
bool hasWork = (combined & (1u << ((int)ActivityType.Work - 1))) != 0;
Notes: - Ensure the ActivityType enum values start at 0 or 1 as expected by the subtraction (the constructor assumes ActivityType.None is a distinct value and other activities map to 1..N). - If ActivityType can exceed 32 values, consider using a wider mask (ulong or BitArray) to avoid undefined shifts.