31 lines
717 B
C#
31 lines
717 B
C#
using Unity.Jobs;
|
|||
|
|
using Unity.Burst;
|
||
|
|
using Unity.Collections;
|
||
|
|
|
||
|
|
[BurstCompile]
|
||
|
|
public struct FishSpawnTimerJob : IJob
|
||
|
|
{
|
||
|
|
public float deltaTime;
|
||
|
|
public NativeArray<float> timers; // 每条鱼的计时器
|
||
|
|
public NativeArray<float> frequencies; // 每条鱼的频率
|
||
|
|
public NativeArray<int> shouldSpawn; // 输出:是否应该生成
|
||
|
|
|
||
|
|
public void Execute()
|
||
|
|
{
|
||
|
|
for (int i = 0; i < timers.Length; i++)
|
||
|
|
{
|
||
|
|
timers[i] += deltaTime;
|
||
|
|
|
||
|
|
if (timers[i] >= frequencies[i])
|
||
|
|
{
|
||
|
|
timers[i] = 0;
|
||
|
|
shouldSpawn[i] = 1;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
shouldSpawn[i] = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|