Skip to content

Game.UI.InGame.FeatureUISystem

Assembly:
Game (inferred from file path Game\UI\InGame\FeatureUISystem.cs)
Namespace: Game.UI.InGame

Type:
class

Base:
UISystemBase

Summary:
FeatureUISystem is a UI-oriented ECS system that exposes the game's locked feature prefabs to the UI layer via a JSON binding. It queries for feature prefabs that are currently locked and, when appropriate, writes their display data (name and requirements) into a RawValueBinding named "feature" -> "lockedFeatures". The system depends on PrefabSystem and PrefabUISystem to resolve prefab information and to serialize requirements. It updates the binding when feature unlock state changes and on game load so the UI can display current locked features.


Fields

  • private const string kGroup = "feature"
    This constant is used as the group/key for the binding (the code registers a RawValueBinding under the "feature" group).

  • private PrefabSystem m_PrefabSystem
    Reference to the PrefabSystem used to resolve PrefabData -> Prefab objects (specifically FeaturePrefab instances).

  • private PrefabUISystem m_PrefabUISystem
    Reference to PrefabUISystem used to serialize a prefab's requirements into the UI JSON (calls BindPrefabRequirements).

  • private EntityQuery m_UnlockedFeatureQuery
    EntityQuery that selects feature prefabs that have PrefabData, FeatureData and Locked components. This query is used to enumerate locked features to present to the UI.

  • private EntityQuery m_UnlocksQuery
    EntityQuery that selects Unlock components (used to determine if any unlock has occurred so the binding should be updated).

  • private RawValueBinding m_FeaturesBinding
    RawValueBinding instance registered in OnCreate under the "feature" group with the name "lockedFeatures". The binding uses BindLockedFeatures to produce JSON representing locked features.

Properties

  • This class defines no public properties. It uses private fields and overrides lifecycle methods on UISystemBase.

Constructors

  • public FeatureUISystem()
    Default parameterless constructor. Marked with [Preserve] on the lifecycle methods, but the constructor itself is empty and simply allows the ECS to construct the system.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system. Obtains references to PrefabSystem and PrefabUISystem from the world, creates two EntityQueries (one for locked features and one for unlock records), and registers a RawValueBinding named "feature"/"lockedFeatures" that points to BindLockedFeatures. This sets up the JSON binding the UI will consume.

  • protected override void OnUpdate() : System.Void
    Called every frame; checks whether any prefabs of FeatureData have been unlocked via PrefabUtils.HasUnlockedPrefab using m_UnlocksQuery. If so, it calls m_FeaturesBinding.Update() to refresh the bound JSON (causing the UI to re-read locked features).

  • protected override void OnGameLoaded(Context serializationContext) : System.Void
    Called after a game has been loaded. It calls the base implementation and triggers m_FeaturesBinding.Update() so the UI receives the current locked features state immediately after load.

  • private void BindLockedFeatures(IJsonWriter writer) : System.Void
    The binding callback that writes the locked features array into the provided IJsonWriter. Implementation details:

  • Uses m_UnlockedFeatureQuery.ToEntityArray(Allocator.Temp) and ToComponentDataArray(Allocator.Temp) to enumerate matching entities and their PrefabData.
  • Writes a JSON array with one element per locked feature. For each element:
    • Resolves the FeaturePrefab instance via m_PrefabSystem.GetPrefab(prefabData).
    • Writes an object with properties:
    • "name": the prefab's name string.
    • "requirements": delegated to m_PrefabUISystem.BindPrefabRequirements(writer, prefabEntity).
  • Ends the JSON array.
  • Note: the method uses NativeArray<...>(Allocator.Temp) for temporary iteration — ensure these arrays are properly disposed to avoid NativeArray resource issues if modifying this method. In the current source they are created as Allocator.Temp; callers should ensure they are short-lived (same-frame) and disposed or rely on the environment's expectations for Allocator.Temp lifetime.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Typical initialization (as implemented in FeatureUISystem).
    m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
    m_PrefabUISystem = base.World.GetOrCreateSystemManaged<PrefabUISystem>();
    m_UnlockedFeatureQuery = GetEntityQuery(
        ComponentType.ReadOnly<PrefabData>(),
        ComponentType.ReadOnly<FeatureData>(),
        ComponentType.ReadOnly<Locked>());
    m_UnlocksQuery = GetEntityQuery(ComponentType.ReadOnly<Unlock>());
    AddBinding(m_FeaturesBinding = new RawValueBinding("feature", "lockedFeatures", BindLockedFeatures));
}

Additional notes: - The JSON produced under the binding group "feature" with property "lockedFeatures" is an array of objects shaped like: { "name": "", "requirements": { ... } // produced by PrefabUISystem.BindPrefabRequirements } - The system relies on PrefabUtils.HasUnlockedPrefab to detect unlock changes; if integrating custom unlock logic, trigger the binding update (m_FeaturesBinding.Update()) when appropriate. - Be cautious with NativeArray allocation (Allocator.Temp) inside BindLockedFeatures — for robust code, ensure proper disposal or use Allocator.TempJob with guaranteed short lifetime per Unity recommendations.