Game.Notifications.IconElement
Assembly: Game
Namespace: Game.Notifications
Type: struct
Base: System.ValueType
Summary:
IconElement is a lightweight DOTS buffer element that holds a reference to a Unity.Entities.Entity used as a notification icon. The struct is annotated with [InternalBufferCapacity(4)], allowing up to 4 elements to be stored inline in the chunk before additional memory is allocated. It implements IBufferElementData so it can be used with DynamicBuffer
Fields
-
public Entity m_Icon
Holds the Entity that represents the icon. This is the primary payload of the buffer element and is used to reference icon entities from notification-related entities or systems. -
(Struct attribute)
[InternalBufferCapacity(4)]
Although not a field, this attribute applies to the buffer element type and configures an internal capacity of 4 elements per-chunk before heap allocation is required.
Properties
This type does not declare any properties. Access the stored Entity via the public field m_Icon.
Constructors
public IconElement(Entity icon)
Initializes a new IconElement with the provided Entity reference.
Note: As a struct, IconElement also has the implicit parameterless default constructor (m_Icon will be default(Entity)).
Methods
-
public bool Equals(IconElement other)
Implements IEquatable. Returns true when the contained m_Icon equals the other.m_Icon. -
public override int GetHashCode()
Returns the hash code of the contained Entity (m_Icon.GetHashCode()).
Remarks: Equals(object) is not overridden in this type; equality comparisons should use the IEquatable implementation or compare the m_Icon fields directly.
Usage Example
// Example usage inside a System or initialization code
// Assumes `entityManager` and relevant Entities world are available.
Entity notificationEntity = entityManager.CreateEntity();
// Add a DynamicBuffer<IconElement> to hold icon entities
var buffer = entityManager.AddBuffer<Game.Notifications.IconElement>(notificationEntity);
// Suppose you have one or more icon entities
Entity iconEntity1 = /* created or obtained elsewhere */;
Entity iconEntity2 = /* created or obtained elsewhere */;
// Add icons to the buffer
buffer.Add(new Game.Notifications.IconElement(iconEntity1));
buffer.Add(new Game.Notifications.IconElement(iconEntity2));
// Iterate the buffer to access icon entities
for (int i = 0; i < buffer.Length; i++)
{
Entity icon = buffer[i].m_Icon;
// Use icon (e.g., lookup sprite, update state, etc.)
}
Additional notes:
- Use DynamicBuffer