Utils / SystemUtil
SystemUtil Class
Status information acquisition tool
Determine whether the current environment status is client, server, or mobile. Obtain version number and other information
Table of contents
Properties
currentPlatform: RuntimePlatform other |
---|
Determine the operating platform of the current program and refer to Type for the return value RuntimePlatform |
isPIE: boolean other |
Determine whether the current mode is in editor running mode |
Accessors
onExit(): MulticastDelegate <() => void > other |
---|
Add callback function executed when exiting the game |
onPause(): MulticastDelegate <() => void > other |
Add the callback function to be executed at the beginning of PnP ause |
onResume(): MulticastDelegate <(leaveDuration : any ) => void > other |
Add callback function to execute at the end of PnP ause |
roomId(): string other |
Retrieve the current room ID. If it is a single player game, return null |
sceneId(): string other |
Get the SceneId of the current scene |
Methods
closeLoadingView(): void other |
---|
Shut down the engine and initialize the UI |
getCurrentEnv(): string other |
Get the current environment |
getEditorVersion(): string other |
Get editor version number |
getFullEditorVersion(): string other |
Get the complete editor version number |
getGameId(): string other |
Get the current game GameId |
getVersion(): string other |
Get the current game version |
isClient(): boolean other |
Is the client running |
isMobile(): boolean other |
Determine whether it is currently a mobile device |
isServer(): boolean other |
Is the server running |
Properties
currentPlatform
▪ Static
currentPlatform: RuntimePlatform
other
Determine the operating platform of the current program and refer to Type for the return value RuntimePlatform
Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the current running environment will be printed to the console
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console.log ("current program's running platform", SystemUtil.currentPlatform)
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console.log ("current program's running platform", SystemUtil.currentPlatform)
}
}
isPIE
▪ Static
isPIE: boolean
other
Determine whether the current mode is in editor running mode
Accessors
onExit
• | ||
---|---|---|
Add callback function executed when exiting the game Returns
|
onPause
• | ||
---|---|---|
Add the callback function to be executed at the beginning of PnP ause Precautions It only works on Android and iOS. The triggering timing includes entering the background, closing the screen, and playing advertisements. Some models will not pause the game when they switch to the background, so the callback will not be triggered or the pause time is very short, which can be judged by whether the game background music continues to play. Returns
|
onResume
• | ||
---|---|---|
Add callback function to execute at the end of PnP ause Precautions It only works on Android and iOS. Triggering opportunities include cutting into the background, information screen and returning to the game after broadcasting Ads. Some models will not pause the game when they switch to the background, so the callback will not be triggered or the pause time is very short, which can be judged by whether the game background music continues to play. Returns
|
roomId
• | ||
---|---|---|
Retrieve the current room ID. If it is a single player game, return null Usage example: create a script named SystemExample, place it in the object bar, open the script, modify the original content as follows, save and run the game, output the current room ID, and if it is a stand-alone game, output null ts
Returns
|
sceneId
• |
---|
Get the SceneId of the current scene Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and output the SceneId of the current scene ts
Returns |
string | SceneId of the current scene |
---|
Methods
closeLoadingView
• Static
closeLoadingView(): void
other
Shut down the engine and initialize the UI
Usage example: create a script named SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and close the engine UI when executing
@Component
export default class SystemExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
InputUtil.onKeyDown(Keys.F, () => {
SystemUtil.closeLoadingView();
}))
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
InputUtil.onKeyDown(Keys.F, () => {
SystemUtil.closeLoadingView();
}))
}
}
getCurrentEnv
• Static
getCurrentEnv(): string
other
Get the current environment
Returns
string |
---|
Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the current environment will be printed to the console
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console. log ("current environment", SystemUtil. getCurrentEnv())
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console. log ("current environment", SystemUtil. getCurrentEnv())
}
}
getEditorVersion
• Static
getEditorVersion(): string
other
Get editor version number
Returns
string | Current editor version number |
---|
Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the current editor version number will be printed to the console
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console.log ("current editor version number", SystemUtil. getEditorVersion())
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console.log ("current editor version number", SystemUtil. getEditorVersion())
}
}
getFullEditorVersion
• Static
getFullEditorVersion(): string
other
Get the complete editor version number
Returns
string | Current full editor version number |
---|
Usage example: create a script named SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and print the current full editor version number to the console
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console.log ("current full editor version number", SystemUtil. getFullEditorVersion())
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console.log ("current full editor version number", SystemUtil. getFullEditorVersion())
}
}
getGameId
• Static
getGameId(): string
other
Get the current game GameId
Returns
string | Current Game GameId |
---|
Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, output the current game GameId as empty on the PC end and GameId as empty on the mobile end
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (!SystemUtil.isClient()) return;
const gameId = SystemUtil.getGameId();
console.log(`gameId: ${gameId}`);
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (!SystemUtil.isClient()) return;
const gameId = SystemUtil.getGameId();
console.log(`gameId: ${gameId}`);
}
}
getVersion
• Static
getVersion(): string
other
Get the current game version
Returns
string | Current game version |
---|
Usage example: create a script named SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, output the current game version as empty on the PC side, and output the game version as the mobile side
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (!SystemUtil.isClient()) return;
const version = SystemUtil.getVersion();
console.log(`version: ${version}`);
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (!SystemUtil.isClient()) return;
const version = SystemUtil.getVersion();
console.log(`version: ${version}`);
}
}
isClient
• Static
isClient(): boolean
other
Is the client running
Returns
boolean | Is the client running |
---|
Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the current running environment will be printed to the console
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (SystemUtil.isClient()) {
Console.log ("currently a client");
} else if (SystemUtil.isServer()) {
Console.log ("currently on the server side");
}
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (SystemUtil.isClient()) {
Console.log ("currently a client");
} else if (SystemUtil.isServer()) {
Console.log ("currently on the server side");
}
}
}
isMobile
• Static
isMobile(): boolean
other
Determine whether it is currently a mobile device
Returns
boolean | Is it a mobile device |
---|
Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and print whether it is currently a mobile device to the console
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console. log ("Is it currently a mobile device", SystemUtil. isMobile())
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
Console. log ("Is it currently a mobile device", SystemUtil. isMobile())
}
}
isServer
• Static
isServer(): boolean
other
Is the server running
Returns
boolean | Is the server running |
---|
Example usage: Create a script called SystemExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the current running environment will be printed to the console
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (SystemUtil.isClient()) {
Console.log ("currently a client");
} else if (SystemUtil.isServer()) {
Console.log ("currently on the server side");
}
}
}
@Component
export default class SystemExample extends Script {
protected onStart(): void {
this.test();
}
private async test(): Promise<void> {
if (SystemUtil.isClient()) {
Console.log ("currently a client");
} else if (SystemUtil.isServer()) {
Console.log ("currently on the server side");
}
}
}