Game.Prefabs.UpdateDeliveryTruckSelectJob
Assembly: Game
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType, Unity.Jobs.IJob
Summary:
Burst-compiled job that scans a set of prefab archetype chunks and builds a filtered, sorted list of candidate delivery truck prefabs and combinations (tractors + trailers) that satisfy selection requirements. It inspects DeliveryTruckData, CarTrailerData and CarTractorData components together with VehicleSelectRequirementData to produce a NativeList
Fields
-
private struct TruckData
Container used internally inside the job to hold an Entity together with its DeliveryTruckData, CarTrailerData, CarTractorData and ObjectData (as present in the prefab chunk). Used as a temporary value when building combinations of tractors/trailers/trucks. -
public EntityTypeHandle m_EntityType
EntityTypeHandle used to retrieve the Entity array from each archetype chunk. -
public ComponentTypeHandle<DeliveryTruckData> m_DeliveryTruckDataType
Component handle to read DeliveryTruckData for prefabs in each chunk (cargo capacity, transported resources, cost to drive, etc.). -
public ComponentTypeHandle<CarTrailerData> m_CarTrailerDataType
Component handle to read CarTrailerData (trailer type, fixed tractor, fixed trailer relationships, etc.). -
public ComponentTypeHandle<CarTractorData> m_CarTractorDataType
Component handle to read CarTractorData (tractor trailer type, fixed trailer, etc.). -
public NativeList<ArchetypeChunk> m_PrefabChunks
Read-only list of archetype chunks representing the set of prefabs to examine. The job iterates these chunks to extract component native arrays. -
public VehicleSelectRequirementData m_RequirementData
Read-only requirement data used to check per-prefab selection constraints. The job calls m_RequirementData.CheckRequirements to skip prefabs that do not meet selection constraints. -
public NativeList<DeliveryTruckSelectItem> m_DeliveryTruckItems
NativeList used as the output container. The job clears this list at start and adds DeliveryTruckSelectItem entries for single prefabs and combinations (up to 4 parts). The list is sorted and pruned inside Execute().
Properties
- (none)
Constructors
- (none — this is a value type job; fields are expected to be assigned before scheduling or running)
Methods
public void Execute()
: System.Void
Main entry point for the IJob. Clears m_DeliveryTruckItems then iterates all provided prefab chunks. For each prefab it:- Reads DeliveryTruckData and skips entries with zero capacity or Resource.NoResource (or those failing requirement checks).
- Collects single prefabs and, when trailers/tractors exist, explores combinations (tractor+trailer chains) by calling the CheckTrailers / CheckTractors helper overloads.
- After populating the list, sorts DeliveryTruckSelectItem entries and prunes entries that are strictly dominated by cheaper or higher-capacity combinations or whose resource coverage is fully covered by better options.
-
Trims excess capacity of the NativeList at the end.
-
private void CheckTrailers(Resource resourceMask, bool firstIsTrailer, TruckData firstData)
: System.Void
Searches through trailer prefabs to find trailers that can pair with firstData (which may be a tractor or trailer depending on firstIsTrailer). Builds 2-part combinations (tractor + trailer, or trailer + trailer chain) or continues chaining by calling other overloads, respecting fixed-tractor/fixed-trailer constraints and requirement checks. -
private void CheckTrailers(Resource resourceMask, bool firstIsTrailer, TruckData firstData, TruckData secondData)
: System.Void
Extends the trailer search to produce 3-part combinations (first + second + found trailer). Continues chaining if further fixed relationships exist; otherwise adds a combined DeliveryTruckSelectItem for matching configurations. -
private void CheckTrailers(Resource resourceMask, TruckData firstData, TruckData secondData, TruckData thirdData)
: System.Void
Finds a fourth trailer to form 4-part combos (aggregates capacities and costs of first/second/third + found trailer) and adds the result to m_DeliveryTruckItems. Respects requirement checks and fixed relationships. -
private void CheckTractors(Resource resourceMask, TruckData secondData)
: System.Void
Searches tractors that can attach to a trailer described by secondData, producing 2-part combinations, or chaining into longer combinations (calls other overloads if trailers exist). Verifies resource compatibility (resourceMask intersected with tractor transported resources) and requirements. -
private void CheckTractors(Resource resourceMask, TruckData secondData, TruckData thirdData)
: System.Void
Searches tractors that can pair with trailer combinations (secondData + thirdData) and produces 3-part combos where valid. Respects resource compatibility and fixed relationships. -
private void CheckTractors(Resource resourceMask, TruckData secondData, TruckData thirdData, TruckData forthData)
: System.Void
Searches tractors (only tractors without trailer component present in chunk) that can form 4-part combos with the provided trailer chain (secondData, thirdData, forthData). Adds aggregated DeliveryTruckSelectItem entries for valid combinations.
Notes on behavior and constraints: - All checks pay attention to fixed attachment relationships (m_FixedTrailer, m_FixedTractor) and trailer type compatibility (m_TrailerType). - Resource masks are used to ensure transported resources are compatible across the combined prefabs; combinations that would transport no resources are skipped. - The job relies solely on Burst-friendly types and Unity.Collections/Entities handles — avoid passing managed containers into the job. - The output list is deduplicated/pruned by a custom algorithm that compares cost vs capacity and resource coverage; after pruning the list is compacted and trimmed.
Usage Example
// Example: create and run the job (synchronous Run) — in real code these handles/lists are prepared beforehand.
var job = new UpdateDeliveryTruckSelectJob
{
m_EntityType = entityTypeHandle,
m_DeliveryTruckDataType = deliveryTruckDataHandle,
m_CarTrailerDataType = carTrailerDataHandle,
m_CarTractorDataType = carTractorDataHandle,
m_PrefabChunks = prefabChunksList, // NativeList<ArchetypeChunk> filled earlier
m_RequirementData = requirementData, // VehicleSelectRequirementData constructed earlier
m_DeliveryTruckItems = deliveryTruckItemsList // NativeList<DeliveryTruckSelectItem> allocated beforehand
};
job.Run(); // or .Schedule() depending on calling context
// After Run/Schedule completes, m_DeliveryTruckItems contains the filtered selection list.
If you want, I can also: - Produce a summarized class diagram or a flowchart describing how Execute() and the Check* helpers interact. - Provide an example of preparing EntityTypeHandle / ComponentTypeHandle and populating m_PrefabChunks in a systems context.