Example #1
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);
    }
Example #2
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;

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

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

            if (test.isTrigger && xBefore > 0 && xAfter <= 0)
            {
                // Passed the Player
                eventTrigger.TriggerEvent(entityInQueryIndex, new TriggerEvent {
                    triggerTime = elapsedTime
                });
            }
        }).Schedule(inputDeps);

        dotsEvents.CaptureEvents(jobHandle, (TriggerEvent basicEvent) =>
        {
            Debug.Log(basicEvent.triggerTime + " ###### " + elapsedTime);
            OnPipePassed?.Invoke(this, EventArgs.Empty);
        });
        return(jobHandle);
    }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //Debug.Log("MovementSystem working...");
            float time = Time.DeltaTime;

            double elapsedTime = Time.ElapsedTime;

            DOTSEvents_NextFrame <EventComponent> .EventTrigger eventTrigger = dotsEvent.GetEventTrigger();

            JobHandle jobHandle =
                Entities
                .ForEach((int entityInQueryIndex, ref Translation translation, ref MovementData movementData) =>
            {
                if (movementData.position.x > 5)
                {
                    movementData.speed.x = -movementData.speed.x;
                    eventTrigger.TriggerEvent(entityInQueryIndex,
                                              new EventComponent {
                        ElapsedTime = elapsedTime
                    });
                }
                if (movementData.position.x < -5)
                {
                    movementData.speed.x = -movementData.speed.x;
                }
                if (movementData.position.y > 3)
                {
                    movementData.speed.y = -movementData.speed.y;
                }
                if (movementData.position.y < -3)
                {
                    movementData.speed.y = -movementData.speed.y;
                }

                movementData.position =
                    new float3(movementData.position.x + movementData.speed.x * time,
                               movementData.position.y + movementData.speed.y * time, 0);

                translation.Value = movementData.position;
            }).Schedule(inputDeps);

            dotsEvent.CaptureEvents(jobHandle, (EventComponent basicEvent) =>
            {
                Debug.Log("Event!");
                onSpeedChange?.Invoke(this, EventArgs.Empty);
            });

            return(jobHandle);
        }