diff --git a/pal/input/web/mouse-input.ts b/pal/input/web/mouse-input.ts index 930f6fd748..f13ef4c7bd 100644 --- a/pal/input/web/mouse-input.ts +++ b/pal/input/web/mouse-input.ts @@ -1,4 +1,4 @@ -import { TEST } from 'internal:constants'; +import { EDITOR, TEST } from 'internal:constants'; import { MouseCallback } from 'pal/input'; import { systemInfo } from 'pal/system-info'; import { screenAdapter } from 'pal/screen-adapter'; @@ -25,14 +25,17 @@ export class MouseInputSource { constructor () { if (systemInfo.hasFeature(Feature.EVENT_MOUSE)) { this._canvas = document.getElementById('GameCanvas') as HTMLCanvasElement; - if (!this._canvas && !TEST) { + if (!this._canvas && !TEST && !EDITOR) { console.warn('failed to access canvas'); } this._handleMouseDown = this._createCallback(InputEventType.MOUSE_DOWN); this._handleMouseMove = this._createCallback(InputEventType.MOUSE_MOVE); this._handleMouseUp = this._createCallback(InputEventType.MOUSE_UP); - this._registerEvent(); + // In Editor, we receive mouse event from manually event dispatching. + if (!EDITOR) { + this._registerEvent(); + } } } diff --git a/pal/input/web/touch-input.ts b/pal/input/web/touch-input.ts index 8c3981614e..f92325285a 100644 --- a/pal/input/web/touch-input.ts +++ b/pal/input/web/touch-input.ts @@ -1,5 +1,5 @@ import { TouchCallback } from 'pal/input'; -import { TEST } from 'internal:constants'; +import { EDITOR, TEST } from 'internal:constants'; import { systemInfo } from 'pal/system-info'; import { screenAdapter } from 'pal/screen-adapter'; import { Rect, Vec2 } from '../../../cocos/core/math'; @@ -17,10 +17,13 @@ export class TouchInputSource { constructor () { if (systemInfo.hasFeature(Feature.INPUT_TOUCH)) { this._canvas = document.getElementById('GameCanvas') as HTMLCanvasElement; - if (!this._canvas && !TEST) { + if (!this._canvas && !TEST && !EDITOR) { console.warn('failed to access canvas'); } - this._registerEvent(); + // In Editor, we don't receive touch event but maybe receive simulated touch event. + if (!EDITOR) { + this._registerEvent(); + } } }