Game.UI.UIObjectInfo
Assembly:
Game
Namespace:
Game.UI
Type:
struct (readonly) — implements System.IComparable
Base:
System.ValueType
Summary:
A lightweight readonly value type that represents a UI-related entity together with its PrefabData and a priority used for sorting. UIObjectInfo is primarily used to collect UI entities (or prefabs) and produce sorted NativeList
Fields
- None
This struct exposes data via readonly properties; there are no explicit instance fields declared in the source.
Properties
-
public Entity entity { get; }
Represents the ECS Entity for the UI object (or prefab) referenced by this UIObjectInfo. -
public PrefabData prefabData { get; }
The PrefabData component for the entity/prefab. May be default if not provided by the constructor. -
public int priority { get; }
Priority value used when sorting UI objects. Lower values come first (CompareTo uses int.CompareTo).
Constructors
-
public UIObjectInfo(Entity entity, int priority)
Creates an instance with the given entity and priority. prefabData will be default(PrefabData). -
public UIObjectInfo(Entity entity, PrefabData prefabData, int priority)
Creates an instance with the given entity, explicit PrefabData and priority.
Methods
-
public int CompareTo(UIObjectInfo other)
Implements IComparable. Compares this.priority to other.priority using int.CompareTo so that NativeList .Sort() orders items by ascending priority. -
public static NativeList<UIObjectInfo> GetSortedObjects(EntityQuery query, Allocator allocator)
Builds a NativeListfrom the entities matched by the provided EntityQuery. It reads Entity, PrefabData and UIObjectData (to obtain m_Priority) from the query result arrays, adds UIObjectInfo entries, sorts the list by priority, and returns it. Temporary NativeArrays used inside are disposed automatically via using blocks. The returned NativeList is allocated with the provided Allocator and must be disposed by the caller. -
public static NativeList<UIObjectInfo> GetSortedObjects(EntityManager entityManager, EntityQuery query, Allocator allocator)
Similar to the previous overload but uses an EntityManager to try to read UIObjectData per entity (falling back to priority 0 if missing). It reads PrefabData via the query's component array and constructs then sorts the resulting NativeList. -
public static NativeList<UIObjectInfo> GetSortedObjects(EntityManager entityManager, NativeList<Entity> entities, Allocator allocator)
Builds a sorted NativeList from a provided NativeList. For each entity it obtains PrefabData via entityManager.GetComponentData (entity) and attempts to read UIObjectData to get the priority (0 if absent). Returns a sorted NativeList allocated with the given Allocator. -
public static NativeList<UIObjectInfo> GetObjects(EntityManager entityManager, DynamicBuffer<UIGroupElement> elements, Allocator allocator)
Creates a NativeListfrom a DynamicBuffer without sorting. For each element it reads the prefab Entity and its PrefabData, attempts to read UIObjectData for priority (0 if absent), and adds entries in the same order as elements. The caller must dispose the returned NativeList. -
public static NativeList<UIObjectInfo> GetSortedObjects(EntityManager entityManager, DynamicBuffer<UIGroupElement> elements, Allocator allocator)
Same as GetObjects but sorts the resulting list by priority before returning.
Notes on memory management:
- All Get*/GetSortedObjects methods return a NativeList
Usage Example
// Example: get a sorted list of UI objects from an EntityQuery and iterate them.
// Remember to dispose the returned NativeList when done.
NativeList<UIObjectInfo> sorted = UIObjectInfo.GetSortedObjects(myEntityQuery, Allocator.Temp);
// Use the sorted list
for (int i = 0; i < sorted.Length; i++)
{
UIObjectInfo info = sorted[i];
Entity e = info.entity;
PrefabData prefab = info.prefabData;
int priority = info.priority;
// ... do work ...
}
// Dispose when finished
sorted.Dispose();