创造你的世界
社交
用户信息
4 分
搜索用户信息 可以使用 zepetoworldhelper getuserinfo 函数搜索用户信息。 包含在 userid 中的回调函数,例如完成时间、错误发生时间和字符串数组作为参数传递。 以下是调用 zepetoworldhelper getuserinfo 函数的示例。 zepetoworldhelper getuserinfo(ids, (info users\[]) => { for (let i = 0; i < info length; i++) { console log(`userid ${info\[i] useroid}, name ${info\[i] name}, zepetoid ${info\[i] zepetoid}`); } }, (error) => { console log(error); }); 以下是搜索用户信息的完整示例代码。 使用示例代码时,请将 "userid 1","userid 2" 的值更改为真实的用户id值。 import { zepetoscriptbehaviour } from 'zepeto script'; import { zepetoworldhelper, users } from 'zepeto world'; export default class userinfo extends zepetoscriptbehaviour { start() { let ids string\[] = \["userid 1", "userid 2"]; zepetoworldhelper getuserinfo(ids, (info users\[]) => { for (let i = 0; i < info length; i++) { console log(`userid ${info\[i] useroid}, name ${info\[i] name}, zepetoid ${info\[i] zepetoid}`); } }, (error) => { console log(error); }); } } 导入用户头像 使用 zepetoworldhelper getprofiletexture 函数加载用户的个人资料照片。 从完成时间到错误发生时间的回调函数和 userid 作为参数传递。 以下是调用 zepetoworldhelper getprofiletexture 函数的示例代码。 zepetoworldhelper getprofiletexture(this userid, (texture texture) => { this sampleimage sprite = this getsprite(texture); }, (error) => { console log(error); }); 以下是导入用户个人资料照片的示例代码。 import { zepetoscriptbehaviour } from 'zepeto script'; import { zepetoworldhelper } from 'zepeto world'; import { texture,texture2d, sprite, rect, vector2 } from 'unityengine'; import { image } from 'unityengine ui'; export default class gettextureexample extends zepetoscriptbehaviour { public userid string; public sampleimage image; start() { zepetoworldhelper getprofiletexture(this userid, (texture texture) => { this sampleimage sprite = this getsprite(texture); }, (error) => { console log(error); }); } getsprite(texture texture) { let rect rect = new rect(0, 0, texture width, texture height); return sprite create(texture as texture2d, rect, new vector2(0 5, 0 5)); } }