Esempio n. 1
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        float  deltaTime = Time.DeltaTime;
        float3 moveDir   = new float3(-1f, 0f, 0f);
        float  moveSpeed = 4f;

        NativeQueue <RacingEnemyPassedEvent> .ParallelWriter eventQueueParallel = eventQueue.AsParallelWriter();

        JobHandle jobHandle = Entities.ForEach((int entityInQueryIndex, ref Translation translation, ref RacingEnemy pipe) => {
            float xBefore      = translation.Value.x;
            translation.Value += moveDir * moveSpeed * deltaTime;
            float xAfter       = translation.Value.x;

            if (xBefore > 0 && xAfter <= 0)
            {
                // Passed the Player
                eventQueueParallel.Enqueue(new RacingEnemyPassedEvent {
                });
            }
        }).Schedule(inputDeps);

        jobHandle.Complete();

        while (eventQueue.TryDequeue(out RacingEnemyPassedEvent pipePassedEvent))
        {
            OnRacingEnemyPassed?.Invoke(this, EventArgs.Empty);
        }

        return(jobHandle);
    }
Esempio n. 2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        float  deltaTime   = Time.DeltaTime;
        double elapsedTime = Time.ElapsedTime;

        DOTSEvents_NextFrame <RacingEnemyPassedEvent> .EventTrigger eventTrigger = dotsEvents.GetEventTrigger();

        JobHandle jobHandle = Entities.ForEach((int entityInQueryIndex, ref Translation translation, ref RacingEnemy pipe, ref MoveSpeed moveSpeed) => {
            float yBefore      = translation.Value.y;
            translation.Value += moveSpeed.moveDirSpeed * deltaTime;
            float yAfter       = translation.Value.y;

            if (yBefore > -6 && yAfter <= -6)
            {
                // Passed the Player
                eventTrigger.TriggerEvent(entityInQueryIndex, new RacingEnemyPassedEvent {
                    Value = elapsedTime
                });
            }
        }).Schedule(inputDeps);

        dotsEvents.CaptureEvents(jobHandle, (RacingEnemyPassedEvent basicEvent) => {
            Debug.Log(basicEvent.Value + " ###### " + elapsedTime);
            OnRacingEnemyPassed?.Invoke(this, EventArgs.Empty);
        });
        return(jobHandle);
    }
Esempio n. 3
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        float  deltaTime   = Time.DeltaTime;
        double elapsedTime = Time.ElapsedTime;
        float3 moveDir     = new float3(-1f, 0f, 0f);
        float  moveSpeed   = 4f;

        EntityCommandBuffer entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer();

        EntityCommandBuffer.Concurrent entityCommandBufferConcurrent = entityCommandBuffer.ToConcurrent();
        EntityArchetype eventEntityArchetype = EntityManager.CreateArchetype(typeof(EventComponent));

        double ElapsedTime = Time.ElapsedTime;

        JobHandle jobHandle = Entities.ForEach((int entityInQueryIndex, ref Translation translation, ref RacingEnemy pipe) => {
            float xBefore      = translation.Value.x;
            translation.Value += moveDir * moveSpeed * deltaTime;
            float xAfter       = translation.Value.x;

            if (xBefore > 0 && xAfter <= 0)
            {
                // Passed the Player
                Entity eventEntity = entityCommandBufferConcurrent.CreateEntity(entityInQueryIndex, eventEntityArchetype);
                entityCommandBufferConcurrent.SetComponent(entityInQueryIndex, eventEntity, new EventComponent {
                    ElapsedTime = ElapsedTime
                });
            }
        }).Schedule(inputDeps);

        endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

        EntityCommandBuffer captureEventsEntityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer();

        Entities.WithoutBurst().ForEach((Entity entity, ref EventComponent eventComponent) => {
            Debug.Log(eventComponent.ElapsedTime + " ### " + ElapsedTime);
            OnRacingEnemyPassed?.Invoke(this, EventArgs.Empty);
            captureEventsEntityCommandBuffer.DestroyEntity(entity);
        }).Run();

        return(jobHandle);
    }