Game.AffiliatedBrandElement
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType, Unity.Entities.IBufferElementData, System.IComparable
Summary:
A DynamicBuffer element type used by the ECS to store a reference to an affiliated brand Entity. The struct is marked with [InternalBufferCapacity(0)], meaning no inline storage is reserved on the entity — the buffer is stored out-of-line as a dynamic buffer. Primarily used to maintain lists of brand Entities associated with another entity (for example, a prefab or company record). The struct implements IComparable
Fields
public Unity.Entities.Entity m_Brand
Holds the Entity reference for the affiliated brand. As a plain Entity value, it contains the index and version encoded by Unity.Entities.Entity. This field is what gets stored per buffer element.
Properties
- None.
This struct exposes no properties; it's a plain value-type buffer element with a single public field.
Constructors
public AffiliatedBrandElement()
No explicit constructors are defined; the default value-type constructor applies. The default (parameterless) constructor will leave m_Brand as default(Entity) (typically Entity.Null).
Methods
public int CompareTo(AffiliatedBrandElement other)
Compares two AffiliatedBrandElement instances by their m_Brand.Index and returns the difference. This allows the elements to be sorted by the underlying Entity index. Notes and caveats:- Only the Entity.Index is used for comparison; Entity.Version is ignored. If an entity index is reused (after destruction and recreation), comparing by index alone may treat different incarnations of an entity as equal or out-of-order.
- The implementation performs integer subtraction (this.m_Brand.Index - other.m_Brand.Index); for large indices this is safe in typical Unity use, but be aware of potential overflow in extreme edge cases.
Usage Example
// Add and populate an AffiliatedBrandElement buffer on an entity
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity target = /* some entity */;
Entity brandEntity = /* brand entity */;
// Ensure entity has a dynamic buffer for affiliated brands
if (!em.HasComponent<AffiliatedBrandElement>(target))
em.AddBuffer<AffiliatedBrandElement>(target);
var buffer = em.GetBuffer<AffiliatedBrandElement>(target);
buffer.Add(new AffiliatedBrandElement { m_Brand = brandEntity });
// Sort the buffer by brand entity index (requires the element's IComparable<T>)
buffer.AsNativeArray().Sort();
Additional notes: - Because the type is annotated [InternalBufferCapacity(0)], the buffer will always be stored out-of-line; there is no inline storage optimization for small counts. - When sorting or comparing, consider whether comparing by Entity.Index alone is appropriate for your use case; if you need to differentiate recycled entities, include the version in comparisons.