unity3d - 计算作业优化属性不起作用。缺少 using 指令或程序集引用?

标签 unity3d namespaces jobs assembly-references

尝试统一使用作业系统。 [ComputeJobOptimization] 不能放在我的代码中。

Assets/GameManager.cs(26,6):错误 CS0246:找不到类型或命名空间名称“ComputeJobOptimization”(您是否缺少 using 指令或程序集引用?)

我添加了 Burst 包,Jobs 包。将所有可能的 using.xxx 放入代码中。他们都没有工作。我在哭。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Jobs;
using Unity.Jobs;
using Unity.Collections;
using Unity.Burst;

public class GameManager : MonoBehaviour
{

    [SerializeField]
    int shipAmount;
    [SerializeField]
    GameObject enemyShipPrefab;

    TransformAccessArray transforms;
    MovementJob movementJob;
    JobHandle movementJobHandle;

    public float fallSpeed = 10.0f;

    public static GameManager GM = null;

    //ComputeJobOptimization
    [ComputeJobOptimization]
    public struct MovementJob : IJobParallelForTransform
    {

        public float fallSpeed;
        public float topBound;
        public float bottomBound;
        public float deltaTime;
        public void Execute(int index, TransformAccess transform)
        {
            Vector3 down = new Vector3(0, -1f, 0);
            Vector3 pos = transform.position;
            pos += down * deltaTime * fallSpeed;
            if (pos.y < bottomBound)
            {
                pos.y = topBound;
            }
            transform.position = pos;
        }
    }

    private void Start()
    {
        if (GM == null)
        {
            GM = this;
        }
        transforms = new TransformAccessArray(0);
    }

    private void OnDisable()
    {
        this.transforms.Dispose();
    }
    // Start is called before the first frame update
    void Update()
    {

        if (Input.GetKeyDown("space"))
            AddShips(shipAmount);

        movementJob = new MovementJob()
        {
            fallSpeed = fallSpeed,
            bottomBound = -3.5f,
            topBound = 5.5f,
            deltaTime = Time.deltaTime
        };

        movementJob.Schedule(transforms);

        JobHandle.ScheduleBatchedJobs();
    }

    private void LateUpdate()
    {
        movementJobHandle.Complete();
    }

    void AddShips(int amount)
    {
        movementJobHandle.Complete();
        transforms.capacity = transforms.length + amount;
        for (int i = 0; i < amount; i++)
        {
            float xVal = Random.Range(-8.4f, 8.4f);
            float yVal = Random.Range(-3.5f, 5.5f);
            float zVal = Random.Range(-2.0f, 10f);

            Vector3 pos = new Vector3(xVal, yVal, zVal);
            Quaternion rot = Quaternion.Euler(0f, 180f, 0f);

            var obj = Instantiate(enemyShipPrefab, pos, rot) as GameObject;
            transforms.Add(obj.transform);
        }
    }

}

最佳答案

据我所知,现在是 [BurstCompile] 属性。我在尝试使用新属性时也遇到了类似的问题,我不得不从统一包管理器窗口导入突发包库。

关于unity3d - 计算作业优化属性不起作用。缺少 using 指令或程序集引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55841488/

相关文章:

c# - 在碰撞检测期间区分玩家和其他物体碰撞器

c# - 在不在 Unity 中创建新对象的情况下打碎对象

jsf - 命名空间为 http ://xmlns. jcp.org/jsf/html 的元素可能没有命名空间 http ://xmlns. jcp.org/jsf 中的属性

javascript - 简单地访问其他命名空间的成员

amazon-web-services - 我可以使用 Athena View 作为 AWS Glue 作业的源吗?

c# - 如何检测鼠标左键单击,但在 UI 按钮组件上发生单击时不检测

unity3d - 如何在Unity应用中设置和使用Kin区 block 链-逐步

C++ 类中的 C++ 命名空间声明

python - Supervisord 进程控制 - 停止单个子进程

powershell - Start-Process 不执行后 Job 脚本 block 中的代码