MatchingCompetitionSelectView.cs 20 KB

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