Skip to content
WindowUtil

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.

ts
@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

Static get 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.

Returns

MulticastDelegate<() => void>

onFocus

Static get 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.

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
@Component
export default class NewScript extends Script {

     protected onStart(): void {
         WindowUtil. onDefocused. add (()=>{console. log ("Game window out of focus, screen cut out")});
         WindowUtil.onFocused. add()=>{console. log ("Game window focused, screen displayed")};
     }
 }
@Component
export default class NewScript extends Script {

     protected onStart(): void {
         WindowUtil. onDefocused. add (()=>{console. log ("Game window out of focus, screen cut out")});
         WindowUtil.onFocused. add()=>{console. log ("Game window focused, screen displayed")};
     }
 }

Returns

MulticastDelegate<() => void>

screenSize

Static get screenSize(): Vector2 other

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
let viewportSize = WindowUtil.screenSize;
console.log(`viewportSize ${viewportSize}`);

// The printed output is: X=1920 Y=1080
let viewportSize = WindowUtil.screenSize;
console.log(`viewportSize ${viewportSize}`);

// The printed output is: X=1920 Y=1080

Returns

Vector2Return the resolution size of the screen.

Methods