Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
cleaning up system registration spam issue, removing a log and changi…
Browse files Browse the repository at this point in the history
…ng execution order of InteractableComponent's input subsystem to the end to prevent conflict with drag events for others using useExecuteWithInput (#10393)
  • Loading branch information
SamMazerIR authored Jun 14, 2024
1 parent 0019feb commit 14aca78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
18 changes: 6 additions & 12 deletions packages/editor/src/systems/EditorControlSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
hasComponent,
setComponent
} from '@etherealengine/ecs/src/ComponentFunctions'
import { ECSState } from '@etherealengine/ecs/src/ECSState'
import { Engine } from '@etherealengine/ecs/src/Engine'
import { defineQuery } from '@etherealengine/ecs/src/QueryFunctions'
import { defineSystem } from '@etherealengine/ecs/src/SystemFunctions'
Expand Down Expand Up @@ -245,8 +244,6 @@ const execute = () => {

if (hasComponent(Engine.instance.cameraEntity, FlyControlComponent)) return

const deltaSeconds = getState(ECSState).deltaSeconds

const selectedEntities = SelectionState.getSelectedEntities()

const inputSources = inputQuery()
Expand Down Expand Up @@ -295,18 +292,15 @@ const execute = () => {
}
if (buttons.PrimaryClick?.up && !buttons.PrimaryClick?.dragging) {
if (hasComponent(clickStartEntity, SourceComponent)) {
const selectedEntities = SelectionState.getSelectedEntities()
const modelComponent = getAncestorWithComponent(clickStartEntity, ModelComponent)
const ancestorModelEntity = modelComponent || clickStartEntity
const targetSelection = selectedEntities[0] === ancestorModelEntity ? clickStartEntity : ancestorModelEntity

console.log(
SelectionState.getSelectedEntities()[0] === ancestorModelEntity ? clickStartEntity : ancestorModelEntity
)
SelectionState.updateSelection([
getComponent(
SelectionState.getSelectedEntities()[0] === ancestorModelEntity ? clickStartEntity : ancestorModelEntity,
UUIDComponent
)
])
//only update selection if the selection actually changed (prevents unnecessarily creating new transform gizmos in edit mode)
if (selectedEntities.length !== 1 || (selectedEntities.length === 1 && selectedEntities[0] !== targetSelection)) {
SelectionState.updateSelection([getComponent(targetSelection, UUIDComponent)])
}
}
}
}
Expand Down
30 changes: 17 additions & 13 deletions packages/engine/src/interaction/components/InteractableComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { getState, NO_PROXY, useMutableState } from '@etherealengine/hyperflux'
import { TransformComponent } from '@etherealengine/spatial'
import { CallbackComponent } from '@etherealengine/spatial/src/common/CallbackComponent'
import { createTransitionState } from '@etherealengine/spatial/src/common/functions/createTransitionState'
import { InputComponent } from '@etherealengine/spatial/src/input/components/InputComponent'
import { InputComponent, InputExecutionOrder } from '@etherealengine/spatial/src/input/components/InputComponent'
import { RigidBodyComponent } from '@etherealengine/spatial/src/physics/components/RigidBodyComponent'
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent'
import {
Expand Down Expand Up @@ -292,21 +292,25 @@ export const InteractableComponent = defineComponent({
const entity = useEntityContext()
const isEditing = useMutableState(EngineState).isEditing

InputComponent.useExecuteWithInput(() => {
const buttons = InputComponent.getMergedButtons(entity)
InputComponent.useExecuteWithInput(
() => {
const buttons = InputComponent.getMergedButtons(entity)

if (
buttons.Interact?.pressed &&
!buttons.Interact?.dragging &&
getState(InputState).capturingEntity === UndefinedEntity
) {
InputState.setCapturingEntity(entity)
if (
buttons.Interact?.pressed &&
!buttons.Interact?.dragging &&
getState(InputState).capturingEntity === UndefinedEntity
) {
InputState.setCapturingEntity(entity)

if (buttons.Interact?.up) {
callInteractCallbacks(entity)
if (buttons.Interact?.up) {
callInteractCallbacks(entity)
}
}
}
}, true)
},
true,
InputExecutionOrder.After
)

useEffect(() => {
setComponent(entity, DistanceFromCameraComponent)
Expand Down

0 comments on commit 14aca78

Please sign in to comment.