diff --git a/cocos/input/input.ts b/cocos/input/input.ts index 47ab13464b3..013be74c837 100644 --- a/cocos/input/input.ts +++ b/cocos/input/input.ts @@ -25,7 +25,8 @@ */ import { EDITOR_NOT_IN_PREVIEW, NATIVE } from 'internal:constants'; -import { AccelerometerInputSource, GamepadInputDevice, HMDInputDevice, HandheldInputDevice, HandleInputDevice, KeyboardInputSource, MouseInputSource, TouchInputSource } from 'pal/input'; +import { AccelerometerInputSource, GamepadInputDevice, HMDInputDevice, HandheldInputDevice, + HandleInputDevice, KeyboardInputSource, MouseInputSource, TouchInputSource } from 'pal/input'; import { touchManager } from '../../pal/input/touch-manager'; import { EventTarget, error, sys } from '../core'; import { Event, EventAcceleration, EventGamepad, EventHandle, EventHandheld, EventHMD, EventKeyboard, EventMouse, EventTouch, Touch } from './types'; @@ -350,103 +351,108 @@ export class Input { } private _registerEvent (): void { + const self = this; + const touchInput = self._touchInput; + const mouseInput = self._mouseInput; + const keyboardInput = self._keyboardInput; + const handleInput = self._handleInput; if (sys.hasFeature(sys.Feature.INPUT_TOUCH)) { - this._touchInput.on(InputEventType.TOUCH_START, (event): void => { - this._dispatchEventTouch(event); + touchInput.on(InputEventType.TOUCH_START, (event): void => { + self._dispatchEventTouch(event); }); - this._touchInput.on(InputEventType.TOUCH_MOVE, (event): void => { - this._dispatchEventTouch(event); + touchInput.on(InputEventType.TOUCH_MOVE, (event): void => { + self._dispatchEventTouch(event); }); - this._touchInput.on(InputEventType.TOUCH_END, (event): void => { - this._dispatchEventTouch(event); + touchInput.on(InputEventType.TOUCH_END, (event): void => { + self._dispatchEventTouch(event); }); - this._touchInput.on(InputEventType.TOUCH_CANCEL, (event): void => { - this._dispatchEventTouch(event); + touchInput.on(InputEventType.TOUCH_CANCEL, (event): void => { + self._dispatchEventTouch(event); }); } if (sys.hasFeature(sys.Feature.EVENT_MOUSE)) { - this._mouseInput.on(InputEventType.MOUSE_DOWN, (event): void => { - this._needSimulateTouchMoveEvent = true; - this._simulateEventTouch(event); - this._dispatchEventMouse(event); + mouseInput.on(InputEventType.MOUSE_DOWN, (event): void => { + self._needSimulateTouchMoveEvent = true; + self._simulateEventTouch(event); + self._dispatchEventMouse(event); }); - this._mouseInput.on(InputEventType.MOUSE_MOVE, (event): void => { - if (this._needSimulateTouchMoveEvent) { - this._simulateEventTouch(event); + mouseInput.on(InputEventType.MOUSE_MOVE, (event): void => { + if (self._needSimulateTouchMoveEvent) { + self._simulateEventTouch(event); } - this._dispatchEventMouse(event); + self._dispatchEventMouse(event); }); - this._mouseInput.on(InputEventType.MOUSE_UP, (event): void => { - this._needSimulateTouchMoveEvent = false; - this._simulateEventTouch(event); - this._dispatchEventMouse(event); + mouseInput.on(InputEventType.MOUSE_UP, (event): void => { + self._needSimulateTouchMoveEvent = false; + self._simulateEventTouch(event); + self._dispatchEventMouse(event); }); - this._mouseInput.on(InputEventType.MOUSE_WHEEL, (event): void => { - this._dispatchEventMouse(event); + mouseInput.on(InputEventType.MOUSE_WHEEL, (event): void => { + self._dispatchEventMouse(event); }); - this._mouseInput.on(InputEventType.MOUSE_LEAVE, (event): void => { - this._dispatchEventMouse(event); + mouseInput.on(InputEventType.MOUSE_LEAVE, (event): void => { + self._dispatchEventMouse(event); }); - this._mouseInput.on(InputEventType.MOUSE_ENTER, (event): void => { - this._dispatchEventMouse(event); + mouseInput.on(InputEventType.MOUSE_ENTER, (event): void => { + self._dispatchEventMouse(event); }); } if (sys.hasFeature(sys.Feature.EVENT_KEYBOARD)) { - const eventKeyboardList = this._eventKeyboardList; - this._keyboardInput.on(InputEventType.KEY_DOWN, (event): void => { - this._dispatchOrPushEvent(event, eventKeyboardList); + const eventKeyboardList = self._eventKeyboardList; + keyboardInput.on(InputEventType.KEY_DOWN, (event): void => { + self._dispatchOrPushEvent(event, eventKeyboardList); }); - this._keyboardInput.on(InputEventType.KEY_PRESSING, (event): void => { - this._dispatchOrPushEvent(event, eventKeyboardList); + keyboardInput.on(InputEventType.KEY_PRESSING, (event): void => { + self._dispatchOrPushEvent(event, eventKeyboardList); }); - this._keyboardInput.on(InputEventType.KEY_UP, (event): void => { - this._dispatchOrPushEvent(event, eventKeyboardList); + keyboardInput.on(InputEventType.KEY_UP, (event): void => { + self._dispatchOrPushEvent(event, eventKeyboardList); }); } if (sys.hasFeature(sys.Feature.EVENT_ACCELEROMETER)) { - const eventAccelerationList = this._eventAccelerationList; - this._accelerometerInput.on(InputEventType.DEVICEMOTION, (event): void => { - this._dispatchOrPushEvent(event, eventAccelerationList); + const eventAccelerationList = self._eventAccelerationList; + self._accelerometerInput.on(InputEventType.DEVICEMOTION, (event): void => { + self._dispatchOrPushEvent(event, eventAccelerationList); }); } if (sys.hasFeature(sys.Feature.EVENT_GAMEPAD)) { - const eventGamepadList = this._eventGamepadList; + const eventGamepadList = self._eventGamepadList; GamepadInputDevice._on(InputEventType.GAMEPAD_CHANGE, (event): void => { - this._dispatchOrPushEvent(event, eventGamepadList); + self._dispatchOrPushEvent(event, eventGamepadList); }); GamepadInputDevice._on(InputEventType.GAMEPAD_INPUT, (event): void => { - this._dispatchOrPushEvent(event, eventGamepadList); + self._dispatchOrPushEvent(event, eventGamepadList); }); GamepadInputDevice._on(InputEventType.HANDLE_POSE_INPUT, (event): void => { - this._dispatchOrPushEvent(event, eventGamepadList); + self._dispatchOrPushEvent(event, eventGamepadList); }); } if (sys.hasFeature(sys.Feature.EVENT_HANDLE)) { - const eventHandleList = this._eventHandleList; - this._handleInput._on(InputEventType.HANDLE_INPUT, (event): void => { - this._dispatchOrPushEvent(event, eventHandleList); + const eventHandleList = self._eventHandleList; + handleInput._on(InputEventType.HANDLE_INPUT, (event): void => { + self._dispatchOrPushEvent(event, eventHandleList); }); - this._handleInput._on(InputEventType.HANDLE_POSE_INPUT, (event): void => { - this._dispatchOrPushEvent(event, eventHandleList); + handleInput._on(InputEventType.HANDLE_POSE_INPUT, (event): void => { + self._dispatchOrPushEvent(event, eventHandleList); }); } if (sys.hasFeature(sys.Feature.EVENT_HMD)) { - const eventHMDList = this._eventHMDList; - this._hmdInput._on(InputEventType.HMD_POSE_INPUT, (event): void => { - this._dispatchOrPushEvent(event, eventHMDList); + const eventHMDList = self._eventHMDList; + self._hmdInput._on(InputEventType.HMD_POSE_INPUT, (event): void => { + self._dispatchOrPushEvent(event, eventHMDList); }); } if (sys.hasFeature(sys.Feature.EVENT_HANDHELD)) { - const eventHandheldList = this._eventHandheldList; - this._handheldInput._on(InputEventType.HANDHELD_POSE_INPUT, (event): void => { - this._dispatchOrPushEvent(event, eventHandheldList); + const eventHandheldList = self._eventHandheldList; + self._handheldInput._on(InputEventType.HANDHELD_POSE_INPUT, (event): void => { + self._dispatchOrPushEvent(event, eventHandheldList); }); } } diff --git a/cocos/tiledmap/tiled-layer.ts b/cocos/tiledmap/tiled-layer.ts index 2549a123b2f..78770a57d2a 100644 --- a/cocos/tiledmap/tiled-layer.ts +++ b/cocos/tiledmap/tiled-layer.ts @@ -1341,81 +1341,89 @@ export class TiledLayer extends UIRenderer { this._prepareToRender(); } - public init (layerInfo: TMXLayerInfo, mapInfo: TMXMapInfo, tilesets: TMXTilesetInfo[], textures: SpriteFrame[], texGrids: TiledTextureGrids): void { - this._cullingDirty = true; - this._layerInfo = layerInfo; - this._mapInfo = mapInfo; + public init ( + layerInfo: TMXLayerInfo, + mapInfo: TMXMapInfo, + tilesets: TMXTilesetInfo[], + textures: SpriteFrame[], + texGrids: TiledTextureGrids, + ): void { + const self = this; + self._cullingDirty = true; + self._layerInfo = layerInfo; + self._mapInfo = mapInfo; const size = layerInfo.layerSize!; // layerInfo - this._layerName = layerInfo.name; - this.tiles = layerInfo.tiles as unknown as any; - this._properties = layerInfo.properties; - this._layerSize = size; - this._minGID = layerInfo.minGID; - this._maxGID = layerInfo.maxGID; - this._opacity = layerInfo.opacity; + self._layerName = layerInfo.name; + self.tiles = layerInfo.tiles as unknown as any; + self._properties = layerInfo.properties; + self._layerSize = size; + self._minGID = layerInfo.minGID; + self._maxGID = layerInfo.maxGID; + self._opacity = layerInfo.opacity; if (layerInfo.tintColor) { - this._tintColor = layerInfo.tintColor; + self._tintColor = layerInfo.tintColor; // this.node.color = this._tintColor; } - this.renderOrder = mapInfo.renderOrder; - this._staggerAxis = mapInfo.getStaggerAxis()!; - this._staggerIndex = mapInfo.getStaggerIndex()!; - this._hexSideLength = mapInfo.getHexSideLength(); - this._animations = mapInfo.getTileAnimations(); + self.renderOrder = mapInfo.renderOrder; + self._staggerAxis = mapInfo.getStaggerAxis()!; + self._staggerIndex = mapInfo.getStaggerIndex()!; + self._hexSideLength = mapInfo.getHexSideLength(); + self._animations = mapInfo.getTileAnimations(); // tilesets - this._tilesets = tilesets; + self._tilesets = tilesets; // textures - this._textures = textures; + self._textures = textures; // grid texture - this.texGrids = texGrids; + self.texGrids = texGrids; // mapInfo - this._layerOrientation = mapInfo.orientation; - this._mapTileSize = mapInfo.getTileSize(); + self._layerOrientation = mapInfo.orientation; + self._mapTileSize = mapInfo.getTileSize(); - const maptw = this._mapTileSize.width; - const mapth = this._mapTileSize.height; - const layerW = this._layerSize.width; - const layerH = this._layerSize.height; + const maptw = self._mapTileSize.width; + const mapth = self._mapTileSize.height; + const layerW = self._layerSize.width; + const layerH = self._layerSize.height; + const uiTransformComp = self.node._getUITransformComp()!; - if (this._layerOrientation === Orientation.HEX) { + if (self._layerOrientation === Orientation.HEX) { let width = 0; let height = 0; const tileWidth = maptw & ~1; const tileHeight = mapth & ~1; - this._odd_even = (this._staggerIndex === StaggerIndex.STAGGERINDEX_ODD) ? 1 : -1; - if (this._staggerAxis === StaggerAxis.STAGGERAXIS_X) { - this._diffX1 = (tileWidth - this._hexSideLength) / 2; - this._diffY1 = 0; - width = (this._diffX1 + this._hexSideLength) * layerW + this._diffX1; + self._odd_even = (self._staggerIndex === StaggerIndex.STAGGERINDEX_ODD) ? 1 : -1; + if (self._staggerAxis === StaggerAxis.STAGGERAXIS_X) { + self._diffX1 = (tileWidth - self._hexSideLength) / 2; + self._diffY1 = 0; + width = (self._diffX1 + self._hexSideLength) * layerW + self._diffX1; height = (tileHeight * layerH) + tileHeight / 2; } else { - this._diffX1 = 0; - this._diffY1 = (tileHeight - this._hexSideLength) / 2; + self._diffX1 = 0; + self._diffY1 = (tileHeight - self._hexSideLength) / 2; width = (tileWidth * layerW) + tileWidth / 2; - height = (this._diffY1 + this._hexSideLength) * layerH + this._diffY1; + height = (self._diffY1 + self._hexSideLength) * layerH + self._diffY1; } - this.node._getUITransformComp()!.setContentSize(width, height); - } else if (this._layerOrientation === Orientation.ISO) { + uiTransformComp.setContentSize(width, height); + } else if (self._layerOrientation === Orientation.ISO) { const wh = layerW + layerH; - this.node._getUITransformComp()!.setContentSize(maptw * 0.5 * wh, mapth * 0.5 * wh); + uiTransformComp.setContentSize(maptw * 0.5 * wh, mapth * 0.5 * wh); } else { - this.node._getUITransformComp()!.setContentSize(layerW * maptw, layerH * mapth); + uiTransformComp.setContentSize(layerW * maptw, layerH * mapth); } // offset (after layer orientation is set); - this._offset = new Vec2(layerInfo.offset.x, -layerInfo.offset.y); - this._useAutomaticVertexZ = false; - this._vertexZvalue = 0; - this._syncAnchorPoint(); - this._prepareToRender(); + self._offset = new Vec2(layerInfo.offset.x, -layerInfo.offset.y); + self._useAutomaticVertexZ = false; + self._vertexZvalue = 0; + self._syncAnchorPoint(); + self._prepareToRender(); } protected _prepareToRender (): void { diff --git a/pal/input/minigame/gamepad-input.ts b/pal/input/minigame/gamepad-input.ts index 97ff9e90987..caa32884b6a 100644 --- a/pal/input/minigame/gamepad-input.ts +++ b/pal/input/minigame/gamepad-input.ts @@ -122,37 +122,38 @@ export class GamepadInputDevice { } private _initInputSource (): void { - this._buttonNorth = new InputSourceButton(); - this._buttonNorth.getValue = (): number => 0; - this._buttonEast = new InputSourceButton(); - this._buttonEast.getValue = (): number => 0; - this._buttonWest = new InputSourceButton(); - this._buttonWest.getValue = (): number => 0; - this._buttonSouth = new InputSourceButton(); - this._buttonSouth.getValue = (): number => 0; - - this._buttonL1 = new InputSourceButton(); - this._buttonL1.getValue = (): number => 0; - this._buttonL2 = new InputSourceButton(); - this._buttonL2.getValue = (): number => 0; - this._buttonL3 = new InputSourceButton(); - this._buttonL3.getValue = (): number => 0; - this._buttonR1 = new InputSourceButton(); - this._buttonR1.getValue = (): number => 0; - this._buttonR2 = new InputSourceButton(); - this._buttonR2.getValue = (): number => 0; - this._buttonR3 = new InputSourceButton(); - this._buttonR3.getValue = (): number => 0; - - // this._buttonTouchPad = new InputSourceButton(); - // this._buttonTouchPad.getValue = () => 0; - // this._buttonHome = new InputSourceButton(); - // this._buttonHome.getValue = () => 0; - - this._buttonShare = new InputSourceButton(); - this._buttonShare.getValue = (): number => 0; - this._buttonOptions = new InputSourceButton(); - this._buttonOptions.getValue = (): number => 0; + const self = this; + self._buttonNorth = new InputSourceButton(); + self._buttonNorth.getValue = (): number => 0; + self._buttonEast = new InputSourceButton(); + self._buttonEast.getValue = (): number => 0; + self._buttonWest = new InputSourceButton(); + self._buttonWest.getValue = (): number => 0; + self._buttonSouth = new InputSourceButton(); + self._buttonSouth.getValue = (): number => 0; + + self._buttonL1 = new InputSourceButton(); + self._buttonL1.getValue = (): number => 0; + self._buttonL2 = new InputSourceButton(); + self._buttonL2.getValue = (): number => 0; + self._buttonL3 = new InputSourceButton(); + self._buttonL3.getValue = (): number => 0; + self._buttonR1 = new InputSourceButton(); + self._buttonR1.getValue = (): number => 0; + self._buttonR2 = new InputSourceButton(); + self._buttonR2.getValue = (): number => 0; + self._buttonR3 = new InputSourceButton(); + self._buttonR3.getValue = (): number => 0; + + // self._buttonTouchPad = new InputSourceButton(); + // self._buttonTouchPad.getValue = () => 0; + // self._buttonHome = new InputSourceButton(); + // self._buttonHome.getValue = () => 0; + + self._buttonShare = new InputSourceButton(); + self._buttonShare.getValue = (): number => 0; + self._buttonOptions = new InputSourceButton(); + self._buttonOptions.getValue = (): number => 0; const dpadUp = new InputSourceButton(); dpadUp.getValue = (): number => 0; @@ -162,7 +163,7 @@ export class GamepadInputDevice { dpadLeft.getValue = (): number => 0; const dpadRight = new InputSourceButton(); dpadRight.getValue = (): number => 0; - this._dpad = new InputSourceDpad({ up: dpadUp, down: dpadDown, left: dpadLeft, right: dpadRight }); + self._dpad = new InputSourceDpad({ up: dpadUp, down: dpadDown, left: dpadLeft, right: dpadRight }); const leftStickUp = new InputSourceButton(); leftStickUp.getValue = (): number => 0; @@ -172,7 +173,7 @@ export class GamepadInputDevice { leftStickLeft.getValue = (): number => 0; const leftStickRight = new InputSourceButton(); leftStickRight.getValue = (): number => 0; - this._leftStick = new InputSourceStick({ up: leftStickUp, down: leftStickDown, left: leftStickLeft, right: leftStickRight }); + self._leftStick = new InputSourceStick({ up: leftStickUp, down: leftStickDown, left: leftStickLeft, right: leftStickRight }); const rightStickUp = new InputSourceButton(); rightStickUp.getValue = (): number => 0; @@ -182,34 +183,34 @@ export class GamepadInputDevice { rightStickLeft.getValue = (): number => 0; const rightStickRight = new InputSourceButton(); rightStickRight.getValue = (): number => 0; - this._rightStick = new InputSourceStick({ up: rightStickUp, down: rightStickDown, left: rightStickLeft, right: rightStickRight }); - - this._buttonStart = new InputSourceButton(); - this._buttonStart.getValue = (): number => 0; - - this._gripLeft = new InputSourceButton(); - this._gripLeft.getValue = (): number => 0; - this._gripRight = new InputSourceButton(); - this._gripRight.getValue = (): number => 0; - - this._handLeftPosition = new InputSourcePosition(); - this._handLeftPosition.getValue = (): Readonly => Vec3.ZERO; - this._handLeftOrientation = new InputSourceOrientation(); - this._handLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; - - this._handRightPosition = new InputSourcePosition(); - this._handRightPosition.getValue = (): Readonly => Vec3.ZERO; - this._handRightOrientation = new InputSourceOrientation(); - this._handRightOrientation.getValue = (): Readonly => Quat.IDENTITY; - - this._aimLeftPosition = new InputSourcePosition(); - this._aimLeftPosition.getValue = (): Readonly => Vec3.ZERO; - this._aimLeftOrientation = new InputSourceOrientation(); - this._aimLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; - - this._aimRightPosition = new InputSourcePosition(); - this._aimRightPosition.getValue = (): Readonly => Vec3.ZERO; - this._aimRightOrientation = new InputSourceOrientation(); - this._aimRightOrientation.getValue = (): Readonly => Quat.IDENTITY; + self._rightStick = new InputSourceStick({ up: rightStickUp, down: rightStickDown, left: rightStickLeft, right: rightStickRight }); + + self._buttonStart = new InputSourceButton(); + self._buttonStart.getValue = (): number => 0; + + self._gripLeft = new InputSourceButton(); + self._gripLeft.getValue = (): number => 0; + self._gripRight = new InputSourceButton(); + self._gripRight.getValue = (): number => 0; + + self._handLeftPosition = new InputSourcePosition(); + self._handLeftPosition.getValue = (): Readonly => Vec3.ZERO; + self._handLeftOrientation = new InputSourceOrientation(); + self._handLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; + + self._handRightPosition = new InputSourcePosition(); + self._handRightPosition.getValue = (): Readonly => Vec3.ZERO; + self._handRightOrientation = new InputSourceOrientation(); + self._handRightOrientation.getValue = (): Readonly => Quat.IDENTITY; + + self._aimLeftPosition = new InputSourcePosition(); + self._aimLeftPosition.getValue = (): Readonly => Vec3.ZERO; + self._aimLeftOrientation = new InputSourceOrientation(); + self._aimLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; + + self._aimRightPosition = new InputSourcePosition(); + self._aimRightPosition.getValue = (): Readonly => Vec3.ZERO; + self._aimRightOrientation = new InputSourceOrientation(); + self._aimRightOrientation.getValue = (): Readonly => Quat.IDENTITY; } } diff --git a/pal/input/minigame/handle-input.ts b/pal/input/minigame/handle-input.ts index 8be6a55e045..e3cb4d87986 100644 --- a/pal/input/minigame/handle-input.ts +++ b/pal/input/minigame/handle-input.ts @@ -109,30 +109,31 @@ export class HandleInputDevice { } private _initInputSource (): void { - this._buttonNorth = new InputSourceButton(); - this._buttonNorth.getValue = (): number => 0; - this._buttonEast = new InputSourceButton(); - this._buttonEast.getValue = (): number => 0; - this._buttonWest = new InputSourceButton(); - this._buttonWest.getValue = (): number => 0; - this._buttonSouth = new InputSourceButton(); - this._buttonSouth.getValue = (): number => 0; - - this._buttonTriggerLeft = new InputSourceButton(); - this._buttonTriggerLeft.getValue = (): number => 0; - this._buttonTriggerRight = new InputSourceButton(); - this._buttonTriggerRight.getValue = (): number => 0; - this._triggerLeft = new InputSourceButton(); - this._triggerLeft.getValue = (): number => 0; - this._triggerRight = new InputSourceButton(); - this._triggerRight.getValue = (): number => 0; - this._gripLeft = new InputSourceButton(); - this._gripLeft.getValue = (): number => 0; - this._gripRight = new InputSourceButton(); - this._gripRight.getValue = (): number => 0; - - this._buttonLeftStick = new InputSourceButton(); - this._buttonLeftStick.getValue = (): number => 0; + const self = this; + self._buttonNorth = new InputSourceButton(); + self._buttonNorth.getValue = (): number => 0; + self._buttonEast = new InputSourceButton(); + self._buttonEast.getValue = (): number => 0; + self._buttonWest = new InputSourceButton(); + self._buttonWest.getValue = (): number => 0; + self._buttonSouth = new InputSourceButton(); + self._buttonSouth.getValue = (): number => 0; + + self._buttonTriggerLeft = new InputSourceButton(); + self._buttonTriggerLeft.getValue = (): number => 0; + self._buttonTriggerRight = new InputSourceButton(); + self._buttonTriggerRight.getValue = (): number => 0; + self._triggerLeft = new InputSourceButton(); + self._triggerLeft.getValue = (): number => 0; + self._triggerRight = new InputSourceButton(); + self._triggerRight.getValue = (): number => 0; + self._gripLeft = new InputSourceButton(); + self._gripLeft.getValue = (): number => 0; + self._gripRight = new InputSourceButton(); + self._gripRight.getValue = (): number => 0; + + self._buttonLeftStick = new InputSourceButton(); + self._buttonLeftStick.getValue = (): number => 0; const leftStickUp = new InputSourceButton(); leftStickUp.getValue = (): number => 0; const leftStickDown = new InputSourceButton(); @@ -141,10 +142,10 @@ export class HandleInputDevice { leftStickLeft.getValue = (): number => 0; const leftStickRight = new InputSourceButton(); leftStickRight.getValue = (): number => 0; - this._leftStick = new InputSourceStick({ up: leftStickUp, down: leftStickDown, left: leftStickLeft, right: leftStickRight }); + self._leftStick = new InputSourceStick({ up: leftStickUp, down: leftStickDown, left: leftStickLeft, right: leftStickRight }); - this._buttonRightStick = new InputSourceButton(); - this._buttonRightStick.getValue = (): number => 0; + self._buttonRightStick = new InputSourceButton(); + self._buttonRightStick.getValue = (): number => 0; const rightStickUp = new InputSourceButton(); rightStickUp.getValue = (): number => 0; const rightStickDown = new InputSourceButton(); @@ -153,48 +154,48 @@ export class HandleInputDevice { rightStickLeft.getValue = (): number => 0; const rightStickRight = new InputSourceButton(); rightStickRight.getValue = (): number => 0; - this._rightStick = new InputSourceStick({ up: rightStickUp, down: rightStickDown, left: rightStickLeft, right: rightStickRight }); - - this._buttonOptions = new InputSourceButton(); - this._buttonOptions.getValue = (): number => 0; - this._buttonStart = new InputSourceButton(); - this._buttonStart.getValue = (): number => 0; - - this._handLeftPosition = new InputSourcePosition(); - this._handLeftPosition.getValue = (): Readonly => Vec3.ZERO; - this._handLeftOrientation = new InputSourceOrientation(); - this._handLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; - - this._handRightPosition = new InputSourcePosition(); - this._handRightPosition.getValue = (): Readonly => Vec3.ZERO; - this._handRightOrientation = new InputSourceOrientation(); - this._handRightOrientation.getValue = (): Readonly => Quat.IDENTITY; - - this._aimLeftPosition = new InputSourcePosition(); - this._aimLeftPosition.getValue = (): Readonly => Vec3.ZERO; - this._aimLeftOrientation = new InputSourceOrientation(); - this._aimLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; - - this._aimRightPosition = new InputSourcePosition(); - this._aimRightPosition.getValue = (): Readonly => Vec3.ZERO; - this._aimRightOrientation = new InputSourceOrientation(); - this._aimRightOrientation.getValue = (): Readonly => Quat.IDENTITY; - - this._touchButtonA = new InputSourceTouch(); - this._touchButtonA.getValue = (): number => 0; - this._touchButtonB = new InputSourceTouch(); - this._touchButtonB.getValue = (): number => 0; - this._touchButtonX = new InputSourceTouch(); - this._touchButtonX.getValue = (): number => 0; - this._touchButtonY = new InputSourceTouch(); - this._touchButtonY.getValue = (): number => 0; - this._touchButtonTriggerLeft = new InputSourceTouch(); - this._touchButtonTriggerLeft.getValue = (): number => 0; - this._touchButtonTriggerRight = new InputSourceTouch(); - this._touchButtonTriggerRight.getValue = (): number => 0; - this._touchButtonThumbStickLeft = new InputSourceTouch(); - this._touchButtonThumbStickLeft.getValue = (): number => 0; - this._touchButtonThumbStickRight = new InputSourceTouch(); - this._touchButtonThumbStickRight.getValue = (): number => 0; + self._rightStick = new InputSourceStick({ up: rightStickUp, down: rightStickDown, left: rightStickLeft, right: rightStickRight }); + + self._buttonOptions = new InputSourceButton(); + self._buttonOptions.getValue = (): number => 0; + self._buttonStart = new InputSourceButton(); + self._buttonStart.getValue = (): number => 0; + + self._handLeftPosition = new InputSourcePosition(); + self._handLeftPosition.getValue = (): Readonly => Vec3.ZERO; + self._handLeftOrientation = new InputSourceOrientation(); + self._handLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; + + self._handRightPosition = new InputSourcePosition(); + self._handRightPosition.getValue = (): Readonly => Vec3.ZERO; + self._handRightOrientation = new InputSourceOrientation(); + self._handRightOrientation.getValue = (): Readonly => Quat.IDENTITY; + + self._aimLeftPosition = new InputSourcePosition(); + self._aimLeftPosition.getValue = (): Readonly => Vec3.ZERO; + self._aimLeftOrientation = new InputSourceOrientation(); + self._aimLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; + + self._aimRightPosition = new InputSourcePosition(); + self._aimRightPosition.getValue = (): Readonly => Vec3.ZERO; + self._aimRightOrientation = new InputSourceOrientation(); + self._aimRightOrientation.getValue = (): Readonly => Quat.IDENTITY; + + self._touchButtonA = new InputSourceTouch(); + self._touchButtonA.getValue = (): number => 0; + self._touchButtonB = new InputSourceTouch(); + self._touchButtonB.getValue = (): number => 0; + self._touchButtonX = new InputSourceTouch(); + self._touchButtonX.getValue = (): number => 0; + self._touchButtonY = new InputSourceTouch(); + self._touchButtonY.getValue = (): number => 0; + self._touchButtonTriggerLeft = new InputSourceTouch(); + self._touchButtonTriggerLeft.getValue = (): number => 0; + self._touchButtonTriggerRight = new InputSourceTouch(); + self._touchButtonTriggerRight.getValue = (): number => 0; + self._touchButtonThumbStickLeft = new InputSourceTouch(); + self._touchButtonThumbStickLeft.getValue = (): number => 0; + self._touchButtonThumbStickRight = new InputSourceTouch(); + self._touchButtonThumbStickRight.getValue = (): number => 0; } } diff --git a/pal/input/minigame/hmd-input.ts b/pal/input/minigame/hmd-input.ts index 20ebe8a167e..0ff04bd1cf6 100644 --- a/pal/input/minigame/hmd-input.ts +++ b/pal/input/minigame/hmd-input.ts @@ -57,19 +57,20 @@ export class HMDInputDevice { } private _initInputSource (): void { - this._viewLeftPosition = new InputSourcePosition(); - this._viewLeftPosition.getValue = (): Readonly => Vec3.ZERO; - this._viewLeftOrientation = new InputSourceOrientation(); - this._viewLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; + const self = this; + self._viewLeftPosition = new InputSourcePosition(); + self._viewLeftPosition.getValue = (): Readonly => Vec3.ZERO; + self._viewLeftOrientation = new InputSourceOrientation(); + self._viewLeftOrientation.getValue = (): Readonly => Quat.IDENTITY; - this._viewRightPosition = new InputSourcePosition(); - this._viewRightPosition.getValue = (): Readonly => Vec3.ZERO; - this._viewRightOrientation = new InputSourceOrientation(); - this._viewRightOrientation.getValue = (): Readonly => Quat.IDENTITY; + self._viewRightPosition = new InputSourcePosition(); + self._viewRightPosition.getValue = (): Readonly => Vec3.ZERO; + self._viewRightOrientation = new InputSourceOrientation(); + self._viewRightOrientation.getValue = (): Readonly => Quat.IDENTITY; - this._headMiddlePosition = new InputSourcePosition(); - this._headMiddlePosition.getValue = (): Readonly => Vec3.ZERO; - this._headMiddleOrientation = new InputSourceOrientation(); - this._headMiddleOrientation.getValue = (): Readonly => Quat.IDENTITY; + self._headMiddlePosition = new InputSourcePosition(); + self._headMiddlePosition.getValue = (): Readonly => Vec3.ZERO; + self._headMiddleOrientation = new InputSourceOrientation(); + self._headMiddleOrientation.getValue = (): Readonly => Quat.IDENTITY; } }