Service / AccountService
AccountService Class
User Account Information Management Service
Table of contents
Methods
addFriend(resp: MGSResponse, userId: string, reason: string): void other |
|---|
| Initiate addFriend to app and obtain callback |
applySharedId(character: Character, id: string, callback: BoolResponse): void other |
| Character data of application sharing ID |
checkVIP(userId: string, gameId: string, callback: (result: string) => void): void other |
| Launch a checkVIP and obtain a callback to query the VIP information of Player |
createSharedId(character: Character, callback: StringResponse): void other |
| Generate Share Id |
dataShowToOther(index: number, isOpen: boolean, callback?: BoolResponse): void other |
| Set whether data is publicly available to other users |
downloadData(character: Character, callback?: BoolResponse VoidResponse, index?: number): void other |
| Download the character appearance and apply it to the current character |
fillAvatar(img: Image): void other |
| Assign avatar to Image variable |
getNickName(): string other |
| Get player nickname |
getUserData(userId: string, index: number, callback: StringResponse): void other |
| Retrieve the user's character image data stored on the server |
getUserId(): string other |
| Get the user ID of the platform, which can be used for the getUserData interface |
getUserInfo(userId: string, gameId: string, callback: (nickname: string, gender: number) => void): void other |
| Initiate getUserInfo and obtain a callback to query the player's nickname and gender |
isFriend(resp: MGSResponse, userId: string): void other |
| If you need to check whether a player is a friend, you can call the isFriend interface to view it |
setUserData(character: Character, dataString: string, callback?: BoolResponse): void other |
| Apply character appearance data to character |
uploadData(character: Character, callback?: BoolResponse VoidResponse, index?: number, openStatus?: number): void other |
| Upload character image resources to the server Character, Hair, UpperCloth, LowerCloth, Gloves, Shoe |
Methods
addFriend
• Static addFriend(resp, userId, reason): void other
Initiate addFriend to app and obtain callback
Parameters
resp MGSResponse | Callback for usage: app |
|---|---|
userId string | Usage: User ID of the player to be added |
reason string | Usage: Reason for application |
Precautions
Only effective when pulled up by app on mobile devices
applySharedId
• Static applySharedId(character, id, callback): void other
Character data of application sharing ID
Parameters
character Character | Usage: character of sharing reload data |
|---|---|
id string | Usage: Share ID |
callback BoolResponse | Callback parameter, true: application successful; False: Application failed |
checkVIP
• Static checkVIP(userId, gameId, callback): void other
Launch a checkVIP and obtain a callback to query the VIP information of Player
Parameters
userId string | Usage: Player UserId |
|---|---|
gameId string | GameId |
callback (result: string) => void | Usage: Return result, whether the player's VIP is normal |
createSharedId
• Static createSharedId(character, callback): void other
Generate Share Id
Parameters
character Character | Usage: character of sharing reload data |
|---|---|
callback StringResponse | Callback parameter, return the generated Id |
dataShowToOther
• Static dataShowToOther(index, isOpen, callback?): void other
Set whether data is publicly available to other users
Parameters
index number | Usage: asset bit (0-5) default: 0, protagonist asset bit |
|---|---|
isOpen boolean | Usage: Is it public |
callback? BoolResponse | Usage: Set successful callback default: No callback |
downloadData
• Static downloadData(character, callback?, index?): void other
Download the character appearance and apply it to the current character
Parameters
character Character | Usage: the character to apply the reload data |
|---|---|
callback? BoolResponse VoidResponse | Usage: Set successful callback default: No callback by default |
index? number | Usage: Character position (0-5) default: 0, protagonist resource position |
fillAvatar
• Static fillAvatar(img): void other
Assign avatar to Image variable
Parameters
img Image | Usage: Need to assign a value to obtain the Image variable of the avatar |
|---|
Precautions
Only effective when pulled up by app
Usage example: Create a script called AccountExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, the user's avatar will be displayed in the upper right corner of the screen, and it will be a white image in PC environment
@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let imgUI = new ImageUI();
AccountService.fillAvatar(imgUI.image);
}
}
class ImageUI {
public image: mw.Image;
constructor() {
this.creatUI();
}
private creatUI() {
// Create a UI object
let ui = UserWidget.newObject();
// Add UI to screen
ui.addToViewport(1);
// Create a canvas component
let rootCanvas = Canvas.newObject();
rootCanvas.size = new Vector2(1920, 1080);
rootCanvas.position = Vector2.zero;
// Set Ui's root canvas to rootCanvas
ui.rootContent = rootCanvas;
// Create a button
this.image = mw.Image.newObject(rootCanvas);
this.image.position = new Vector2(1700, 310);
this.image.size = new Vector2(150, 50);
this.image.visibility = SlateVisibility.Visible;
}
}@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let imgUI = new ImageUI();
AccountService.fillAvatar(imgUI.image);
}
}
class ImageUI {
public image: mw.Image;
constructor() {
this.creatUI();
}
private creatUI() {
// Create a UI object
let ui = UserWidget.newObject();
// Add UI to screen
ui.addToViewport(1);
// Create a canvas component
let rootCanvas = Canvas.newObject();
rootCanvas.size = new Vector2(1920, 1080);
rootCanvas.position = Vector2.zero;
// Set Ui's root canvas to rootCanvas
ui.rootContent = rootCanvas;
// Create a button
this.image = mw.Image.newObject(rootCanvas);
this.image.position = new Vector2(1700, 310);
this.image.size = new Vector2(150, 50);
this.image.visibility = SlateVisibility.Visible;
}
}getNickName
• Static getNickName(): string other
Get player nickname
Returns
string | Nickname? |
|---|
Precautions
Only effective when pulled up by app
Usage example: create a script named AccountExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, the control window will output the user's nickname, which is empty in PC environment
@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let name = AccountService.getNickName();
Console. log ("Get Player's nickname", name);
}
}@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let name = AccountService.getNickName();
Console. log ("Get Player's nickname", name);
}
}getUserData
• Static getUserData(userId, index, callback): void other
Retrieve the user's character image data stored on the server
Parameters
userId string | Usage: User ID |
|---|---|
index number | Usage: asset bits (0-5) |
callback StringResponse | Usage: Return the obtained data string |
Usage example: create a script named AccountExample, place it in the object bar, open the script, modify the original content to the following content, publish the game to run on the real machine, and you will see a humanoid object consistent with the appearance of the Player
@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = await Player.asyncGetLocalPlayer();
let npc = (await GameObject.asyncSpawn({ guid: "NPC" })) as Character;
npc.worldTransform.position = new Vector(0, 0, 200);
AccountService.getUserData(player.userId, 0, async str => {
await TimeUtil.delaySecond(5);
AccountService.setUserData(npc, str, isSuccess => {
player.character.name = isSuccess ? Success ":" Failure ";
})
});
}
}@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = await Player.asyncGetLocalPlayer();
let npc = (await GameObject.asyncSpawn({ guid: "NPC" })) as Character;
npc.worldTransform.position = new Vector(0, 0, 200);
AccountService.getUserData(player.userId, 0, async str => {
await TimeUtil.delaySecond(5);
AccountService.setUserData(npc, str, isSuccess => {
player.character.name = isSuccess ? Success ":" Failure ";
})
});
}
}getUserId
• Static getUserId(): string other
Get the user ID of the platform, which can be used for the getUserData interface
Returns
string | User ID |
|---|
Example usage: Create a script called AccountExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the control window will output the user's UserId
@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let userId = AccountService.getUserId();
Console.log ("Get the platform's user ID", userID);
}
}@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let userId = AccountService.getUserId();
Console.log ("Get the platform's user ID", userID);
}
}getUserInfo
• Static getUserInfo(userId, gameId, callback): void other
Initiate getUserInfo and obtain a callback to query the player's nickname and gender
Parameters
userId string | Usage: Player UserId |
|---|---|
gameId string | GameId |
callback (nickname: string, gender: number) => void | Usage: Return nickname (string) and gender (number) |
isFriend
• Static isFriend(resp, userId): void other
If you need to check whether a player is a friend, you can call the isFriend interface to view it
Parameters
resp MGSResponse | Callback for usage: app |
|---|---|
userId string | Usage: Player UserId to be determined |
Precautions
Only effective when pulled up by app on mobile devices
setUserData
• Static setUserData(character, dataString, callback?): void other
Apply character appearance data to character
Parameters
character Character | Character for dressing |
|---|---|
dataString string | Returned data |
callback? BoolResponse | Usage: Set successful callback default: No callback |
Usage example: create a script named AccountExample, place it in the object bar, open the script, modify the original content to the following content, publish the game to run on the real machine, and you will see a humanoid object consistent with the appearance of the Player
@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = await Player.asyncGetLocalPlayer();
let npc = (await GameObject.asyncSpawn({ guid: "NPC" })) as Character;
npc.worldTransform.position = new Vector(0, 0, 200);
AccountService.getUserData(player.userId, 0, async str => {
await TimeUtil.delaySecond(5);
AccountService.setUserData(npc, str, isSuccess => {
player.character.name = isSuccess ? Success ":" Failure ";
})
});
}
}@Component
export default class AccountExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = await Player.asyncGetLocalPlayer();
let npc = (await GameObject.asyncSpawn({ guid: "NPC" })) as Character;
npc.worldTransform.position = new Vector(0, 0, 200);
AccountService.getUserData(player.userId, 0, async str => {
await TimeUtil.delaySecond(5);
AccountService.setUserData(npc, str, isSuccess => {
player.character.name = isSuccess ? Success ":" Failure ";
})
});
}
}uploadData
• Static uploadData(character, callback?, index?, openStatus?): void other
Upload character image resources to the server Character, Hair, UpperCloth, LowerCloth, Gloves, Shoe
Parameters
character Character | Usage: character to upload reload data |
|---|---|
callback? BoolResponse VoidResponse | Usage: Set successful callback default: No callback by default |
index? number | Usage: Character position (0-5) default: 0, protagonist resource position |
openStatus? number | Usage: development status default: 1, default is open status |
Editor API