Game.Prefabs.UIAvatarColors
Assembly:
Assembly-CSharp
Namespace:
Game.Prefabs
Type:
public class
Base:
PrefabBase
Summary:
UIAvatarColors is a prefab helper used to provide a palette of avatar colors to an entity at prefab initialization time. It exposes an array of Color32 values (m_AvatarColors) that are pushed into a DynamicBuffer
Fields
public UnityEngine.Color32[] m_AvatarColors
Array of colors that will be added to the entity's UIAvatarColorData buffer during LateInitialize. Populate this in the prefab (Inspector) or by code before the prefab is used. Each entry results in one UIAvatarColorData element.
Properties
- This class does not define any public properties.
Constructors
public UIAvatarColors()
Implicit default constructor. Initialization is typically done via Inspector or by overriding prefab lifecycle methods; no custom constructor logic is present in this class.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component types required by this prefab to the provided HashSet. UIAvatarColors adds ComponentType.ReadWrite() so the entity will have the buffer component available when created.
Behavior: - Calls base.GetPrefabComponents(components). - Adds UIAvatarColorData as a read/write component to the components set.
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called late in prefab initialization to populate the entity's UIAvatarColorData buffer with the colors from m_AvatarColors.
Behavior:
- Acquires the DynamicBuffer
Notes: - Assumes the UIAvatarColorData buffer component has been added as part of GetPrefabComponents. - If m_AvatarColors is null or empty, the buffer will remain empty.
Usage Example
// Example: assigning colors in code before using the prefab
var prefab = /* obtain reference to the UIAvatarColors prefab MonoBehaviour */;
prefab.m_AvatarColors = new Color32[]
{
new Color32(255, 0, 0, 255), // red
new Color32(0, 255, 0, 255), // green
new Color32(0, 0, 255, 255) // blue
};
// When the prefab is instantiated and LateInitialize runs, the entity will receive
// a UIAvatarColorData buffer with three entries corresponding to these colors.
// Example: reading the colors from an entity after initialization
var buffer = entityManager.GetBuffer<UIAvatarColorData>(entity);
for (int i = 0; i < buffer.Length; i++)
{
Color32 color = buffer[i].color; // assuming UIAvatarColorData has a 'color' field
// use color in UI code...
}