Skip to content

Game.UI.InGame.AvatarsUISystem

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: class

Base: UISystemBase

Summary:
AvatarsUISystem is a UI system responsible for producing avatar data used by the in-game UI "avatars" group. It binds a map of avatar entries (picture, name, color) to the UI via a RawMapBinding and resolves avatar pictures from prefabs (including special handling for companies, chirper accounts, and brand prefabs). It also selects avatar colors from a singleton UIAvatarColorData buffer, using a per-entity RandomLocalizationIndex if available.


Fields

  • private const string kGroup = "avatars"
    Used as the UI group name for the avatars binding.

  • private const int kIconSize = 32
    Icon size used when constructing a thumbnail URL for BrandPrefab (width/height query parameters).

  • private PrefabSystem m_PrefabSystem
    Cached reference to the PrefabSystem (retrieved in OnCreate). Used to resolve prefabs from PrefabData components.

  • private NameSystem m_NameSystem
    Cached reference to the NameSystem (retrieved in OnCreate). Used to bind/resolve entity names when writing avatar entries.

  • private EntityQuery m_ColorsQuery
    EntityQuery used to access the UIAvatarColorData singleton buffer which contains available avatar colors.

  • [UsedImplicitly] private RawMapBinding<Entity> m_AvatarsBinding
    The RawMapBinding that writes avatar map entries to the UI. Registered in OnCreate with the key "avatars" and internal map name "avatarsMap". Marked UsedImplicitly since it's stored for lifecycle management.

Properties

  • None (no public properties exposed by this system)

Constructors

  • public AvatarsUISystem()
    Default constructor. The system performs initialization in OnCreate.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system: obtains PrefabSystem and NameSystem instances from the World, creates an EntityQuery for UIAvatarColorData, and registers the RawMapBinding (m_AvatarsBinding) with the UI map writer by providing BindAvatar as the writer callback.

  • protected override void OnUpdate() : System.Void
    Empty override. The binding supplies data to the UI; the system does not perform per-frame logic itself here.

  • private void BindAvatar(IJsonWriter writer, Entity entity) : System.Void
    Writes a single avatar entry to the JSON writer. Produces an object with:

  • "picture": string or null (from GetPicture)
  • "name": written via NameSystem.BindName for the entity
  • "color": Color32 value chosen via GetColor This is the callback used by m_AvatarsBinding to populate each avatar entry.

  • private Color32 GetColor(Entity entity) : Color32
    Reads the singleton DynamicBuffer via m_ColorsQuery and selects a color. Selection logic:

  • Obtains a random index via GetRandomIndex(entity).
  • If the random index is negative, returns the first color in the buffer.
  • Otherwise returns buffer[randomIndex % buffer.Length].m_Color. If the buffer is present and has entries, it uses it to pick an avatar color (wrap-around via modulus).

  • private string GetPicture(Entity entity) : string (nullable)
    Resolves an avatar picture path for an entity:

  • If the entity has a CompanyData component, it uses the company's brand entity for picture lookup.
  • If the entity (or brand) has a PrefabData component and the PrefabSystem can resolve the PrefabBase:
    • Attempts ImageSystem.GetIcon(prefab) and returns it if non-null.
    • If prefab is a ChirperAccount and has m_InfoView.m_IconPath, returns that path.
    • If prefab is a BrandPrefab, returns a thumbnail URL augmented with width/height query parameters (using kIconSize).
  • Returns null if no picture can be resolved.

  • private int GetRandomIndex(Entity entity) : int
    Attempts to read a read-only DynamicBuffer from the entity. If present and non-empty returns buffer[0].m_Index; otherwise returns 0. This index is used to select a color from the UIAvatarColorData buffer.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
    m_NameSystem = base.World.GetOrCreateSystemManaged<NameSystem>();
    m_ColorsQuery = GetEntityQuery(ComponentType.ReadOnly<UIAvatarColorData>());
    AddBinding(m_AvatarsBinding = new RawMapBinding<Entity>("avatars", "avatarsMap", BindAvatar));
}

Additional notes: - Dependencies: PrefabSystem, NameSystem, ImageSystem, CompanyData, PrefabData, UIAvatarColorData, RandomLocalizationIndex, BrandPrefab, ChirperAccount. - The binding writes entries under the UI group "avatars" with internal map name "avatarsMap"; the UI side needs to consume that map to render the avatar list. - OnUpdate does no processing — all runtime behavior is handled when the UI reads the bound map via the binding callback.