MatchingCompetitionSelectView.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. UpdateDressLeft();
  61. ViewManager.Hide<ModalStatusView>();
  62. }
  63. protected override void OnHide()
  64. {
  65. if (_sceneObjectLeft != null)
  66. {
  67. PrefabManager.Instance.Restore(_sceneObjectLeft);
  68. _sceneObjectLeft = null;
  69. }
  70. if (_sceneObjectRight != null)
  71. {
  72. PrefabManager.Instance.Restore(_sceneObjectRight);
  73. _sceneObjectRight = null;
  74. }
  75. base.OnHide();
  76. }
  77. protected override void AddEventListener()
  78. {
  79. base.AddEventListener();
  80. //EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdatePlayer);
  81. //EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateDressLeft);
  82. }
  83. protected override void RemoveEventListener()
  84. {
  85. base.RemoveEventListener();
  86. //EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdatePlayer);
  87. //EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateDressLeft);
  88. }
  89. private async void UpdateDressLeft()
  90. {
  91. //ViewManager.Show<ModalStatusView>("获取搭配数据中...");
  92. MatchingLeftDataManager.Instance.itemGameObjs.Clear();
  93. PhotographDataManager.Instance.itemGameObjs.Clear();
  94. PhotographDataManager.Instance.dressUpObj?.Dispose();
  95. PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  96. if (_sceneObjectLeft == null)
  97. {
  98. _sceneObjectLeft = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  99. // 创建render texture
  100. renderTexureLeft = new RenderTexture((int)_ui.m_playerShow1.target.width, (int)_ui.m_playerShow2.target.height, 24);
  101. // 换装父节点 + 相机
  102. Camera camera = _sceneObjectLeft.transform.Find("Camera").GetComponent<Camera>();
  103. camera.gameObject.SetActive(true);
  104. camera.targetTexture = renderTexureLeft;
  105. // 创建RawImg
  106. }
  107. PhotographSceneManager.Instance.sceneObject = _sceneObjectLeft;
  108. if (MatchingLeftDataManager.Instance.DressUpBgID == 0)
  109. {
  110. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(180001));
  111. }
  112. else
  113. {
  114. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(MatchingLeftDataManager.Instance.DressUpBgID));
  115. }
  116. PhotographSceneManager.Instance.AddBodyItem();
  117. GameObject bodyParent = _sceneObjectLeft.transform.Find("Scene/Role").gameObject;
  118. PhotographDataManager.Instance.dressUpObj.setSceneObj(_sceneObjectLeft, false, true, bodyParent, false, null);
  119. PhotographDataManager.Instance.dressUpObj.PutOnDressUpData(MatchingLeftDataManager.Instance.MathingDressDate);
  120. //对搭配赛特殊处理
  121. for (int i = 0; i < MatchingLeftDataManager.Instance.DressPropIdList.Count; i++)
  122. {
  123. if (MatchingLeftDataManager.Instance.DressPropIdList[i] <= 0)
  124. {
  125. continue;
  126. }
  127. else
  128. {
  129. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(MatchingLeftDataManager.Instance.DressPropIdList[i]);
  130. ET.Log.Debug(string.Format("zyq:{0}", MatchingLeftDataManager.Instance.DressPropIdList[i]));
  131. MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, true,1);
  132. }
  133. }
  134. await Task.Delay(100);
  135. MatchingLeftDataManager.Instance.InsertGameObjectList();
  136. for (int i = 0; i < MatchingLeftDataManager.Instance.TransformDataList.Count; i++)
  137. {
  138. TransformData itemdata = MatchingLeftDataManager.Instance.TransformDataList[i];
  139. GameObject itemGObj = MatchingLeftDataManager.Instance.itemGameObjs[i];
  140. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
  141. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.Rotate(itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
  142. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
  143. PhotographUtil.Instance.ChangeLayer(MatchingLeftDataManager.Instance.itemGameObjs[i], i * PhotographDataManager.layerCount, "up");
  144. }
  145. UpdateDressRigh();
  146. }
  147. private async void UpdateDressRigh()
  148. {
  149. MatchingRightDataManager.Instance.itemGameObjs.Clear();
  150. PhotographDataManager.Instance.itemGameObjs.Clear();
  151. PhotographDataManager.Instance.dressUpObj?.Dispose();
  152. PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  153. if (_sceneObjectRight == null)
  154. {
  155. _sceneObjectRight = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  156. // 创建render texture
  157. renderTexureRight = new RenderTexture((int)_ui.m_playerShow1.target.width, (int)_ui.m_playerShow2.target.height, 24);
  158. // 换装父节点 + 相机
  159. Camera camera = _sceneObjectRight.transform.Find("Camera").GetComponent<Camera>();
  160. camera.gameObject.SetActive(true);
  161. camera.targetTexture = renderTexureRight;
  162. }
  163. PhotographSceneManager.Instance.sceneObject = _sceneObjectRight;
  164. if (MatchingRightDataManager.Instance.DressUpBgID == 0)
  165. {
  166. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(180004));
  167. }
  168. else
  169. {
  170. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(MatchingRightDataManager.Instance.DressUpBgID));
  171. }
  172. PhotographSceneManager.Instance.AddBodyItem();
  173. GameObject bodyParent = _sceneObjectRight.transform.Find("Scene/Role").gameObject;
  174. PhotographDataManager.Instance.dressUpObj.setSceneObj(_sceneObjectRight, false, true, bodyParent, false, null);
  175. PhotographDataManager.Instance.dressUpObj.PutOnDressUpData(MatchingRightDataManager.Instance.MathingDressDate);
  176. //对搭配赛特殊处理
  177. for (int i = 0; i < MatchingRightDataManager.Instance.DressPropIdList.Count; i++)
  178. {
  179. if (MatchingRightDataManager.Instance.DressPropIdList[i] <= 0)
  180. {
  181. continue;
  182. }
  183. else
  184. {
  185. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(MatchingRightDataManager.Instance.DressPropIdList[i]);
  186. MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, true,2);
  187. }
  188. }
  189. await Task.Delay(100);
  190. MatchingRightDataManager.Instance.InsertGameObjectList();
  191. for (int i = 0; i < MatchingRightDataManager.Instance.TransformDataList.Count; i++)
  192. {
  193. TransformData itemdata = MatchingRightDataManager.Instance.TransformDataList[i];
  194. GameObject itemGObj = MatchingRightDataManager.Instance.itemGameObjs[i];
  195. MatchingRightDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
  196. MatchingRightDataManager.Instance.itemGameObjs[i].transform.Rotate(itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
  197. MatchingRightDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
  198. PhotographUtil.Instance.ChangeLayer(MatchingRightDataManager.Instance.itemGameObjs[i], i * PhotographDataManager.layerCount, "up");
  199. }
  200. _sceneObjectRight.transform.position = new Vector3(50, 50, 50);
  201. await Task.Delay(100);
  202. UpdatePlayer();
  203. }
  204. private RenderTexture renderTexureLeft;
  205. private RenderTexture renderTexureRight;
  206. private void UpdatePlayer()
  207. {
  208. _ui.m_playerShow1.m_playerImage.m_playerImage.texture = new NTexture(renderTexureLeft);
  209. _ui.m_playerShow2.m_playerImage.m_playerImage.texture = new NTexture(renderTexureRight);
  210. MatchingPhotoWorksData otherLeftdata = MatchingLeftDataManager.Instance.LeftRoleInfo;
  211. JudgingRoundRoleInfo otherLeftInfo = otherLeftdata.JudgingInfo;
  212. RoleInfoManager.Instance.UpdateHead(_ui.m_player1.m_head, otherLeftInfo.HeadItemId, otherLeftInfo.HeadBorderItemId);
  213. _ui.m_player1.m_nameText.text = otherLeftInfo.RoleName.ToString();
  214. _ui.m_select1.m_numText.visible = false;
  215. _ui.m_select1.m_numText.text = otherLeftInfo.Score.ToString();
  216. MatchingPhotoWorksData otherRightdata = MatchingRightDataManager.Instance.RightRoleInfo;
  217. JudgingRoundRoleInfo otherRightInfo = otherRightdata.JudgingInfo;
  218. RoleInfoManager.Instance.UpdateHead(_ui.m_player2.m_head, otherRightInfo.HeadItemId, otherRightInfo.HeadBorderItemId);
  219. _ui.m_player2.m_nameText.text = otherRightInfo.RoleName.ToString();
  220. _ui.m_select2.m_numText.visible = false;
  221. _ui.m_select2.m_numText.text = otherRightInfo.Score.ToString();
  222. ViewManager.Hide<ModalStatusView>();
  223. }
  224. private void UpdateView()
  225. {
  226. _ui.m_selectText1.alpha = 0;
  227. _ui.m_selectText2.alpha = 0;
  228. _ui.m_timeText.text = string.Format("剩余次数:{0}",Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  229. }
  230. private void OnClickBtnBack()
  231. {
  232. _ui.m_BtnBack.touchable = true;
  233. ViewManager.GoBackFrom(typeof(MatchingCompetitionSelectView).FullName);
  234. }
  235. private async void OnClickBtnSelect1()
  236. {
  237. if((judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes)<=0)
  238. {
  239. PromptController.Instance.ShowFloatTextPrompt("评选次数不足");
  240. return;
  241. }
  242. bool result = await MatchingCompetitionSproxy.ReqCheckMatchingCompetitionWork(
  243. MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.WorksId,MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.WorksId
  244. ) ;
  245. if(result)
  246. {
  247. _ui.m_select1.m_c1.selectedIndex = 1;
  248. _ui.m_select1.m_numText.visible = true;
  249. _ui.m_select2.m_numText.visible = true;
  250. _ui.m_select1.m_numText.text = string.Format("心动值{0}", MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.Score.ToString());
  251. _ui.m_timeText.text = string.Format("剩余次数:{0}", Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  252. }
  253. _ui.m_t0.Play(async () =>
  254. {
  255. bool resulst = await MatchingCompetitionSproxy.ReqGetTwoPlayers();
  256. if (resulst)
  257. {
  258. if (_sceneObjectLeft != null)
  259. {
  260. PrefabManager.Instance.Restore(_sceneObjectLeft);
  261. _sceneObjectLeft = null;
  262. }
  263. if (_sceneObjectRight != null)
  264. {
  265. PrefabManager.Instance.Restore(_sceneObjectRight);
  266. _sceneObjectRight = null;
  267. }
  268. UpdateDressLeft();
  269. UpdateView();
  270. }
  271. });
  272. }
  273. private async void OnClickBtnSelect2()
  274. {
  275. if ((judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes) <= 0)
  276. {
  277. PromptController.Instance.ShowFloatTextPrompt("评选次数不足");
  278. return;
  279. }
  280. bool result = await MatchingCompetitionSproxy.ReqCheckMatchingCompetitionWork(
  281. MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.WorksId, MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.WorksId
  282. );
  283. if (result)
  284. {
  285. _ui.m_select2.m_c1.selectedIndex = 1;
  286. _ui.m_select1.m_numText.visible = true;
  287. _ui.m_select2.m_numText.visible = true;
  288. _ui.m_select2.m_numText.text = string.Format("心动值{0}", MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.Score.ToString());
  289. _ui.m_timeText.text = string.Format("剩余次数:{0}", Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  290. }
  291. _ui.m_t1.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. }
  312. }