using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace Assets.MyGame.Scripts.Net.WebResponses.ChineseChess
{
[Serializable]
public class ChineseChessGameClassList
{
///
/// 创建房间参数
///
public class CreateRoomParam
{
///
/// 房间id
///
public string roomId { get; set; }
///
/// 用户ID
///
public string userId { get; set; }
///
/// 游戏类型 1 我方黑 2 我方红
///
public int gameType { get; set; }
///
/// 密码,可为空字符串
///
public string password { get; set; }
///
/// 金币数量
///
public int gold { get; set; } = 1000;
}
[Serializable]
///
/// 游戏房间
///
public class ChessGameRoom
{
///
/// 用户列表
///
public List users { get; set; } = new List();
///
/// 房间id
///
public string roomId { get; set; }
///
/// 创建时间
///
public DateTime createTime { get; set; }
///
/// 游戏类型 1 房主黑 2 房主红
///
public int gameType { get; set; }
///
/// 密码,可为空字符串
///
public string password { get; set; }
///
/// 创建者id
///
public string createUserId { get; set; }
///
/// 状态 1 未开始 2 进行中 3 已结束
///
public int state { get; set; } = 1;
///
/// 金币数量
///
public int gold { get; set; } = 1000;
}
[Serializable]
///
/// 缓存中的游戏用户模型
///
public class RedisGameUser
{
//下载头像 失败最多重试5次
public IEnumerator DownTexture2d(System.Action action)
{
string url = userAvatar;
int downCount = 5;
Texture2D avatarTexture2D = new Texture2D(100, 100);
//if (avatarTexture2D == null)
for (int i = 0; i < downCount; i++)
{
using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(url))
{
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError ||
www.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError("下载失败: " + www.error);
downCount++;
if (downCount == 5)
{
action.Invoke(new Texture2D(100, 100));
yield break;
}
}
else
{
avatarTexture2D = DownloadHandlerTexture.GetContent(www);
break;
}
}
}
action.Invoke(avatarTexture2D);
}
///
/// 链接Id
///
public string cid { get; set; }
///
/// 用户ID
///
public string userId { get; set; }
///
/// 用户名称
///
public string userName { get; set; }
///
/// 用户头像
///
public string userAvatar { get; set; }
///
/// 用户类型 1 黑方 2 红方
///
public int type { get; set; }
///
/// 是否掉线
///
public bool isLeave { get; set; } = false;
///
/// 是否准备
///
public bool isReady { get; set; } = false;
///
/// 金币数量
///
public int gold { get; set; } = 0;
}
}
}