MatchingCompetitionSelectView.cs 21 KB

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