remove canvas access warning in Editor (#11709)

This commit is contained in:
PP
2022-06-27 11:50:48 +08:00
committed by GitHub
parent 8d25a7ddca
commit ebb9b800b3
2 changed files with 12 additions and 6 deletions
+6 -3
View File
@@ -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();
}
}
}
+6 -3
View File
@@ -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();
}
}
}