예제 #1
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Instead of performing structural changes directly, a Job can add a command to an EntityCommandBuffer to perform such changes on the main thread after the Job has finished.
        //Command buffers allow you to perform any, potentially costly, calculations on a worker thread, while queuing up the actual insertions and deletions for later.

        if (Input.GetMouseButtonDown(1))
        {
            // Schedule the job that will add Instantiate commands to the EntityCommandBuffer.
            var job = new UnitSpawnJob
            {
                CommandBuffer = m_EntityCommandBufferSystem1.CreateCommandBuffer()
            }.ScheduleSingle(this, inputDeps);

            m_EntityCommandBufferSystem1.AddJobHandleForProducer(job);

            return(job);
        }

        return(inputDeps);
    }
예제 #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var mouse    = GetSingleton <SingletonMouseInput>();
        var keyboard = GetSingleton <SingletonKeyboardInput>();

        if (keyboard.SpaceBar)
        {
            keyboard.SpaceBar = false;
            SetSingleton <SingletonKeyboardInput>(keyboard);

            var unitJob = new UnitSpawnJob
            {
                CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer(),
                CurrentMouseRaycastPosition = mouse.CurrentMouseRaycastPosition
            }.ScheduleSingle(this, inputDeps);

            m_EntityCommandBufferSystem.AddJobHandleForProducer(unitJob);

            return(unitJob);
        }

        return(inputDeps);
    }