服务 / 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 MGSResponse | 233的回调 |
---|---|
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 string | GameId |
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拉起生效
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拉起生效
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. |
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 |
---|
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 string | GameId |
callback (nickname : string , gender : number ) => void | 返回 nickname(string) 和 gender(number) |
isFriend
• Static
isFriend(resp
, userId
): void
若需要检测玩家是否好友关系,可通过调用isFriend接口进行查看
Parameters
resp MGSResponse | 233的回调 |
---|---|
userId string | 要确定的玩家UserId |
Precautions
只在移动端由233拉起生效
setUserData
• Static
setUserData(character
, dataString
, callback?
): void
client
将角色形象数据应用至角色
Parameters
character Character | 用于换装的角色 |
---|---|
dataString string | 返回的数据 |
callback? BoolResponse | 设置是否成功的回调 default:无回调 |
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,默认是开放状态 |