using System.Collections; using System.Collections.Generic; using UnityEngine; using XRTool.Util; using System; using ShadowStudio.Model; using Studio.Scripts.HttpMessage; /******************************************************************************** ** Company: YC ** auth: CaoTing ** date: 2021\5 ** desc: 处理home room事务 *******************************************************************************/ namespace Studio.Scripts { public class HomeProxy : UnitySingleton { public Action CreateRoomAction; public Action DeleteRoomAction; public Action UpdateSettingsAction; public Action GetSettingsAction; /// /// 文件存储地址获取 /// public Action GetFileAddressAction; /// /// 获取资源列表 /// public Action> GetArtListAction; /// /// 获取资源 /// public Action GetArtDetailAction; /// /// 搜索资源列表 /// public Action> SearchArtListAction; /// /// 搜索资源无资源 /// public Action NoArtReturnAction; /// /// ArtInfoMgr 专用的一个回调 /// private Action _artDetailAction; private bool _isCreatePrivateRomm = true; public bool IsCreatePrivateRoom { get => _isCreatePrivateRomm; } /// /// 资源列表 /// public List ArtList { get => _artList; } /// /// 资源列表 /// private List _artList ; private MySetting _mySetting; public MySetting my_MySetting { get => _mySetting; } public void IsOpenPrivateOrPublicRoom(bool isPrivate) { _isCreatePrivateRomm = isPrivate; } private void Start() { _artList = new List(); } public void GetModelList() { Studio.Scripts.HomeProxy.Instance.RequestFileAddress(); } /// /// 根据资源id获取资源具体信息 /// /// /// public void GetArtInfoDetailByArtID(string artID,Action artInfoAction) { RequestArtDetail(artID); _artDetailAction = artInfoAction; GetArtDetailAction += _artDetailAction; } #region 请求服务器数据 /// /// 修改我的设置 /// public void RequestUpdateSettings(bool isOpenCamera, bool isOpenMic, RatioType ratioType , FpsType fpsType) { NetWorkHeaders.Instance.UpdateSettings(UserInfo.User_Token,isOpenCamera,isOpenMic,ratioType,fpsType); } /// /// 修改我的设置 /// public void RequestUpdateSettings(int fmss) { NetWorkHeaders.Instance.UpdateSettings(UserInfo.User_Token, fmss); } /// /// 获取房间设置 /// public void RequestGetSettings() { NetWorkHeaders.Instance.GetSettings(UserInfo.User_Token); } /// /// 创建房间 /// /// 1:个人 2:公开 /// 房间名 /// 房间信息说明 /// 房间密码 /// 公开房间类型 1 是只能浏览 2是 全功能 public void RequestCreateRoom(int roomType, string roomName = "", string roomExplain = "", string roomPassword = "", int publicRoomType = 1,int roomMaxNum=3) { NetWorkHeaders.Instance.CreateRoom(UserInfo.User_Token, roomType, roomName, roomExplain, roomPassword, roomMaxNum, publicRoomType); } public void RequestCreateRoom(string roomName = "", string roomExplain = "", string roomPassword = "", int publicRoomType = 1, int roomMaxNum = 3) { NetWorkHeaders.Instance.CreateRoom(UserInfo.User_Token, _isCreatePrivateRomm?1:2, roomName, roomExplain, roomPassword, _isCreatePrivateRomm?1: roomMaxNum, publicRoomType); } /// /// 删除房间 /// /// public void RequestDeleteRoom(int roomID) { NetWorkHeaders.Instance.DeleteRoom(roomID,UserInfo.User_Token); } /// /// 文件存储地址获取 /// public void RequestFileAddress() { NetWorkHeaders.Instance.GetFileAddress(UserInfo.User_Token); } /// /// 获取资源列表 /// /// public void RequestGetArtList(int artType) { NetWorkHeaders.Instance.GetArtList(UserInfo.User_Token, artType); } /// /// 获取资源详情 /// /// public void RequestArtDetail(string artID ) { NetWorkHeaders.Instance.GetDetailAir(UserInfo.User_Token, artID); } /// /// 搜索资源列表 /// /// /// /// public void RequestSearchArtList(int artType, int fileType, string keywords = "") { NetWorkHeaders.Instance.SearchArtList(UserInfo.User_Token, artType, fileType, keywords); } #endregion #region http respond /// /// 更新设置 /// /// public void UpdateSettingsHandler(UpdateSettingsCallBackMessage updateRoomCallBackMessage) { UpdateSettingsCallBackData data = updateRoomCallBackMessage.data; if (UpdateSettingsAction != null) { UpdateSettingsAction(); } } /// /// 获取设置 /// /// public void GetSettingsHandler(GetSettingsCallBackMessage getSettingsCallBackMessage) { GetSettingsCallBackData data = getSettingsCallBackMessage.data; _mySetting = new MySetting(data.camera, data.mic, (int)data.ratio, (int)data.fps, (int)data.isActivate,(int)data.fmss); GetSettingsAction?.Invoke(_mySetting); } /// /// 创建房间 /// /// public void CreateRoomHandler(CreateRoomCallBackMessage createRoomCallBackMessage) { CreateRoomCallBackData data = createRoomCallBackMessage.data; if (CreateRoomAction != null) { CreateRoomAction(data.roomID); } } /// /// 删除房间 /// /// public void DeleteRoomHandler(DeleteRoomCallBackMessage deleteRoomCallBackMessage) { DeleteRoomCallBackData data = deleteRoomCallBackMessage.data; if (DeleteRoomAction != null) { DeleteRoomAction(data.roomID); } } /// /// 文件存储地址回调 /// /// public void GetFileAddressHandler(FileAddressCallBackMessage fileAddressCallBackMessage) { ResourcesManager.ArtServerPath = fileAddressCallBackMessage.data.fileAddress; //不知道为什么是7,老项目就是7 for (int i = 0; i < 7; i++) { RequestGetArtList(i); } if (GetFileAddressAction != null) { GetFileAddressAction(fileAddressCallBackMessage.data.fileAddress); } } /// /// 获取资源列表 /// /// public void GetArtListHandler(GetArtListCallBackMessage getArtListCallBackMessage) { if (getArtListCallBackMessage.data.result != null && getArtListCallBackMessage.data.result.Count > 0) { _artList.AddRange(this.GetArtInfoListByArtCallBackDatas(getArtListCallBackMessage.data.result)); CommonMethod.SetArtInfoList(_artList); if (GetArtListAction != null) { GetArtListAction(_artList); } } } /// /// 获取资源详情回调 /// /// public void GetArtDetailHandler(GetArtDetailCallBackMessage getArtDetailCallBackMessage) { ArtCallBackData data = getArtDetailCallBackMessage.data; ArtInfo artInfo =this.GetArtInfoByArtCallBackData(data); if (GetArtDetailAction != null) { GetArtDetailAction(artInfo); if (Array.IndexOf(GetArtDetailAction.GetInvocationList(), _artDetailAction) >= 0) { //GetArtDetailAction -= _artDetailAction; } } } /// /// 搜索资源列表的回调 /// /// public void SearchArtListHandler(SearchArtListCallBackMessage searchArtListCallBackMessage) { if (searchArtListCallBackMessage.data.list != null && searchArtListCallBackMessage.data.list.Count > 0) { SearchArtListAction?.Invoke(this.GetArtInfoListByArtCallBackDatas(searchArtListCallBackMessage.data.list)); } } #endregion /// /// 错误信息汇总 /// /// /// /// /// public void HomeErrorHandler(MessageType messageType, int code, string codeMessage) { if (code == 5018) { NoArtReturnAction?.Invoke(); } } } }