# TapBattleClient.UpdatePlayerCustomStatus
# 功能描述
更新玩家自定义状态,如准备/未准备状态。状态是一个整数值,可以自定义含义。更新后房间内所有玩家(包括发送者自己)会收到OnPlayerCustomStatusChanged事件。
# 方法签名
public static void UpdatePlayerCustomStatus(UpdatePlayerCustomStatusOption option)
# 参数说明
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| data | UpdatePlayerCustomStatusData | 是 | 状态更新数据 |
| success | Action<TapCallbackResult> | 否 | 更新成功回调 |
| fail | Action<TapCallbackResult> | 否 | 更新失败回调 |
# UpdatePlayerCustomStatusData
| 字段名 | 类型 | 说明 |
|---|---|---|
| customStatus | int | 自定义状态值(如0=未准备,1=已准备) |
# 使用说明
# 注意事项
- 事件通知 - 更新后房间内所有玩家(包括发送者自己)都会收到OnPlayerCustomStatusChanged事件
- 房间内可用 - 必须在房间内才能更新玩家状态
- 自定义含义 - 状态值的含义由开发者自行定义,SDK不做限制
# 代码示例
# 示例1:切换准备状态
using UnityEngine;
public class ReadyStatusController : MonoBehaviour
{
private int myStatus = 0; // 0=未准备,1=已准备
public void ToggleReady()
{
myStatus = (myStatus == 0) ? 1 : 0;
TapBattleClient.UpdatePlayerCustomStatus(new UpdatePlayerCustomStatusOption
{
data = new UpdatePlayerCustomStatusData
{
customStatus = myStatus
},
success = (result) => {
Debug.Log($"状态更新成功: {(myStatus == 1 ? "已准备" : "未准备")}");
UpdateReadyButton();
}
});
}
// 收到其他玩家状态变更
public void OnPlayerCustomStatusChanged(PlayerCustomStatusNotification info)
{
Debug.Log($"玩家 {info.player_id} 状态变更为: {info.custom_status}");
UpdatePlayerListUI();
}
private void UpdateReadyButton() { }
private void UpdatePlayerListUI() { }
}
# 示例2:房主检查所有玩家准备状态
using UnityEngine;
public class HostReadyChecker : MonoBehaviour
{
private RoomInfo currentRoom;
public bool AllPlayersReady()
{
foreach (var player in currentRoom.players) {
if (player.status != 1) { // 1=已准备
return false;
}
}
return true;
}
public void CheckAndStartFrameSync()
{
if (AllPlayersReady()) {
Debug.Log("所有玩家已准备,可以开始对战");
TapBattleClient.StartFrameSync(new StartFrameSyncOption { });
}
}
}
