Merger
Merger is an implementation of IMergeJobWrapper. It is the last step that the BaseSteeringSystem does. Its resposibility is to for each entity, take all its results from all the system's behaviors and turn it into one final result for one of the movement systems. By default, this is:
VelocityResult- Result which behaviors output per entity.DesiredVelocityComponent- Final result attached as component on the entity telling the movement system where the entity wants to go.CombineVelocitiesJobWrapper- Implementation ofIMergeJobWrapper.
It is however entirely possible to use your own types instead of VelocityResult and DesiredVelocityComponent. The implementation should declare the types it works with using attributes. For example this is the declaration of CombineVelocitiesJobWrapper:
[JobWrapper(typeof(DesiredVelocityComponent))]
[OutData(typeof(VelocityResults))]
public class CombineVelocitiesJobWrapper : IMergeJobWrapper
{
public JobHandle Schedule(
SystemBase system,
in BaseBehaviorParams mainBaseParams,
in IDelayedDisposable[] results,
JobHandle dependency) { ... }
}
The interface receives an array of data structures containing results. The results should be castable into whichever type is declared in the [OutData] attribute. For example in CombineVelocitiesJobWrapper, they are cast into VelocityResults which is just a wrapper struct for NativeArray<VelocityResult>.
Attributes
This job wrapper uses two attributes. First declares what type of objects the merger accepts. Second declares which components are expected on the entity. The types from the attributes are used in the editor of the SteeringSystemAsset.
[OutData]- Declares the type of results the merger acceptsVelocityResults.[JobWrapper]- Declares the type of components (final result) which should be present on the entity, aboveDesiredVelocityComponent.
Behavior - Merger Compatibility
If a merger is declared as accepting VelocityResults and a behavior as outputting VelocityResults, then they are compatible. When a merger is selected in the editor, only compatible behaviors will be shown as possibilities. This prevents issues when casting from the IDelayedDisposable. As usual, the editor will also add whichever component is declared in the [JobWrapper] as the entity's dependency.