Skip to content
AccountService

服务 / AccountService

AccountService Class

用户账号信息管理服务

Table of contents

Methods

addFriend(resp: MGSResponse, userId: string, reason: string): void
向233发起addFriend并获得回调
applySharedId(character: Character, id: string, callback: BoolResponse): void client
应用分享Id的角色数据
checkVIP(userId: string, gameId: string, callback: (result: string) => void): void
发起checkVIP并获得回调,查询玩家的vip信息
createSharedId(character: Character, callback: StringResponse): void client
生成分享Id
dataShowToOther(index: number, isOpen: boolean, callback?: BoolResponse): void client
设置数据是否公开给其他用户
downloadData(character: Character, callback?: BoolResponse VoidResponse, index?: number): void client
下载角色形象并应用到当前角色身上
fillAvatar(img: Image): void client
将头像赋值到Image变量上
getNickName(): string client
获取玩家昵称
getUserData(userId: string, index: number, callback: StringResponse): void client
获取用户存储在服务器上的角色形象数据
getUserId(): string client
获取平台的用户Id,可以用于getUserData接口
getUserInfo(userId: string, gameId: string, callback: (nickname: string, gender: number) => void): void
发起getUserInfo并获得回调,查询玩家的昵称、性别
isFriend(resp: MGSResponse, userId: string): void
若需要检测玩家是否好友关系,可通过调用isFriend接口进行查看
setUserData(character: Character, dataString: string, callback?: BoolResponse): void client
将角色形象数据应用至角色
uploadData(character: Character, callback?: BoolResponse VoidResponse, index?: number, openStatus?: number): void client
上传角色形象资源到服务器 Character, Hair, UpperCloth, LowerCloth, Gloves, Shoe

Methods

addFriend

Static addFriend(resp, userId, reason): void

向233发起addFriend并获得回调

Parameters

resp MGSResponse233的回调
userId string要加的玩家UserId
reason string申请理由

Precautions

只在移动端由233拉起生效


applySharedId

Static applySharedId(character, id, callback): void client

应用分享Id的角色数据

Parameters

character Character分享换装数据的角色
id string分享Id
callback BoolResponse回调参数,true:应用成功;false:应用失败

checkVIP

Static checkVIP(userId, gameId, callback): void

发起checkVIP并获得回调,查询玩家的vip信息

Parameters

userId string玩家UserId
gameId stringGameId
callback (result: string) => void返回 result,玩家的vip是否正常

createSharedId

Static createSharedId(character, callback): void client

生成分享Id

Parameters

character Character分享换装数据的角色
callback StringResponse回调参数,返回生成的Id

dataShowToOther

Static dataShowToOther(index, isOpen, callback?): void client

设置数据是否公开给其他用户

Parameters

index number资源位(0-5) default:0,主角资源位
isOpen boolean是否公开
callback? BoolResponse设置是否成功的回调 default:无回调

downloadData

Static downloadData(character, callback?, index?): void client

下载角色形象并应用到当前角色身上

Parameters

character Character要应用换装数据的角色
callback? BoolResponse VoidResponse设置是否成功的回调 default:默认没有回调
index? number角色位(0-5) default:0,主角资源位

fillAvatar

Static fillAvatar(img): void client

将头像赋值到Image变量上

Parameters

img Image需要赋值获得头像的Image变量

Precautions

只在由233拉起生效

使用示例:创建一个名为AccountExample的脚本,放置在对象栏中,打开脚本,将原本内容修改为如下内容,保存并运行游戏,会在屏幕右上方显示用户的头像,PC环境下为白图
ts
@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() {
        // 创建一个UI对象
        let ui = UserWidget.newObject();
        // 将UI添加到屏幕上
        ui.addToViewport(1);
        // 创建一个画布组件
        let rootCanvas = Canvas.newObject();
        rootCanvas.size = new Vector2(1920, 1080);
        rootCanvas.position = Vector2.zero;
        // 将Ui的根画布设置为rootCanvas
        ui.rootContent = rootCanvas;
        // 创建一个按钮
        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() {
        // 创建一个UI对象
        let ui = UserWidget.newObject();
        // 将UI添加到屏幕上
        ui.addToViewport(1);
        // 创建一个画布组件
        let rootCanvas = Canvas.newObject();
        rootCanvas.size = new Vector2(1920, 1080);
        rootCanvas.position = Vector2.zero;
        // 将Ui的根画布设置为rootCanvas
        ui.rootContent = rootCanvas;
        // 创建一个按钮
        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 client

获取玩家昵称

Returns

string昵称

Precautions

只在由233拉起生效

使用示例:创建一个名为AccountExample的脚本,放置在对象栏中,打开脚本,将原本内容修改为如下内容,保存并运行游戏,控制窗口会输出用户的昵称,PC环境下为空
ts
@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("获取玩家昵称", 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("获取玩家昵称", name);
    }

}

getUserData

Static getUserData(userId, index, callback): void client

获取用户存储在服务器上的角色形象数据

Parameters

userId string用户Id
index number资源位(0-5)
callback StringResponse返回获取的数据string.
使用示例:创建一个名为AccountExample的脚本,放置在对象栏中,打开脚本,将原本内容修改为如下内容,发布在真机上运行游戏,会看到一个和玩家形象一致的人形对象
ts
@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 ? "成功" : "失败";
            })
        });
    }
}
@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 ? "成功" : "失败";
            })
        });
    }
}

getUserId

Static getUserId(): string client

获取平台的用户Id,可以用于getUserData接口

Returns

string用户Id
使用示例:创建一个名为AccountExample的脚本,放置在对象栏中,打开脚本,将原本内容修改为如下内容,保存并运行游戏,控制窗口会输出用户的UserId
ts
@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("获取平台的用户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("获取平台的用户Id", userId);
    }
}

getUserInfo

Static getUserInfo(userId, gameId, callback): void

发起getUserInfo并获得回调,查询玩家的昵称、性别

Parameters

userId string玩家UserId
gameId stringGameId
callback (nickname: string, gender: number) => void返回 nickname(string) 和 gender(number)

isFriend

Static isFriend(resp, userId): void

若需要检测玩家是否好友关系,可通过调用isFriend接口进行查看

Parameters

resp MGSResponse233的回调
userId string要确定的玩家UserId

Precautions

只在移动端由233拉起生效


setUserData

Static setUserData(character, dataString, callback?): void client

将角色形象数据应用至角色

Parameters

character Character用于换装的角色
dataString string返回的数据
callback? BoolResponse设置是否成功的回调 default:无回调
使用示例:创建一个名为AccountExample的脚本,放置在对象栏中,打开脚本,将原本内容修改为如下内容,发布在真机上运行游戏,会看到一个和玩家形象一致的人形对象
ts
@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 ? "成功" : "失败";
            })
        });
    }
}
@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 ? "成功" : "失败";
            })
        });
    }
}

uploadData

Static uploadData(character, callback?, index?, openStatus?): void client

上传角色形象资源到服务器 Character, Hair, UpperCloth, LowerCloth, Gloves, Shoe

Parameters

character Character要上传换装数据的角色
callback? BoolResponse VoidResponse设置是否成功的回调 default:默认没有回调
index? number角色位(0-5) default:0,主角资源位
openStatus? number开发状态 default:1,默认是开放状态