Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active November 26, 2018 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/94044d82b714f56ab839b1961bd56536 to your computer and use it in GitHub Desktop.
Save tsubaki/94044d82b714f56ab839b1961bd56536 to your computer and use it in GitHub Desktop.
ECSサンプル、並列化
using Unity.Entities;
using Unity.Jobs;
public class CountSystem : JobComponentSystem
{
AddCounterJob job;
protected override void OnCreateManager(int capacity)
{
base.OnCreateManager(capacity);
// ジョブを作っとく
job = new AddCounterJob();
}
// ジョブを発行
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
return job.Schedule(this, 64, inputDeps);
}
[Unity.Burst.BurstCompile] // Burstコンパイラに最適化属性
struct AddCounterJob : IJobProcessComponentData<CountData> // 要求するComponentData
{
public void Execute(ref CountData data)
{
data.count++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment