MatchingCompetitionSelectView.cs 20 KB

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