InteractableComponent


public final class InteractableComponent extends Component


Provides access to raw InputEvents for given Entity, so a client can implement their own interaction logic.

Summary

Public methods

static final @NonNull InteractableComponent
create(
    @NonNull Session session,
    @NonNull Consumer<@NonNull InputEvent> inputEventListener
)

Public factory for creating an InteractableComponent.

static final @NonNull InteractableComponent
create(
    @NonNull Session session,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull InputEvent> inputEventListener
)

Public factory for creating an InteractableComponent.

Protected methods

boolean

Attaches this component to the given Entity.

void

Detaches this component from the given Entity.

Public methods

create

Added in 1.0.0-beta01
public static final @NonNull InteractableComponent create(
    @NonNull Session session,
    @NonNull Consumer<@NonNull InputEvent> inputEventListener
)

Public factory for creating an InteractableComponent. It enables access to raw input events.

Parameters
@NonNull Session session

Session to create the InteractableComponent in.

@NonNull Consumer<@NonNull InputEvent> inputEventListener

Consumer that accepts InputEvents. The listener callbacks will be invoked on the main thread.

create

Added in 1.0.0-beta01
public static final @NonNull InteractableComponent create(
    @NonNull Session session,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull InputEvent> inputEventListener
)

Public factory for creating an InteractableComponent. It enables access to raw input events.

Parameters
@NonNull Session session

Session to create the InteractableComponent in.

@NonNull Executor executor

Executor for invoking the inputEventListener.

@NonNull Consumer<@NonNull InputEvent> inputEventListener

Consumer that accepts InputEvents.

Protected methods

onAttach

protected boolean onAttach(@NonNull Entity entity)

Attaches this component to the given Entity. When attached, the component begins listening for InputEvents on this Entity, and any descendant Entitys in its subgraph that do not have a InteractableComponent attached to themselves.

Parameters
@NonNull Entity entity

The Entity to attach this component to.

Returns
boolean

true if the component was successfully attached, false otherwise.

onDetach

protected void onDetach(@NonNull Entity entity)

Detaches this component from the given Entity.

Parameters
@NonNull Entity entity

The Entity to detach this component from.