Unity C#作业系统

时间:2018-08-22 11:06:21

标签: c# multithreading unity3d

假设_NoiseLayer是一个计数为3的列表。Jobs将如何执行。

  1. 我们在调度作业时,是要执行作业1然后执行作业2吗?

  2. 还有一项工作将如何在处理器级别执行?

  3. 执行方法是否要同时在处理器中所有内核的不同集合上执行??

公共无效ExecutePerlinNoise(Vector3 []个顶点)

{
    var jobHandle = new List<JobHandle>();
    var vertexArray = new NativeArray<Vector3>(vertices, Allocator.TempJob);

    for ( int i =0; i < _NoiseLayer.Count; i++)
    {
        var job = new PerlinJobSystem
        {
            vertices = vertexArray,
            layer = _NoiseLayer,
            time = Time.timeSinceLevelLoad
        };
        if (i == 0)
        {
           jobHandle.Add(job.Schedule(vertices.Length, 250));
        }
        else
        {
            jobHandle.Add(job.Schedule(vertices.Length, 250,jobHandle[i-1]));
        }
    }
    jobHandle.Last().Complete();
    vertexArray.CopyTo(vertices);
    vertexArray.Dispose();
}

公共无效执行(国际索引)

{
    var vertex = vertices[index];
    var x = vertex.x + layer.Scale + time * layer.Speed;
    var z = vertex.z + layer.Scale + time * layer.Speed;
    vertex.y += (Mathf.PerlinNoise(x, z) - 0.5f) * layer.Height;
    vertices[index] = vertex;
}

0 个答案:

没有答案