HomeProxy.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using XRTool.Util;
  5. using System;
  6. using ShadowStudio.Model;
  7. using Studio.Scripts.HttpMessage;
  8. /********************************************************************************
  9. ** Company: YC
  10. ** auth: CaoTing
  11. ** date: 2021\5
  12. ** desc: 处理home room事务
  13. *******************************************************************************/
  14. namespace Studio.Scripts
  15. {
  16. public class HomeProxy : UnitySingleton<HomeProxy>
  17. {
  18. public Action<int> CreateRoomAction;
  19. public Action<int> DeleteRoomAction;
  20. public Action UpdateSettingsAction;
  21. public Action<MySetting> GetSettingsAction;
  22. /// <summary>
  23. /// 文件存储地址获取
  24. /// </summary>
  25. public Action<string> GetFileAddressAction;
  26. /// <summary>
  27. /// 获取资源列表
  28. /// </summary>
  29. public Action<List<ArtInfo>> GetArtListAction;
  30. /// <summary>
  31. /// 获取资源
  32. /// </summary>
  33. public Action<ArtInfo> GetArtDetailAction;
  34. /// <summary>
  35. /// 搜索资源列表
  36. /// </summary>
  37. public Action<List<ArtInfo>> SearchArtListAction;
  38. /// <summary>
  39. /// 搜索资源无资源
  40. /// </summary>
  41. public Action NoArtReturnAction;
  42. /// <summary>
  43. /// ArtInfoMgr 专用的一个回调
  44. /// </summary>
  45. private Action<ArtInfo> _artDetailAction;
  46. private bool _isCreatePrivateRomm = true;
  47. public bool IsCreatePrivateRoom { get => _isCreatePrivateRomm; }
  48. /// <summary>
  49. /// 资源列表
  50. /// </summary>
  51. public List<ArtInfo> ArtList { get => _artList; }
  52. /// <summary>
  53. /// 资源列表
  54. /// </summary>
  55. private List<ArtInfo> _artList ;
  56. private MySetting _mySetting;
  57. public MySetting my_MySetting
  58. {
  59. get => _mySetting;
  60. }
  61. public void IsOpenPrivateOrPublicRoom(bool isPrivate)
  62. {
  63. _isCreatePrivateRomm = isPrivate;
  64. }
  65. private void Start()
  66. {
  67. _artList = new List<ArtInfo>();
  68. }
  69. public void GetModelList()
  70. {
  71. Studio.Scripts.HomeProxy.Instance.RequestFileAddress();
  72. }
  73. /// <summary>
  74. /// 根据资源id获取资源具体信息
  75. /// </summary>
  76. /// <param name="artID"></param>
  77. /// <param name="artInfoAction"></param>
  78. public void GetArtInfoDetailByArtID(string artID,Action<ArtInfo> artInfoAction)
  79. {
  80. RequestArtDetail(artID);
  81. _artDetailAction = artInfoAction;
  82. GetArtDetailAction += _artDetailAction;
  83. }
  84. #region 请求服务器数据
  85. /// <summary>
  86. /// 修改我的设置
  87. /// </summary>
  88. public void RequestUpdateSettings(bool isOpenCamera, bool isOpenMic, RatioType ratioType , FpsType fpsType)
  89. {
  90. NetWorkHeaders.Instance.UpdateSettings(UserInfo.User_Token,isOpenCamera,isOpenMic,ratioType,fpsType);
  91. }
  92. /// <summary>
  93. /// 修改我的设置
  94. /// </summary>
  95. public void RequestUpdateSettings(int fmss)
  96. {
  97. NetWorkHeaders.Instance.UpdateSettings(UserInfo.User_Token, fmss);
  98. }
  99. /// <summary>
  100. /// 获取房间设置
  101. /// </summary>
  102. public void RequestGetSettings()
  103. {
  104. NetWorkHeaders.Instance.GetSettings(UserInfo.User_Token);
  105. }
  106. /// <summary>
  107. /// 创建房间
  108. /// </summary>
  109. /// <param name="roomType">1:个人 2:公开</param>
  110. /// <param name="roomName">房间名</param>
  111. /// <param name="roomExplain">房间信息说明</param>
  112. /// <param name="roomPassword">房间密码</param>
  113. /// <param name="publicRoomType">公开房间类型 1 是只能浏览 2是 全功能</param>
  114. public void RequestCreateRoom(int roomType, string roomName = "", string roomExplain = "", string roomPassword = "", int publicRoomType = 1,int roomMaxNum=3)
  115. {
  116. NetWorkHeaders.Instance.CreateRoom(UserInfo.User_Token, roomType, roomName, roomExplain, roomPassword, roomMaxNum, publicRoomType);
  117. }
  118. public void RequestCreateRoom(string roomName = "", string roomExplain = "", string roomPassword = "", int publicRoomType = 1, int roomMaxNum = 3)
  119. {
  120. NetWorkHeaders.Instance.CreateRoom(UserInfo.User_Token, _isCreatePrivateRomm?1:2, roomName, roomExplain, roomPassword, _isCreatePrivateRomm?1: roomMaxNum, publicRoomType);
  121. }
  122. /// <summary>
  123. /// 删除房间
  124. /// </summary>
  125. /// <param name="roomID"></param>
  126. public void RequestDeleteRoom(int roomID)
  127. {
  128. NetWorkHeaders.Instance.DeleteRoom(roomID,UserInfo.User_Token);
  129. }
  130. /// <summary>
  131. /// 文件存储地址获取
  132. /// </summary>
  133. public void RequestFileAddress()
  134. {
  135. NetWorkHeaders.Instance.GetFileAddress(UserInfo.User_Token);
  136. }
  137. /// <summary>
  138. /// 获取资源列表
  139. /// </summary>
  140. /// <param name="searchInput"></param>
  141. public void RequestGetArtList(int artType)
  142. {
  143. NetWorkHeaders.Instance.GetArtList(UserInfo.User_Token, artType);
  144. }
  145. /// <summary>
  146. /// 获取资源详情
  147. /// </summary>
  148. /// <param name="artID"></param>
  149. public void RequestArtDetail(string artID )
  150. {
  151. NetWorkHeaders.Instance.GetDetailAir(UserInfo.User_Token, artID);
  152. }
  153. /// <summary>
  154. /// 搜索资源列表
  155. /// </summary>
  156. /// <param name="artType"></param>
  157. /// <param name="fileType"></param>
  158. /// <param name="keywords"></param>
  159. public void RequestSearchArtList(int artType, int fileType, string keywords = "")
  160. {
  161. NetWorkHeaders.Instance.SearchArtList(UserInfo.User_Token, artType, fileType, keywords);
  162. }
  163. #endregion
  164. #region http respond
  165. /// <summary>
  166. /// 更新设置
  167. /// </summary>
  168. /// <param name="updateRoomCallBackMessage"></param>
  169. public void UpdateSettingsHandler(UpdateSettingsCallBackMessage updateRoomCallBackMessage)
  170. {
  171. UpdateSettingsCallBackData data = updateRoomCallBackMessage.data;
  172. if (UpdateSettingsAction != null)
  173. {
  174. UpdateSettingsAction();
  175. }
  176. }
  177. /// <summary>
  178. /// 获取设置
  179. /// </summary>
  180. /// <param name="getSettingsCallBackMessage"></param>
  181. public void GetSettingsHandler(GetSettingsCallBackMessage getSettingsCallBackMessage)
  182. {
  183. GetSettingsCallBackData data = getSettingsCallBackMessage.data;
  184. _mySetting = new MySetting(data.camera, data.mic, (int)data.ratio, (int)data.fps, (int)data.isActivate,(int)data.fmss);
  185. GetSettingsAction?.Invoke(_mySetting);
  186. }
  187. /// <summary>
  188. /// 创建房间
  189. /// </summary>
  190. /// <param name="createRoomCallBackMessage"></param>
  191. public void CreateRoomHandler(CreateRoomCallBackMessage createRoomCallBackMessage)
  192. {
  193. CreateRoomCallBackData data = createRoomCallBackMessage.data;
  194. if (CreateRoomAction != null)
  195. {
  196. CreateRoomAction(data.roomID);
  197. }
  198. }
  199. /// <summary>
  200. /// 删除房间
  201. /// </summary>
  202. /// <param name="deleteRoomCallBackMessage"></param>
  203. public void DeleteRoomHandler(DeleteRoomCallBackMessage deleteRoomCallBackMessage)
  204. {
  205. DeleteRoomCallBackData data = deleteRoomCallBackMessage.data;
  206. if (DeleteRoomAction != null)
  207. {
  208. DeleteRoomAction(data.roomID);
  209. }
  210. }
  211. /// <summary>
  212. /// 文件存储地址回调
  213. /// </summary>
  214. /// <param name="fileAddressCallBackMessage"></param>
  215. public void GetFileAddressHandler(FileAddressCallBackMessage fileAddressCallBackMessage)
  216. {
  217. ResourcesManager.ArtServerPath = fileAddressCallBackMessage.data.fileAddress;
  218. //不知道为什么是7,老项目就是7
  219. for (int i = 0; i < 7; i++)
  220. {
  221. RequestGetArtList(i);
  222. }
  223. if (GetFileAddressAction != null)
  224. {
  225. GetFileAddressAction(fileAddressCallBackMessage.data.fileAddress);
  226. }
  227. }
  228. /// <summary>
  229. /// 获取资源列表
  230. /// </summary>
  231. /// <param name="getArtListCallBackMessage"></param>
  232. public void GetArtListHandler(GetArtListCallBackMessage getArtListCallBackMessage)
  233. {
  234. if (getArtListCallBackMessage.data.result != null && getArtListCallBackMessage.data.result.Count > 0)
  235. {
  236. _artList.AddRange(this.GetArtInfoListByArtCallBackDatas(getArtListCallBackMessage.data.result));
  237. CommonMethod.SetArtInfoList(_artList);
  238. if (GetArtListAction != null)
  239. {
  240. GetArtListAction(_artList);
  241. }
  242. }
  243. }
  244. /// <summary>
  245. /// 获取资源详情回调
  246. /// </summary>
  247. /// <param name="getArtDetailCallBackMessage"></param>
  248. public void GetArtDetailHandler(GetArtDetailCallBackMessage getArtDetailCallBackMessage)
  249. {
  250. ArtCallBackData data = getArtDetailCallBackMessage.data;
  251. ArtInfo artInfo =this.GetArtInfoByArtCallBackData(data);
  252. if (GetArtDetailAction != null)
  253. {
  254. GetArtDetailAction(artInfo);
  255. if (Array.IndexOf(GetArtDetailAction.GetInvocationList(), _artDetailAction) >= 0)
  256. {
  257. //GetArtDetailAction -= _artDetailAction;
  258. }
  259. }
  260. }
  261. /// <summary>
  262. /// 搜索资源列表的回调
  263. /// </summary>
  264. /// <param name="searchArtListCallBackMessage"></param>
  265. public void SearchArtListHandler(SearchArtListCallBackMessage searchArtListCallBackMessage)
  266. {
  267. if (searchArtListCallBackMessage.data.list != null && searchArtListCallBackMessage.data.list.Count > 0)
  268. {
  269. SearchArtListAction?.Invoke(this.GetArtInfoListByArtCallBackDatas(searchArtListCallBackMessage.data.list));
  270. }
  271. }
  272. #endregion
  273. /// <summary>
  274. /// 错误信息汇总
  275. /// </summary>
  276. /// <param name="messageType"></param>
  277. /// <param name="code"></param>
  278. /// <param name="codeMessage"></param>
  279. /// <param name="loginNum"></param>
  280. public void HomeErrorHandler(MessageType messageType, int code, string codeMessage)
  281. {
  282. if (code == 5018)
  283. {
  284. NoArtReturnAction?.Invoke();
  285. }
  286. }
  287. }
  288. }