# TapBattleClient.UpdatePlayerCustomProperties
# 功能描述
更新玩家自定义属性,如昵称、等级、头像等。属性是JSON字符串格式,最大2048字节。更新后房间内所有玩家(包括发送者自己)会收到OnPlayerCustomPropertiesChanged事件。
# 方法签名
public static void UpdatePlayerCustomProperties(UpdatePlayerCustomPropertiesOption option)
# 参数说明
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| data | UpdatePlayerCustomPropertiesData | 是 | 属性更新数据 |
| success | Action<TapCallbackResult> | 否 | 更新成功回调 |
| fail | Action<TapCallbackResult> | 否 | 更新失败回调 |
# UpdatePlayerCustomPropertiesData
| 字段名 | 类型 | 说明 |
|---|---|---|
| customProperties | string | 自定义属性(JSON字符串,最大2048字节) |
# 使用说明
# 注意事项
- 事件通知 - 更新后房间内所有玩家(包括发送者自己)都会收到OnPlayerCustomPropertiesChanged事件
- JSON格式 - 属性必须是合法的JSON字符串格式
- 大小限制 - 最大2048字节
- 房间内可用 - 必须在房间内才能更新玩家属性
# 代码示例
# 示例:更新玩家信息
using UnityEngine;
public class PlayerInfoUpdater : MonoBehaviour
{
public void UpdateMyInfo(string nickname, int level, string avatarId)
{
var properties = new {
nickname = nickname,
level = level,
avatarId = avatarId,
vipLevel = 3
};
TapBattleClient.UpdatePlayerCustomProperties(new UpdatePlayerCustomPropertiesOption
{
data = new UpdatePlayerCustomPropertiesData
{
customProperties = JsonUtility.ToJson(properties)
},
success = (result) => {
Debug.Log("玩家信息更新成功");
}
});
}
public void OnPlayerCustomPropertiesChanged(PlayerCustomPropertiesNotification info)
{
Debug.Log($"玩家 {info.player_id} 更新了属性: {info.custom_properties}");
// 更新UI显示
}
}
