在当前系统OnUpdate调用前,Dependency是当前系统读取组件有写入的作业句柄和当前系统写入组件有读取的作业句柄,例如:当前系统读取A组件写入B组件, 在这个系统之前的任何系统中存在对A写入或者对B读取的作业,该作业的句柄会加入Dependency,当前系统作业执行前要等待Dependency里的作业全部完成
在OnUpdate内部,Dependency会被隐式管理,顺序依赖,例如:
protected override void OnUpdate()
{
Entities
.WithName("ForEach_Job_One")
.ForEach((ref AComponent c) =>
{
/*...*/
})
.ScheduleParallel();
Entities
.WithName("ForEach_Job_Two")
.ForEach((ref AnotherComponent c) =>
{
/*...*/
})
.ScheduleParallel();
Job
.WithName("Job_Three")
.WithCode(() =>
{
/*...*/
})
.Schedule();
}
Job_Three依赖ForEach_Job_Two,ForEach_Job_Two依赖ForEach_Job_One
可以手动修改依赖关系,例如:
protected override void OnUpdate()
{
JobHandle One = Entities
.WithName("ForEach_Job_One")
.ForEach((ref AComponent c) =>
{
/*...*/
})
.ScheduleParallel(this.Dependency);
JobHandle Two = Entities
.WithName("ForEach_Job_Two")
.ForEach((ref AnotherComponent c) =>
{
/*...*/
})
.ScheduleParallel(this.Dependency);
JobHandle intermediateDependencies =
JobHandle.CombineDependencies(One, Two);
JobHandle finalDependency = Job
.WithName("Job_Three")
.WithCode(() =>
{
/*...*/
})
.Schedule(intermediateDependencies);
this.Dependency = finalDependency;
}
ForEach_Job_One和ForEach_Job_Two 并行执行,Job_Three需要依赖前两个作业完成