Game.NativeSystem
Assembly:
Namespace: Game.Common
Type: class
Base: GameSystemBase
Summary:
A Unity Entities system used by the game to add or remove the Native marker component on certain game entities depending on the current load purpose. On creation it acquires the LoadGameSystem and builds two EntityQuery objects: one that finds entities of interest (Edge, Game.Net.Node, Object, Area) that do not already have a Native component, and one that selects entities that do have the Native component. During update it inspects the load context (via LoadGameSystem.context.purpose) and:
- when Purpose.NewGame: adds the Native component to the matching entities,
- when Purpose.LoadMap: removes the Native component from entities that have it.
Fields
-
private LoadGameSystem m_LoadGameSystem
Reference to the game's LoadGameSystem retrieved from the World. Used to inspect load context (context.purpose) so the system can decide whether to add or remove the Native component. -
private EntityQuery m_EntityQuery
EntityQuery that matches any entity having one of the following read-only components: Edge, Game.Net.Node, Object, Area — and that do NOT already have the Native component. Used to add Native to newly relevant entities (e.g., on NewGame). -
private EntityQuery m_NativeQuery
EntityQuery that matches entities that have the Native component (ComponentType.ReadOnly), used to remove the Native component when appropriate (e.g., on LoadMap).
Properties
- This class exposes no public properties.
Constructors
public NativeSystem()
Default (parameterless) constructor. Marked with [Preserve] in the implementation; the constructor performs no custom initialization beyond what GameSystemBase does.
Methods
protected override void OnCreate() : System.Void
Initializes the system. Obtains a reference to LoadGameSystem from the World (GetOrCreateSystemManaged()) and constructs two EntityQuery instances: - m_EntityQuery: Any-of { Edge, Game.Net.Node, Object, Area } and None-of { Native }.
-
m_NativeQuery: ReadOnly { Native }. Marked with [Preserve] in the implementation.
-
protected override void OnUpdate() : System.Void
Runs every frame (per ECS scheduling rules). Checks m_LoadGameSystem.context.purpose and performs actions: - Purpose.NewGame: calls EntityManager.AddComponent
(m_EntityQuery) to add the Native component to matching entities. - Purpose.LoadMap: calls EntityManager.RemoveComponent
(m_NativeQuery) to remove the Native component from entities that have it. Marked with [Preserve] in the implementation.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Obtain the system (the system itself does this internally)
var nativeSystem = World.GetOrCreateSystemManaged<Game.Common.NativeSystem>();
// NativeSystem will automatically manage Native components based on LoadGameSystem.context.purpose.
}
{{ This system is intended to be used within the game's ECS world lifecycle. It relies on LoadGameSystem.context.purpose containing values such as Purpose.NewGame and Purpose.LoadMap. Because it manipulates components directly via EntityManager on entity queries, ensure any custom entity types that should receive or lose the Native marker follow the same component patterns (Edge, Game.Net.Node, Object, Area). If you need finer control or different timing, consider adding explicit system dependencies or changing update order relative to LoadGameSystem. }}