Game.AirwaySystem
Assembly: Assembly-CSharp
Namespace: Game.Net
Type: class
Base: GameSystemBase, IJobSerializable
Summary:
AirwaySystem is a game system responsible for creating, initializing, serializing and deserializing airway lane data used by aircraft (helicopters and airplanes). It owns two grid-based AirwayMap instances (helicopter and airplane) inside an AirwayData container, generates Lane/Curve/ConnectionLane entities for each airway cell at new-game initialization, and provides jobs for save/load and default initialization. The system uses Unity Jobs (Burst-compiled where appropriate) for parallel lane generation and for (de)serialization work to avoid blocking the main thread. It also interacts with TerrainSystem and WaterSystem to sample heights when constructing lane geometry.
Key responsibilities: - Maintain AirwayHelpers.AirwayData containing helicopter and airplane AirwayMap instances. - Create entity lanes using a NetLane archetype on new game initialization. - Schedule a parallel GenerateAirwayLanesJob to populate PrefabRef, Lane, Curve and ConnectionLane components for each airway cell. - Provide Serialize/Deserialize job wrappers (generic over IWriter/IReader) to persist airway maps. - Provide SetDefaults job to initialize airway maps for older save versions or defaults. - Coordinate with TerrainSystem and WaterSystem when computing lane node heights.
Constants (from the class): - TERRAIN_SIZE = 14336f - Helicopter grid: 28x28, cell size 494.34482f, path height 200f - Airplane grid: 14x14, cell size 988.68964f, path height 1000f
Fields
-
private const float TERRAIN_SIZE
This constant is declared as 14336f and represents the total terrain size used as a reference in the system. -
private const int HELICOPTER_GRID_WIDTH
private const int HELICOPTER_GRID_LENGTH
private const float HELICOPTER_CELL_SIZE
-
private const float HELICOPTER_PATH_HEIGHT
Constants that define the helicopter airway grid dimensions, each cell size and the default path height used when creating helicopter lanes. -
private const int AIRPLANE_GRID_WIDTH
private const int AIRPLANE_GRID_LENGTH
private const float AIRPLANE_CELL_SIZE
-
private const float AIRPLANE_PATH_HEIGHT
Constants that define the airplane airway grid dimensions, each cell size and the default airplane path height. -
private LoadGameSystem m_LoadGameSystem
Reference to the LoadGameSystem, used to inspect new-game vs load-game context and to gate initial creation behavior. -
private TerrainSystem m_TerrainSystem
Used to obtain terrain height data when positioning airway nodes. -
private WaterSystem m_WaterSystem
Used to obtain water surface data when sampling final node heights. -
private EntityQuery m_PrefabQuery
Query used to fetch the Net lane prefab/prefab data for creating lane entities. -
private EntityQuery m_AirplaneConnectionQuery
Query used to detect existing airplane connection entities (e.g., outside connections / takeoff locations) so that Updated can be set when appropriate. -
private EntityQuery m_OldConnectionQuery
Query used to detect older-style connection lanes that might need migration or detection on new games. -
private AirwayHelpers.AirwayData m_AirwayData
Holds two AirwayMap instances (helicopterMap and airplaneMap). This is the central data container manipulated, serialized and used to create lane entities. -
private TypeHandle __TypeHandle
Internal struct that caches ComponentLookup handles required by the jobs and entity creation logic (PrefabRef, Lane, Curve, ConnectionLane lookups). -
Nested job structs:
SerializeJob<TWriter>
,DeserializeJob<TReader>
,SetDefaultsJob
,GenerateAirwayLanesJob
These are inner types rather than simple fields, but they represent the Burst-compiled work units the AirwaySystem schedules: - SerializeJob
— writes helicopter and airplane maps via an IWriter. - DeserializeJob
— reads helicopter and airplane maps via an IReader, with version handling for airplane airway support. - SetDefaultsJob — fills both maps with default values using a Context.
- GenerateAirwayLanesJob — parallel-for job that creates Per-entity PrefabRef, Lane, Curve and ConnectionLane components and samples terrain/water heights to build straight Bezier curves for lanes.
Properties
- This type exposes no public properties. It exposes methods to access data (GetAirwayData) and to run jobs for serialization/deserialization and defaults.
Constructors
public AirwaySystem()
Default constructor. The real initialization of runtime data happens in OnCreate. The constructor is preserved for compatibility with Unity's systems.
Methods
-
protected override void OnCreate()
: System.Void
Initializes the system: acquires references to LoadGameSystem, TerrainSystem and WaterSystem, prepares EntityQuery instances, creates helicopter and airplane AirwayMap instances (28x28 and 14x14 grids respectively) and stores them in m_AirwayData. Also calls RequireForUpdate(m_PrefabQuery) to ensure the system only updates when relevant prefab data exists. -
protected override void OnDestroy()
: System.Void
Disposes of the m_AirwayData (releasing the persistent Allocator resources used by the AirwayMaps) and performs base cleanup. -
protected override void OnUpdate()
: System.Void
If starting a NewGame and no old-style connections exist, this method: - Retrieves the lane prefab archetype data.
- Marks airplane connection entities as Updated if any exist.
- Creates lane entities in bulk for both helicopter and airplane maps using the lane archetype stored on the prefab.
- Obtains terrain height data and water surface data (scheduling dependencies).
- Schedules GenerateAirwayLanesJob for the helicopter map and a second parallel-for job for the airplane map. The jobs fill PrefabRef, Lane, Curve and ConnectionLane components for each airway entity and sample heights using TerrainSystem and WaterSystem.
-
Registers job handles with TerrainSystem and WaterSystem readers and stores the job handle in base.Dependency.
-
public AirwayHelpers.AirwayData GetAirwayData()
: AirwayHelpers.AirwayData
Returns the internal AirwayData instance (containing helicopterMap and airplaneMap). Useful for other systems or tools that need read access to the airway grid maps. -
public JobHandle Serialize<TWriter>(EntityWriterData writerData, JobHandle inputDeps) where TWriter : struct, IWriter
: JobHandle
Schedules and returns a SerializeJobthat will call Serialize on both helicopter and airplane maps. The job is scheduled with the provided dependency, allowing save serialization to be performed on a job thread. -
public JobHandle Deserialize<TReader>(EntityReaderData readerData, JobHandle inputDeps) where TReader : struct, IReader
: JobHandle
Schedules and returns a DeserializeJobthat will call Deserialize on both maps. The reader job handles legacy save versions by only deserializing the airplane map if the save version supports airplane airways; otherwise, it calls SetDefaults on the airplane map. -
public JobHandle SetDefaults(Context context)
: JobHandle
Schedules a SetDefaultsJob that initializes both airway maps with default values derived from Context. Used when loading older saves or creating default data. -
private void __AssignQueries(ref SystemState state)
: System.Void
Compiler-generated method used by OnCreateForCompiler to assign or initialize queries (contains a call to EntityQueryBuilder in the decompiled code). Not intended for direct use in typical mods. -
protected override void OnCreateForCompiler()
: System.Void
Compiler hook that calls __AssignQueries and __TypeHandle.__AssignHandles to ensure ComponentLookup handles and queries are set up when the system is created in compiled builds. -
private struct TypeHandle.__AssignHandles(ref SystemState state)
: System.Void
Assigns ComponentLookup instances (PrefabRef, Lane, Curve, ConnectionLane) to the TypeHandle fields using the provided SystemState. This is used so jobs can get component lookups through the internal compiler interface. -
Inner job method details:
- GenerateAirwayLanesJob.Execute(int entityIndex) - maps an entity index to grid cell and lane direction, determines start/end nodes and calls CreateLane.
- GenerateAirwayLanesJob.CreateLane(...) - constructs a Lane (start/middle/end), computes node positions, samples terrain/water heights, constructs a straight Bezier Curve via NetUtils.StraightCurve, computes length, builds ConnectionLane and writes PrefabRef, Lane, Curve and ConnectionLane into component lookups.
Usage Example
// Example: Access airway data and schedule a serialization job (pseudo-usage in a mod/system).
public class MyAirwayTool
{
private World world; // acquired from game context
private AirwaySystem m_AirwaySystem;
public void Initialize(World world)
{
this.world = world;
m_AirwaySystem = world.GetOrCreateSystemManaged<AirwaySystem>();
}
public void DoSave(EntityWriterData writerData, JobHandle dependency)
{
// Schedule serialization using the game's writer type (example IWriter struct)
JobHandle saveHandle = m_AirwaySystem.Serialize<MyGameWriter>(writerData, dependency);
// We could then combine saveHandle with other save jobs or complete it as needed.
}
public void ReadAirwayInfo()
{
var data = m_AirwaySystem.GetAirwayData();
// Inspect data.helicopterMap / data.airplaneMap for debugging or custom tooling.
}
}
Notes: - AirwaySystem uses Burst-compiled jobs for heavy processing. Jobs operate on ComponentLookup instances retrieved via InternalCompilerInterface and TypeHandle, which are set up during system creation for the compiler/runtime. - The GenerateAirwayLanesJob creates straight Bezier curves between cell nodes and marks ConnectionLaneFlags.AllowMiddle | ConnectionLaneFlags.Airway on generated lanes. - When working with serialization, ensure the writer/reader types implement IWriter/IReader and that job dependencies are respected (pass correct JobHandle).