MatchingCompetitionSelectView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using ET;
  5. using FairyGUI;
  6. using UI.MatchingCompetition;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. namespace GFGGame
  10. {
  11. class MatchingCompetitionSelectView : BaseWindow
  12. {
  13. private UI_MatchingCompetitionSelectUI _ui;
  14. private int _seasonIndex = 0;
  15. private bool isRefresh = false;
  16. private JudgingRoundOpenCfg judgingCfg;
  17. private GameObject _sceneObjectLeft;
  18. private GameObject _sceneObjectRight;
  19. public override void Dispose()
  20. {
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. }
  25. if (_sceneObjectLeft != null)
  26. {
  27. PrefabManager.Instance.Restore(_sceneObjectLeft);
  28. _sceneObjectLeft = null;
  29. }
  30. if (_sceneObjectRight != null)
  31. {
  32. PrefabManager.Instance.Restore(_sceneObjectRight);
  33. _sceneObjectRight = null;
  34. }
  35. _ui = null;
  36. base.Dispose();
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. packageName = UI_MatchingCompetitionSelectUI.PACKAGE_NAME;
  42. _ui = UI_MatchingCompetitionSelectUI.Create();
  43. this.viewCom = _ui.target;
  44. isReturnView = true;
  45. isfullScreen = true;
  46. _ui.m_BtnBack.onClick.Add(OnClickBtnBack);
  47. _ui.m_select1.target.onClick.Add(OnClickBtnSelect1);
  48. _ui.m_select2.target.onClick.Add(OnClickBtnSelect2);
  49. _ui.m_ruleBtn.onClick.Add(MatchingCompetitionDataManager.Instance.OnClickBtnRule);
  50. }
  51. protected override void OnShown()
  52. {
  53. base.OnShown();
  54. _ui.m_bg.url = ResPathUtil.GetBgImgPath("pxs_bj");
  55. _ui.m_BtnBack.touchable = true;
  56. _ui.m_titleText.text = JudgingRoundOpenCfgArray.Instance.dataArray[MatchingCompetitionDataManager.Instance.MatchingCompetitionSeason - 1].Name;
  57. //isRefresh = (bool)this.viewData;
  58. judgingCfg = JudgingRoundOpenCfgArray.Instance.GetCfg(MatchingCompetitionDataManager.Instance.MatchingCompetitionSeason);
  59. UpdateView();
  60. UpdatePlayer();
  61. //UpdateDressLeft();
  62. ViewManager.Hide<ModalStatusView>();
  63. }
  64. protected override void OnHide()
  65. {
  66. if (_sceneObjectLeft != null)
  67. {
  68. PrefabManager.Instance.Restore(_sceneObjectLeft);
  69. _sceneObjectLeft = null;
  70. }
  71. if (_sceneObjectRight != null)
  72. {
  73. PrefabManager.Instance.Restore(_sceneObjectRight);
  74. _sceneObjectRight = null;
  75. }
  76. base.OnHide();
  77. }
  78. protected override void AddEventListener()
  79. {
  80. base.AddEventListener();
  81. EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdatePlayer);
  82. //EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateDressLeft);
  83. EventAgent.AddEventListener(ConstMessage.REWARDVIEW_CLOTHER, ShowReward);
  84. }
  85. protected override void RemoveEventListener()
  86. {
  87. base.RemoveEventListener();
  88. EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdatePlayer);
  89. //EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateDressLeft);
  90. EventAgent.RemoveEventListener(ConstMessage.REWARDVIEW_CLOTHER, ShowReward);
  91. }
  92. private void ShowReward()
  93. {
  94. if(MatchingCompetitionDataManager.Instance.SpecialBonusList != null && MatchingCompetitionDataManager.Instance.SpecialBonusList.Count > 0)
  95. {
  96. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(MatchingCompetitionDataManager.Instance.SpecialBonusList)); ;
  97. MatchingCompetitionDataManager.Instance.SpecialBonusList = null;
  98. }
  99. }
  100. private async void UpdateDressLeft()
  101. {
  102. //ViewManager.Show<ModalStatusView>("获取搭配数据中...");
  103. MatchingLeftDataManager.Instance.itemGameObjs.Clear();
  104. MatchingRightDataManager.Instance.itemGameObjs.Clear();
  105. PhotographDataManager.Instance.itemGameObjs.Clear();
  106. PhotographDataManager.Instance.dressUpObj?.Dispose();
  107. PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  108. if (_sceneObjectLeft == null)
  109. {
  110. _sceneObjectLeft = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  111. // 创建render texture
  112. renderTexureLeft = new RenderTexture((int)_ui.m_playerShow1.target.width, (int)_ui.m_playerShow2.target.height, 24);
  113. // 换装父节点 + 相机
  114. Camera camera = _sceneObjectLeft.transform.Find("Camera").GetComponent<Camera>();
  115. camera.gameObject.SetActive(true);
  116. camera.targetTexture = renderTexureLeft;
  117. // 创建RawImg
  118. }
  119. PhotographSceneManager.Instance.sceneObject = _sceneObjectLeft;
  120. if (MatchingLeftDataManager.Instance.DressUpBgID == 0)
  121. {
  122. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(180001));
  123. }
  124. else
  125. {
  126. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(MatchingLeftDataManager.Instance.DressUpBgID));
  127. }
  128. PhotographSceneManager.Instance.AddBodyItem(1);
  129. GameObject bodyParent = _sceneObjectLeft.transform.Find("Scene/Role").gameObject;
  130. PhotographDataManager.Instance.dressUpObj.setSceneObj(_sceneObjectLeft, false, true, bodyParent, false, null);
  131. PhotographDataManager.Instance.dressUpObj.PutOnDressUpData(MatchingLeftDataManager.Instance.MathingDressDate);
  132. //对搭配赛特殊处理
  133. for (int i = 0; i < MatchingLeftDataManager.Instance.DressPropIdList.Count; i++)
  134. {
  135. if (MatchingLeftDataManager.Instance.DressPropIdList[i] <= 0)
  136. {
  137. continue;
  138. }
  139. else
  140. {
  141. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(MatchingLeftDataManager.Instance.DressPropIdList[i]);
  142. MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, true,1);
  143. }
  144. }
  145. await Task.Delay(200);
  146. MatchingLeftDataManager.Instance.InsertGameObjectList();
  147. for (int i = 0; i < MatchingLeftDataManager.Instance.TransformDataList.Count; i++)
  148. {
  149. TransformData itemdata = MatchingLeftDataManager.Instance.TransformDataList[i];
  150. GameObject itemGObj = MatchingLeftDataManager.Instance.itemGameObjs[i];
  151. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
  152. if (MatchingLeftDataManager.Instance.itemGameObjs[i].name == "Role")
  153. {
  154. if (itemdata.position.y >= -5 || itemdata.position.y <= 5)
  155. {
  156. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(itemdata.position.x, 0, 0);
  157. }
  158. if (itemdata.position.x >= -5 || itemdata.position.x <= 5)
  159. {
  160. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(0, MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position.y, 0);
  161. }
  162. }
  163. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.Rotate(itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
  164. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
  165. PhotographUtil.Instance.ChangeLayer(MatchingLeftDataManager.Instance.itemGameObjs[i], i * PhotographDataManager.layerCount, "up");
  166. }
  167. PhotographUtil.Instance.ChangeLayer(MatchingLeftDataManager.Instance.roleGameobj, 2 * PhotographDataManager.layerCount, "up");
  168. await Task.Delay(50);
  169. UpdateDressRigh();
  170. }
  171. private async void UpdateDressRigh()
  172. {
  173. MatchingRightDataManager.Instance.itemGameObjs.Clear();
  174. PhotographDataManager.Instance.itemGameObjs.Clear();
  175. PhotographDataManager.Instance.dressUpObj?.Dispose();
  176. PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  177. if (_sceneObjectRight == null)
  178. {
  179. _sceneObjectRight = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  180. // 创建render texture
  181. renderTexureRight = new RenderTexture((int)_ui.m_playerShow1.target.width, (int)_ui.m_playerShow2.target.height, 24);
  182. // 换装父节点 + 相机
  183. Camera camera = _sceneObjectRight.transform.Find("Camera").GetComponent<Camera>();
  184. camera.gameObject.SetActive(true);
  185. camera.targetTexture = renderTexureRight;
  186. }
  187. PhotographSceneManager.Instance.sceneObject = _sceneObjectRight;
  188. if (MatchingRightDataManager.Instance.DressUpBgID == 0)
  189. {
  190. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(180004));
  191. }
  192. else
  193. {
  194. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(MatchingRightDataManager.Instance.DressUpBgID));
  195. }
  196. PhotographSceneManager.Instance.AddBodyItem(2);
  197. GameObject bodyParent = _sceneObjectRight.transform.Find("Scene/Role").gameObject;
  198. PhotographDataManager.Instance.dressUpObj.setSceneObj(_sceneObjectRight, false, true, bodyParent, false, null);
  199. PhotographDataManager.Instance.dressUpObj.PutOnDressUpData(MatchingRightDataManager.Instance.MathingDressDate);
  200. //对搭配赛特殊处理
  201. for (int i = 0; i < MatchingRightDataManager.Instance.DressPropIdList.Count; i++)
  202. {
  203. if (MatchingRightDataManager.Instance.DressPropIdList[i] <= 0)
  204. {
  205. continue;
  206. }
  207. else
  208. {
  209. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(MatchingRightDataManager.Instance.DressPropIdList[i]);
  210. MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, true,2);
  211. }
  212. }
  213. await Task.Delay(200);
  214. MatchingRightDataManager.Instance.InsertGameObjectList();
  215. for (int i = 0; i < MatchingRightDataManager.Instance.TransformDataList.Count; i++)
  216. {
  217. TransformData itemdata = MatchingRightDataManager.Instance.TransformDataList[i];
  218. GameObject itemGObj = MatchingRightDataManager.Instance.itemGameObjs[i];
  219. MatchingRightDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
  220. if (MatchingRightDataManager.Instance.itemGameObjs[i].name == "Role")
  221. {
  222. if (itemdata.position.y >= -5 || itemdata.position.y <= 5)
  223. {
  224. MatchingRightDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(itemdata.position.x, 0, 0);
  225. }
  226. if (itemdata.position.x >= -5 || itemdata.position.x <= 5)
  227. {
  228. MatchingRightDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(0, MatchingRightDataManager.Instance.itemGameObjs[i].transform.position.y, 0);
  229. }
  230. }
  231. MatchingRightDataManager.Instance.itemGameObjs[i].transform.Rotate(itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
  232. MatchingRightDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
  233. PhotographUtil.Instance.ChangeLayer(MatchingRightDataManager.Instance.itemGameObjs[i], i * PhotographDataManager.layerCount, "up");
  234. }
  235. PhotographUtil.Instance.ChangeLayer(MatchingRightDataManager.Instance.roleGameobj, 2 * PhotographDataManager.layerCount, "up");
  236. await Task.Delay(50);
  237. _sceneObjectRight.transform.position = new Vector3(50, 50, 50);
  238. UpdatePlayer();
  239. }
  240. private RenderTexture renderTexureLeft;
  241. private RenderTexture renderTexureRight;
  242. private void UpdatePlayer()
  243. {
  244. //_ui.m_playerShow1.m_playerImage.m_playerImage.texture = new NTexture(renderTexureLeft);
  245. //_ui.m_playerShow2.m_playerImage.m_playerImage.texture = new NTexture(renderTexureRight);
  246. _ui.m_playerShow1.m_playerImage.m_playerImage.texture = MatchingLeftDataManager.Instance.LeftRoleInfo.Ntexture;
  247. _ui.m_playerShow2.m_playerImage.m_playerImage.texture = MatchingRightDataManager.Instance.RightRoleInfo.Ntexture;
  248. MatchingPhotoWorksData otherLeftdata = MatchingLeftDataManager.Instance.LeftRoleInfo;
  249. JudgingRoundRoleInfo otherLeftInfo = otherLeftdata.JudgingInfo;
  250. RoleInfoManager.Instance.UpdateHead(_ui.m_player1.m_head, otherLeftInfo.HeadItemId, otherLeftInfo.HeadBorderItemId);
  251. _ui.m_player1.m_nameText.text = otherLeftInfo.RoleName.ToString();
  252. _ui.m_select1.m_numText.visible = false;
  253. _ui.m_select1.m_numText.text = otherLeftInfo.Score.ToString();
  254. MatchingPhotoWorksData otherRightdata = MatchingRightDataManager.Instance.RightRoleInfo;
  255. JudgingRoundRoleInfo otherRightInfo = otherRightdata.JudgingInfo;
  256. RoleInfoManager.Instance.UpdateHead(_ui.m_player2.m_head, otherRightInfo.HeadItemId, otherRightInfo.HeadBorderItemId);
  257. _ui.m_player2.m_nameText.text = otherRightInfo.RoleName.ToString();
  258. _ui.m_select2.m_numText.visible = false;
  259. _ui.m_select2.m_numText.text = otherRightInfo.Score.ToString();
  260. ViewManager.Hide<ModalStatusView>();
  261. }
  262. private void UpdateView()
  263. {
  264. _ui.m_selectText1.alpha = 0;
  265. _ui.m_selectText2.alpha = 0;
  266. _ui.m_timeText.text = string.Format("剩余次数:{0}",Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  267. }
  268. private void OnClickBtnBack()
  269. {
  270. _ui.m_BtnBack.touchable = true;
  271. ViewManager.GoBackFrom(typeof(MatchingCompetitionSelectView).FullName);
  272. }
  273. private async void OnClickBtnSelect1()
  274. {
  275. if((judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes)<=0)
  276. {
  277. PromptController.Instance.ShowFloatTextPrompt("评选次数不足");
  278. return;
  279. }
  280. bool result = await MatchingCompetitionSproxy.ReqCheckMatchingCompetitionWork(
  281. MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.WorksId,MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.WorksId
  282. ) ;
  283. if(result)
  284. {
  285. _ui.m_select1.m_c1.selectedIndex = 1;
  286. _ui.m_select1.m_numText.visible = true;
  287. _ui.m_select2.m_numText.visible = true;
  288. _ui.m_select1.m_numText.text = string.Format("心动值{0}", MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.Score.ToString());
  289. _ui.m_timeText.text = string.Format("剩余次数:{0}", Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  290. }
  291. _ui.m_t0.Play(async () =>
  292. {
  293. bool resulst = await MatchingCompetitionSproxy.ReqGetTwoPlayers();
  294. if (resulst)
  295. {
  296. if (_sceneObjectLeft != null)
  297. {
  298. PrefabManager.Instance.Restore(_sceneObjectLeft);
  299. _sceneObjectLeft = null;
  300. }
  301. if (_sceneObjectRight != null)
  302. {
  303. PrefabManager.Instance.Restore(_sceneObjectRight);
  304. _sceneObjectRight = null;
  305. }
  306. UpdateDressLeft();
  307. UpdateView();
  308. }
  309. });
  310. }
  311. private async void OnClickBtnSelect2()
  312. {
  313. if ((judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes) <= 0)
  314. {
  315. PromptController.Instance.ShowFloatTextPrompt("评选次数不足");
  316. return;
  317. }
  318. bool result = await MatchingCompetitionSproxy.ReqCheckMatchingCompetitionWork(
  319. MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.WorksId, MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.WorksId
  320. );
  321. if (result)
  322. {
  323. _ui.m_select2.m_c1.selectedIndex = 1;
  324. _ui.m_select1.m_numText.visible = true;
  325. _ui.m_select2.m_numText.visible = true;
  326. _ui.m_select2.m_numText.text = string.Format("心动值{0}", MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.Score.ToString());
  327. _ui.m_timeText.text = string.Format("剩余次数:{0}", Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  328. }
  329. _ui.m_t1.Play(async () =>
  330. {
  331. bool resulst = await MatchingCompetitionSproxy.ReqGetTwoPlayers();
  332. if (resulst)
  333. {
  334. if (_sceneObjectLeft != null)
  335. {
  336. PrefabManager.Instance.Restore(_sceneObjectLeft);
  337. _sceneObjectLeft = null;
  338. }
  339. if (_sceneObjectRight != null)
  340. {
  341. PrefabManager.Instance.Restore(_sceneObjectRight);
  342. _sceneObjectRight = null;
  343. }
  344. UpdateDressLeft();
  345. UpdateView();
  346. }
  347. });
  348. }
  349. }
  350. }