Utils / WindowUtil
WindowUtil Class
Window setting tool.
It can be set to trigger certain behavior when the window is out of focus, and obtain resolution and other functions.
Example usage: Create a script called WindowExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the screen resolution size will be printed on the console.
@Component
export default class WindowExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (!SystemUtil.isClient()) return;
let viewportSize = WindowUtil.getViewportSize();
// X=1920 Y=1080
console.log(`viewportSize ${viewportSize}`);
}
}
@Component
export default class WindowExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (!SystemUtil.isClient()) return;
let viewportSize = WindowUtil.getViewportSize();
// X=1920 Y=1080
console.log(`viewportSize ${viewportSize}`);
}
}
Table of contents
Accessors
onDefocus(): MulticastDelegate <() => void > |
---|
The user's game window is out of focus, and the current game window on the monitor is cut out. Call onDefocused. Returns a multicast delegate type. You can use functions such as Add, Remove, Clear, Broadcast in multicast delegation to write the logic you want when window focus occurs. |
onFocus(): MulticastDelegate <() => void > |
The user's game window is focused, and the display shows the current game window. Call onFocused to return a multicast delegate type. You can use functions such as Add, Remove, Clear, Broadcast in multicast delegation to write the logic you want when window focus occurs. |
screenSize(): Vector2 other |
Obtain the resolution size of the screen (not following the screen scaling changes). |
Methods
Accessors
onDefocus
• | ||
---|---|---|
The user's game window is out of focus, and the current game window on the monitor is cut out. Call onDefocused. Returns a multicast delegate type. You can use functions such as Add, Remove, Clear, Broadcast in multicast delegation to write the logic you want when window focus occurs. Returns
|
onFocus
• | ||
---|---|---|
The user's game window is focused, and the display shows the current game window. Call onFocused to return a multicast delegate type. You can use functions such as Add, Remove, Clear, Broadcast in multicast delegation to write the logic you want when window focus occurs. Usage example: create a script named "NewScript", place it in the object sub level of the object manager, open the script, enter the following code to save, run the game, switch the screen out of the log that will display "Game window out of focus, screen out of focus", and switch the screen back to the log that will display "Game window focus, screen out of focus". ts
Returns
|
screenSize
• |
---|
Obtain the resolution size of the screen (not following the screen scaling changes). This method only takes effect when called by the client. Usage example: Call method ts
Returns |
Vector2 | Return the resolution size of the screen. |
---|