protected override void OnUpdate()
        {
            // for each teleporter with a trigger event buffer...
            Dependency = Entities.ForEach((ref GroundedTrigger groundedTrigger, in DynamicBuffer <TriggerEventBufferElement> triggerEventsBuffer) => {
                // iterate on all trigger events that happened this frame...
                for (int i = 0; i < triggerEventsBuffer.Length; i++)
                {
                    TriggerEventBufferElement triggerEvent = triggerEventsBuffer[i];

                    // If a character has entered the trigger, move its translation to the destination
                    if (triggerEvent.State == PhysicsEventState.Enter || triggerEvent.State == PhysicsEventState.Stay)
                    {
                        GroundedTrigger trigger = groundedTrigger;
                        trigger.triggered       = true;
                        groundedTrigger         = trigger;
                        //JobLogger.Log("triggered-B");
                    }
                    else if (triggerEvent.State == PhysicsEventState.Exit)
                    {
                        GroundedTrigger trigger = groundedTrigger;
                        trigger.triggered       = false;
                        groundedTrigger         = trigger;
                        //JobLogger.Log("triggered-B");
                    }
                }
            }).Schedule(Dependency);
Ejemplo n.º 2
0
        private void ProcessForEntity(Entity entity, Entity otherEntity)
        {
            if (TriggerEventBufferFromEntity.Exists(entity))
            {
                DynamicBuffer <TriggerEventBufferElement> triggerEventBuffer = TriggerEventBufferFromEntity[entity];

                bool foundMatch = false;
                for (int i = 0; i < triggerEventBuffer.Length; i++)
                {
                    TriggerEventBufferElement triggerEvent = triggerEventBuffer[i];

                    // If entity is already there, update to Stay
                    if (triggerEvent.Entity == otherEntity)
                    {
                        foundMatch            = true;
                        triggerEvent.State    = PhysicsEventState.Stay;
                        triggerEvent._isStale = false;
                        triggerEventBuffer[i] = triggerEvent;

                        break;
                    }
                }

                // If it's a new entity, add as Enter
                if (!foundMatch)
                {
                    triggerEventBuffer.Add(new TriggerEventBufferElement {
                        Entity   = otherEntity,
                        State    = PhysicsEventState.Enter,
                        _isStale = false,
                    });
                }
            }
        }
Ejemplo n.º 3
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            BufferAccessor <TriggerEventBufferElement> triggerEventsBufferAccessor = chunk.GetBufferAccessor(TriggerEventBufferType);

            for (int i = 0; i < chunk.Count; i++)
            {
                DynamicBuffer <TriggerEventBufferElement> triggerEventsBuffer = triggerEventsBufferAccessor[i];

                for (int j = triggerEventsBuffer.Length - 1; j >= 0; j--)
                {
                    TriggerEventBufferElement triggerEvent = triggerEventsBuffer[j];

                    if (triggerEvent._isStale)
                    {
                        if (triggerEvent.State == PhysicsEventState.Exit)
                        {
                            triggerEventsBuffer.RemoveAt(j);
                        }
                        else
                        {
                            triggerEvent.State     = PhysicsEventState.Exit;
                            triggerEventsBuffer[j] = triggerEvent;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            BufferAccessor <TriggerEventBufferElement> triggerEventsBufferAccessor = chunk.GetBufferAccessor(TriggerEventBufferType);

            for (int i = 0; i < chunk.Count; i++)
            {
                DynamicBuffer <TriggerEventBufferElement> triggerEventsBuffer = triggerEventsBufferAccessor[i];

                for (int j = triggerEventsBuffer.Length - 1; j >= 0; j--)
                {
                    TriggerEventBufferElement triggerEventElement = triggerEventsBuffer[j];
                    triggerEventElement._isStale = true;
                    triggerEventsBuffer[j]       = triggerEventElement;
                }
            }
        }