Game.ServiceUpgradeReferencesSystem
Assembly:
Assembly-CSharp (inferred)
Namespace:
Game.Buildings
Type:
public class ServiceUpgradeReferencesSystem
Base:
GameSystemBase
Summary:
System responsible for keeping owner-building "InstalledUpgrade" buffers in sync with service upgrade entities. It watches entities that have ServiceUpgrade + Owner + Object and either Created or Deleted. When a ServiceUpgrade is created, the system adds an InstalledUpgrade entry to the owner's InstalledUpgrade buffer (honoring a building's OptionMask and special-case Extension disabled flag). When a ServiceUpgrade is deleted, the system removes the corresponding InstalledUpgrade entry from the owner's buffer. Work is performed with a Burst-compiled IJobChunk (UpdateUpgradeReferencesJob) for performance and uses BufferLookup/ComponentTypeHandles and EntityTypeHandle for chunk-based processing.
Fields
-
private EntityQuery m_UpgradeQuery
Used to find all entities that represent service upgrades. The query requires ServiceUpgrade, Owner and Object components and matches chunks that contain either Created or Deleted components. -
private TypeHandle __TypeHandle
Holds cached type handles (EntityTypeHandle, ComponentTypeHandles and BufferLookup) that are assigned from the SystemState for use when scheduling the IJobChunk. -
private struct UpdateUpgradeReferencesJob
(nested, private)
The Burst-compiled IJobChunk that processes upgrade chunks. It reads Entity, Owner, Created, Building and Extension components and writes into a BufferLookup. Adds InstalledUpgrade entries on Created and removes them on Deleted. -
private struct TypeHandle
(nested, private)
Helper struct that stores the EntityTypeHandle, ComponentTypeHandle, ComponentTypeHandle , ComponentTypeHandle , ComponentTypeHandle , and BufferLookup . Provides an __AssignHandles method to populate these from a SystemState.
Properties
- This system exposes no public properties.
Constructors
public ServiceUpgradeReferencesSystem()
Default constructor. The system is attributed with [Preserve] on lifecycle methods, and the constructor follows the usual GameSystemBase initialization pattern for runtime.
Methods
-
protected override void OnCreate() : System.Void
Creates and caches the EntityQuery (m_UpgradeQuery) that selects ServiceUpgrade entities with Owner and Object, and that also have either Created or Deleted. Calls RequireForUpdate(m_UpgradeQuery) so the system runs only when matching entities exist. -
protected override void OnUpdate() : System.Void
Builds and schedules the Burst-compiled UpdateUpgradeReferencesJob over m_UpgradeQuery. Uses InternalCompilerInterface helpers to obtain EntityTypeHandle, ComponentTypeHandles, and BufferLookup from the cached __TypeHandle and the system's CheckedStateRef. Sets base.Dependency to the scheduled JobHandle. -
protected override void OnCreateForCompiler() : System.Void
Compiler-time helper that assigns queries and populates type handles via __AssignQueries and __TypeHandle.__AssignHandles (used by Generated/IL2CPP/Compiler systems). -
private void __AssignQueries(ref SystemState state) : System.Void
Generated helper used to create/assign entity queries (the method in this file creates a temporary EntityQueryBuilder and disposes it; real query assignment happens in OnCreate). -
private struct TypeHandle.__AssignHandles(ref SystemState state) : System.Void
Assigns all component/type handles (EntityTypeHandle, ComponentTypeHandles for Owner/Created/Building/Extension, and BufferLookup) from the provided SystemState. -
private struct UpdateUpgradeReferencesJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void
Core chunk-processing method: - Retrieves NativeArray
from the chunk. - Retrieves NativeArray
. - If the chunk has Created:
- Tries to read Building and Extension components for the same indices.
- If Extension exists and has ExtensionFlags.Disabled set, sets the building's OptionMask to 2 (value set in code).
- Adds an InstalledUpgrade (upgrade entity + building.OptionMask) into the owner's InstalledUpgrade buffer using CollectionUtils.TryAddUniqueValue.
- Otherwise (Deleted present):
- Removes the InstalledUpgrade entry (by entity, option mask 0) from the owner's InstalledUpgrade buffer using CollectionUtils.RemoveValue.
Notes:
- The job uses BufferLookup
Usage Example
// Example: creating a ServiceUpgrade entity to be picked up by ServiceUpgradeReferencesSystem
// (simplified—actual component types/fields depend on your mod/game code).
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
// Create an upgrade entity with required components: ServiceUpgrade, Owner, Object and mark Created
Entity upgrade = em.CreateEntity(
typeof(ServiceUpgrade),
typeof(Owner),
typeof(Object),
typeof(Created)
);
// Set the owner to the building entity you want to attach the upgrade to
em.SetComponentData(upgrade, new Owner { m_Owner = buildingEntity });
// After this creation, ServiceUpgradeReferencesSystem.OnUpdate will run (if system is enabled)
// and will add an InstalledUpgrade entry to the owner's InstalledUpgrade buffer.
// To remove the upgrade, add a Deleted component (or remove the entity), and the system will
// remove the corresponding InstalledUpgrade entry from the owner's buffer.
Additional notes: - The system is optimized for chunk processing and uses Burst; do not access UnityEngine-managed objects or non-Burst-compatible types inside the job. - The system expects InstalledUpgrade buffer on the owner entity. Ensure owner entities have that buffer type defined. - The code contains a special-case where, if an Extension component exists and has ExtensionFlags.Disabled set, the building's OptionMask is forcibly set to 2u before adding the InstalledUpgrade. Adjust logic if your mod requires different behavior.