MatchingCompetitionSelectView.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. Timers.inst.AddUpdate(CheckGuide);
  64. }
  65. protected override void OnHide()
  66. {
  67. if (_sceneObjectLeft != null)
  68. {
  69. PrefabManager.Instance.Restore(_sceneObjectLeft);
  70. _sceneObjectLeft = null;
  71. }
  72. if (_sceneObjectRight != null)
  73. {
  74. PrefabManager.Instance.Restore(_sceneObjectRight);
  75. _sceneObjectRight = null;
  76. }
  77. Timers.inst.Remove(CheckGuide);
  78. base.OnHide();
  79. }
  80. protected override void AddEventListener()
  81. {
  82. base.AddEventListener();
  83. EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdatePlayer);
  84. //EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateDressLeft);
  85. EventAgent.AddEventListener(ConstMessage.REWARDVIEW_CLOTHER, ShowReward);
  86. }
  87. protected override void RemoveEventListener()
  88. {
  89. base.RemoveEventListener();
  90. EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdatePlayer);
  91. //EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateDressLeft);
  92. EventAgent.RemoveEventListener(ConstMessage.REWARDVIEW_CLOTHER, ShowReward);
  93. }
  94. private void ShowReward()
  95. {
  96. if (MatchingCompetitionDataManager.Instance.SpecialBonusList != null && MatchingCompetitionDataManager.Instance.SpecialBonusList.Count > 0)
  97. {
  98. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(MatchingCompetitionDataManager.Instance.SpecialBonusList)); ;
  99. MatchingCompetitionDataManager.Instance.SpecialBonusList = null;
  100. }
  101. }
  102. private async void UpdateDressLeft()
  103. {
  104. //ViewManager.Show<ModalStatusView>("获取搭配数据中...");
  105. MatchingLeftDataManager.Instance.itemGameObjs.Clear();
  106. MatchingRightDataManager.Instance.itemGameObjs.Clear();
  107. PhotographDataManager.Instance.itemGameObjs.Clear();
  108. PhotographDataManager.Instance.dressUpObj?.Dispose();
  109. PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  110. if (_sceneObjectLeft == null)
  111. {
  112. _sceneObjectLeft = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  113. // 创建render texture
  114. renderTexureLeft = new RenderTexture((int)_ui.m_playerShow1.target.width, (int)_ui.m_playerShow2.target.height, 24);
  115. // 换装父节点 + 相机
  116. Camera camera = _sceneObjectLeft.transform.Find("Camera").GetComponent<Camera>();
  117. camera.gameObject.SetActive(true);
  118. camera.targetTexture = renderTexureLeft;
  119. // 创建RawImg
  120. }
  121. PhotographSceneManager.Instance.sceneObject = _sceneObjectLeft;
  122. if (MatchingLeftDataManager.Instance.DressUpBgID == 0)
  123. {
  124. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(180001));
  125. }
  126. else
  127. {
  128. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(MatchingLeftDataManager.Instance.DressUpBgID));
  129. }
  130. PhotographSceneManager.Instance.AddBodyItem(1);
  131. GameObject bodyParent = _sceneObjectLeft.transform.Find("Scene/Role").gameObject;
  132. PhotographDataManager.Instance.dressUpObj.setSceneObj(_sceneObjectLeft, false, true, bodyParent, false, null);
  133. PhotographDataManager.Instance.dressUpObj.PutOnDressUpData(MatchingLeftDataManager.Instance.MathingDressDate);
  134. //对搭配赛特殊处理
  135. foreach (var item in MatchingLeftDataManager.Instance.DressPropTransInfoDic)
  136. {
  137. if (item.Key == MatchingLeftDataManager.Instance.roleID)
  138. {
  139. continue;
  140. }
  141. else
  142. {
  143. List<int> idList = MatchingCompetitionDataManager.Instance.GetIDListByString(item.Key);
  144. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(idList[0]);
  145. MatchingCompetitionDataManager.Instance.AddSceneItemOne(itemCfg, idList[1], idList[2]);
  146. }
  147. }
  148. await Task.Delay(200);
  149. MatchingLeftDataManager.Instance.InsertGameObjectList();
  150. for (int i = 0; i < MatchingLeftDataManager.Instance.itemGameObjs.Count; i++)
  151. {
  152. GameObject itemGObj = MatchingLeftDataManager.Instance.itemGameObjs[i];
  153. TransformData itemdata = new TransformData();
  154. if (MatchingLeftDataManager.Instance.DressPropTransInfoDic.ContainsKey(itemGObj.name))
  155. {
  156. itemdata = MatchingLeftDataManager.Instance.DressPropTransInfoDic[itemGObj.name];
  157. }
  158. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
  159. if (MatchingLeftDataManager.Instance.itemGameObjs[i].name == "Role")
  160. {
  161. if (itemdata.position.y >= -5 || itemdata.position.y <= 5)
  162. {
  163. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(itemdata.position.x, 0, 0);
  164. }
  165. if (itemdata.position.x >= -5 || itemdata.position.x <= 5)
  166. {
  167. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(0, MatchingLeftDataManager.Instance.itemGameObjs[i].transform.position.y, 0);
  168. }
  169. }
  170. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.Rotate(itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
  171. MatchingLeftDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
  172. PhotographUtil.Instance.ChangeLayer(MatchingLeftDataManager.Instance.itemGameObjs[i], i * PhotographDataManager.layerCount, "up");
  173. }
  174. PhotographUtil.Instance.ChangeLayer(MatchingLeftDataManager.Instance.roleGameobj, 2 * PhotographDataManager.layerCount, "up");
  175. await Task.Delay(50);
  176. UpdateDressRigh();
  177. }
  178. private async void UpdateDressRigh()
  179. {
  180. MatchingRightDataManager.Instance.itemGameObjs.Clear();
  181. PhotographDataManager.Instance.itemGameObjs.Clear();
  182. PhotographDataManager.Instance.dressUpObj?.Dispose();
  183. PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  184. if (_sceneObjectRight == null)
  185. {
  186. _sceneObjectRight = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  187. // 创建render texture
  188. renderTexureRight = new RenderTexture((int)_ui.m_playerShow1.target.width, (int)_ui.m_playerShow2.target.height, 24);
  189. // 换装父节点 + 相机
  190. Camera camera = _sceneObjectRight.transform.Find("Camera").GetComponent<Camera>();
  191. camera.gameObject.SetActive(true);
  192. camera.targetTexture = renderTexureRight;
  193. }
  194. PhotographSceneManager.Instance.sceneObject = _sceneObjectRight;
  195. if (MatchingRightDataManager.Instance.DressUpBgID == 0)
  196. {
  197. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(180004));
  198. }
  199. else
  200. {
  201. PhotographSceneManager.Instance.AddBgItem(ItemCfgArray.Instance.GetCfg(MatchingRightDataManager.Instance.DressUpBgID));
  202. }
  203. PhotographSceneManager.Instance.AddBodyItem(2);
  204. GameObject bodyParent = _sceneObjectRight.transform.Find("Scene/Role").gameObject;
  205. PhotographDataManager.Instance.dressUpObj.setSceneObj(_sceneObjectRight, false, true, bodyParent, false, null);
  206. PhotographDataManager.Instance.dressUpObj.PutOnDressUpData(MatchingRightDataManager.Instance.MathingDressDate);
  207. //对搭配赛特殊处理
  208. foreach (var item in MatchingRightDataManager.Instance.DressPropTransInfoDic)
  209. {
  210. if (item.Key == MatchingRightDataManager.Instance.roleID)
  211. {
  212. continue;
  213. }
  214. else
  215. {
  216. List<int> idList = MatchingCompetitionDataManager.Instance.GetIDListByString(item.Key);
  217. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(idList[0]);
  218. MatchingCompetitionDataManager.Instance.AddSceneItemOne(itemCfg, idList[1], idList[2]);
  219. }
  220. }
  221. await Task.Delay(200);
  222. MatchingRightDataManager.Instance.InsertGameObjectList();
  223. for (int i = 0; i < MatchingRightDataManager.Instance.itemGameObjs.Count; i++)
  224. {
  225. GameObject itemGObj = MatchingRightDataManager.Instance.itemGameObjs[i];
  226. TransformData itemdata = new TransformData();
  227. if (MatchingRightDataManager.Instance.DressPropTransInfoDic.ContainsKey(itemGObj.name))
  228. {
  229. itemdata = MatchingRightDataManager.Instance.DressPropTransInfoDic[itemGObj.name];
  230. }
  231. MatchingRightDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
  232. if (MatchingRightDataManager.Instance.itemGameObjs[i].name == "Role")
  233. {
  234. if (itemdata.position.y >= -5 || itemdata.position.y <= 5)
  235. {
  236. MatchingRightDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(itemdata.position.x, 0, 0);
  237. }
  238. if (itemdata.position.x >= -5 || itemdata.position.x <= 5)
  239. {
  240. MatchingRightDataManager.Instance.itemGameObjs[i].transform.position = new Vector3(0, MatchingRightDataManager.Instance.itemGameObjs[i].transform.position.y, 0);
  241. }
  242. }
  243. MatchingRightDataManager.Instance.itemGameObjs[i].transform.Rotate(itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
  244. MatchingRightDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
  245. PhotographUtil.Instance.ChangeLayer(MatchingRightDataManager.Instance.itemGameObjs[i], i * PhotographDataManager.layerCount, "up");
  246. }
  247. PhotographUtil.Instance.ChangeLayer(MatchingRightDataManager.Instance.roleGameobj, 2 * PhotographDataManager.layerCount, "up");
  248. await Task.Delay(50);
  249. _sceneObjectRight.transform.position = new Vector3(50, 50, 50);
  250. UpdatePlayer();
  251. }
  252. private RenderTexture renderTexureLeft;
  253. private RenderTexture renderTexureRight;
  254. private void UpdatePlayer()
  255. {
  256. _ui.m_playerShow1.m_playerImage.m_playerImage.texture = new NTexture(renderTexureLeft);
  257. _ui.m_playerShow2.m_playerImage.m_playerImage.texture = new NTexture(renderTexureRight);
  258. //_ui.m_playerShow1.m_playerImage.m_playerImage.texture = MatchingLeftDataManager.Instance.LeftRoleInfo.Ntexture;
  259. //_ui.m_playerShow2.m_playerImage.m_playerImage.texture = MatchingRightDataManager.Instance.RightRoleInfo.Ntexture;
  260. MatchingPhotoWorksData otherLeftdata = MatchingLeftDataManager.Instance.LeftRoleInfo;
  261. JudgingRoundRoleInfo otherLeftInfo = otherLeftdata.JudgingInfo;
  262. RoleInfoManager.Instance.UpdateHead(_ui.m_player1.m_head, otherLeftInfo.HeadItemId, otherLeftInfo.HeadBorderItemId);
  263. _ui.m_player1.m_nameText.text = otherLeftInfo.RoleName.ToString();
  264. _ui.m_select1.m_numText.visible = false;
  265. _ui.m_select1.m_numText.text = otherLeftInfo.Score.ToString();
  266. MatchingPhotoWorksData otherRightdata = MatchingRightDataManager.Instance.RightRoleInfo;
  267. JudgingRoundRoleInfo otherRightInfo = otherRightdata.JudgingInfo;
  268. RoleInfoManager.Instance.UpdateHead(_ui.m_player2.m_head, otherRightInfo.HeadItemId, otherRightInfo.HeadBorderItemId);
  269. _ui.m_player2.m_nameText.text = otherRightInfo.RoleName.ToString();
  270. _ui.m_select2.m_numText.visible = false;
  271. _ui.m_select2.m_numText.text = otherRightInfo.Score.ToString();
  272. ViewManager.Hide<ModalStatusView>();
  273. }
  274. private void UpdateView()
  275. {
  276. _ui.m_selectText1.alpha = 0;
  277. _ui.m_selectText2.alpha = 0;
  278. _ui.m_timeText.text = string.Format("剩余次数:{0}",Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  279. }
  280. private void OnClickBtnBack()
  281. {
  282. _ui.m_BtnBack.touchable = true;
  283. ViewManager.GoBackFrom(typeof(MatchingCompetitionSelectView).FullName);
  284. }
  285. private async void OnClickBtnSelect1()
  286. {
  287. if((judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes)<=0)
  288. {
  289. PromptController.Instance.ShowFloatTextPrompt("评选次数不足");
  290. return;
  291. }
  292. bool result = await MatchingCompetitionSproxy.ReqCheckMatchingCompetitionWork(
  293. MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.WorksId,MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.WorksId
  294. ) ;
  295. if(result)
  296. {
  297. _ui.m_select1.m_c1.selectedIndex = 1;
  298. _ui.m_select1.m_numText.visible = true;
  299. _ui.m_select2.m_numText.visible = true;
  300. _ui.m_select1.m_numText.text = string.Format("心动值{0}", MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.Score.ToString());
  301. _ui.m_timeText.text = string.Format("剩余次数:{0}", Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  302. }
  303. _ui.m_t0.Play(async () =>
  304. {
  305. bool resulst = await MatchingCompetitionSproxy.ReqGetTwoPlayers();
  306. if (resulst)
  307. {
  308. if (_sceneObjectLeft != null)
  309. {
  310. PrefabManager.Instance.Restore(_sceneObjectLeft);
  311. _sceneObjectLeft = null;
  312. }
  313. if (_sceneObjectRight != null)
  314. {
  315. PrefabManager.Instance.Restore(_sceneObjectRight);
  316. _sceneObjectRight = null;
  317. }
  318. UpdateDressLeft();
  319. UpdateView();
  320. }
  321. });
  322. }
  323. private async void OnClickBtnSelect2()
  324. {
  325. if ((judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes) <= 0)
  326. {
  327. PromptController.Instance.ShowFloatTextPrompt("评选次数不足");
  328. return;
  329. }
  330. bool result = await MatchingCompetitionSproxy.ReqCheckMatchingCompetitionWork(
  331. MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.WorksId, MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.WorksId
  332. );
  333. if (result)
  334. {
  335. _ui.m_select2.m_c1.selectedIndex = 1;
  336. _ui.m_select1.m_numText.visible = true;
  337. _ui.m_select2.m_numText.visible = true;
  338. _ui.m_select2.m_numText.text = string.Format("心动值{0}", MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo.Score.ToString());
  339. _ui.m_timeText.text = string.Format("剩余次数:{0}", Mathf.Max(0, judgingCfg.FreeTimes - MatchingCompetitionDataManager.Instance.MatchingRemainingTimes));
  340. }
  341. _ui.m_t1.Play(async () =>
  342. {
  343. bool resulst = await MatchingCompetitionSproxy.ReqGetTwoPlayers();
  344. if (resulst)
  345. {
  346. if (_sceneObjectLeft != null)
  347. {
  348. PrefabManager.Instance.Restore(_sceneObjectLeft);
  349. _sceneObjectLeft = null;
  350. }
  351. if (_sceneObjectRight != null)
  352. {
  353. PrefabManager.Instance.Restore(_sceneObjectRight);
  354. _sceneObjectRight = null;
  355. }
  356. UpdateDressLeft();
  357. UpdateView();
  358. }
  359. });
  360. }
  361. private void CheckGuide(object param)
  362. {
  363. if (GuideDataManager.IsGuideFinish("DAPEISAI_2") <= 0)
  364. {
  365. UpdateToCheckGuide(null);
  366. }
  367. else
  368. {
  369. Timers.inst.Remove(CheckGuide);
  370. }
  371. }
  372. protected override void UpdateToCheckGuide(object param)
  373. {
  374. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  375. GuideController.TryGuide(_ui.m_select1.target, "DAPEISAI_2", 3, "选择你喜欢的搭配!");
  376. GuideController.TryCompleteGuide("DAPEISAI_2", 3);
  377. }
  378. }
  379. }