MatchingCompetitionDataManager.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. using ET;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Text.RegularExpressions;
  6. using UnityEngine;
  7. using Live2D.Cubism.Rendering;
  8. using FairyGUI;
  9. using UI.MatchingCompetition;
  10. namespace GFGGame
  11. {
  12. class MatchingCompetitionDataManager : SingletonBase<MatchingCompetitionDataManager>
  13. {
  14. ////搭配赛标记
  15. //public int type = 2;
  16. //位置信息数据索引
  17. public int indexRoleData = 0;
  18. //人物位置信息
  19. public TransformData roleTransFormData = new TransformData();
  20. public GameObject roleGameobj;
  21. public int roleID = -1;
  22. //*********************搭配数据*********************************
  23. //需要传输的数据:MathingDressDate,DressUpBgID,DressPropIdList,TransformDataList,
  24. public DressUpData MathingDressDate = DressUpData.CreateDefault();
  25. public int DressUpBgID = 0;
  26. //*****这两个id放列表的最后面
  27. //边框id
  28. public int BorderID = 0;
  29. //NpcId
  30. public int NpcID = 0;
  31. //*************=**************
  32. //道具数据,一一对应
  33. //场景名字,自己搭配的数据
  34. public List<string> DressPropNameList = new List<string>();
  35. //道具id
  36. public List<int> DressPropIdList = new List<int>();
  37. //道具位置信息
  38. public List<TransformData> TransformDataList = new List<TransformData>();
  39. public List<GameObject> itemGameObjs = new List<GameObject>();
  40. //所有信息的列表,用于前后端交互
  41. public List<CollocationInfo> AllDressIDInfoList = new List<CollocationInfo>();
  42. //public List<int> _equipSceneData = new List<int>();//当前穿戴的场景数据(从套装获得)
  43. //***************************************************************
  44. public int MatchingCompetitionSeason = 1;
  45. public int MatchingState = 1;
  46. public long MatchingEndTimes = 0;
  47. public long WorksID = 0;
  48. public string TempPictureUrl = "";
  49. public int MatchingRemainingTimes = 1;
  50. public MyWorksIdInfo myWorks = new MyWorksIdInfo();
  51. public List<ItemInfoProto> SpecialBonusList = new List<ItemInfoProto>();
  52. /// <summary>
  53. /// 搭配赛相册
  54. /// </summary>
  55. /// <typeparam name="PoemPhotoData"></typeparam>
  56. /// <returns></returns>
  57. public List<PoemPhotoData> MatchingPhotoInfos = new List<PoemPhotoData>();
  58. //角色详情界面图片信息
  59. public NTexture DetailNtexture;
  60. //自己的搭配图片
  61. public NTexture MyNtextture;
  62. public byte[] MyBytes;
  63. //本期排行榜数据
  64. public List<MatchingPhotoWorksData> _currentRankList = new List<MatchingPhotoWorksData>();
  65. //往期作品集
  66. public List<MatchingWorksData> _BeforeWorksList = new List<MatchingWorksData>();
  67. //往期排行榜数据
  68. public List<MatchingPhotoWorksData> _BeforeRankList = new List<MatchingPhotoWorksData>();
  69. //根据时间判断:1:集结期 2:评选期 3;结算期
  70. //public int CheckCompetitionState()
  71. //{
  72. // long currentTime = TimeHelper.ServerNow();
  73. // DateTime dateTime = DateTimeOffset.FromUnixTimeSeconds(currentTime).DateTime;
  74. // // 获取星期几
  75. // DayOfWeek dayOfWeek = dateTime.DayOfWeek;
  76. // int week = (int)dayOfWeek;
  77. // int hour = dateTime.Hour;
  78. // if(week == 0)
  79. // {
  80. // if(hour >= 21)
  81. // {
  82. // return 3;
  83. // }
  84. // else
  85. // {
  86. // return 2;
  87. // }
  88. // }
  89. // if(week <= 3 && week >= 1)
  90. // {
  91. // if(week == 3 && hour >= 5)
  92. // {
  93. // return 2;
  94. // }
  95. // if(week == 1 && hour < 5)
  96. // {
  97. // return 3;
  98. // }
  99. // return 1;
  100. // }
  101. // else if(week > 3 && week <= 6)
  102. // {
  103. // return 2;
  104. // }
  105. // return -1;
  106. //}
  107. public void ConvertInfoToList()
  108. {
  109. //将所有需要存储的信息转换成list
  110. AllDressIDInfoList.Clear();
  111. foreach(var item in MathingDressDate.itemList)
  112. {
  113. CollocationInfo itemInfo = new CollocationInfo();
  114. itemInfo.ItemId = item;
  115. itemInfo.ClientPosition = "";
  116. AllDressIDInfoList.Add(itemInfo);
  117. }
  118. for(int i = 0;i< DressPropIdList.Count;i++)
  119. {
  120. CollocationInfo itemInfo = new CollocationInfo();
  121. itemInfo.ItemId = DressPropIdList[i];
  122. string transStr = TransformDataList[i].position.x.ToString()+"_" + TransformDataList[i].position.y.ToString() + "_"
  123. + TransformDataList[i].position.z.ToString()
  124. + "_" + TransformDataList[i].rotationZ.ToString()
  125. + "_" + TransformDataList[i].scale.x.ToString() + "_" +
  126. TransformDataList[i].scale.y.ToString() + "_" + TransformDataList[i].scale.z.ToString();
  127. itemInfo.ClientPosition = transStr;
  128. AllDressIDInfoList.Add(itemInfo);
  129. }
  130. CollocationInfo itemBgInfo = new CollocationInfo();
  131. itemBgInfo.ItemId = MatchingCompetitionDataManager.Instance.DressUpBgID;
  132. itemBgInfo.ClientPosition = "";
  133. AllDressIDInfoList.Add(itemBgInfo);
  134. CollocationInfo itemActionInfo = new CollocationInfo();
  135. itemActionInfo.ItemId = MatchingCompetitionDataManager.Instance.MathingDressDate.actionId;
  136. itemActionInfo.ClientPosition = "";
  137. AllDressIDInfoList.Add(itemActionInfo);
  138. }
  139. //解析后台获取的信息
  140. public void AnalysisInfoToList()
  141. {
  142. List<int> dressitemIDList = new List<int>();
  143. List<int> propIDList = new List<int>();
  144. List<TransformData> transDataList = new List<TransformData>();
  145. DressUpBgID = 0;
  146. MathingDressDate.actionId = 0;
  147. for (int i = 0; i < AllDressIDInfoList.Count; i++)
  148. {
  149. if(AllDressIDInfoList[i].ItemId == roleID)
  150. {
  151. propIDList.Add(AllDressIDInfoList[i].ItemId);
  152. transDataList.Add(AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  153. }
  154. else
  155. {
  156. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(AllDressIDInfoList[i].ItemId);
  157. if (itemCfg != null && itemCfg.itemType == ConstItemType.DRESS_UP)
  158. {
  159. if(itemCfg.subType == 19 || itemCfg.subType == 17 || itemCfg.subType == 21|| itemCfg.subType == 22)
  160. {
  161. //记录道具和位置信息
  162. propIDList.Add(AllDressIDInfoList[i].ItemId);
  163. transDataList.Add(AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  164. if (itemCfg.resLayer2 == "t" || itemCfg.resLayer3 == "t")
  165. {
  166. propIDList.Add(-3);
  167. transDataList.Add(AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  168. }
  169. }
  170. else if (itemCfg != null && itemCfg.subType == ConstDressUpItemType.BEI_JING)
  171. {
  172. DressUpBgID = itemCfg.id;
  173. }
  174. else
  175. {
  176. dressitemIDList.Add(AllDressIDInfoList[i].ItemId);
  177. }
  178. }
  179. else if (itemCfg != null && itemCfg.itemType == ConstItemType.PHOTOGRAPH)
  180. {
  181. //记录道具和位置信息
  182. propIDList.Add(AllDressIDInfoList[i].ItemId);
  183. transDataList.Add(AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  184. }
  185. else if(itemCfg == null)
  186. {
  187. SuitCfg actionId = SuitCfgArray.Instance.GetCfg(AllDressIDInfoList[i].ItemId);
  188. if(actionId !=null)
  189. {
  190. MathingDressDate.actionId = AllDressIDInfoList[i].ItemId;
  191. }
  192. }
  193. }
  194. }
  195. MathingDressDate.itemList = dressitemIDList;
  196. DressPropIdList = propIDList;
  197. TransformDataList = transDataList;
  198. }
  199. public TransformData AnalysisStringToTransform(string strTrans)
  200. {
  201. TransformData transData = new TransformData();
  202. string[] parts = Regex.Split(strTrans, "_");
  203. if(parts.Length > 6)
  204. {
  205. transData.position.x = float.Parse(parts[0]);
  206. transData.position.y = float.Parse(parts[1]);
  207. transData.position.z = float.Parse(parts[2]);
  208. transData.rotationZ = float.Parse(parts[3]);
  209. transData.scale.x = float.Parse(parts[4]);
  210. transData.scale.y = float.Parse(parts[5]);
  211. transData.scale.z = float.Parse(parts[6]);
  212. }
  213. return transData;
  214. }
  215. //存储道具信息
  216. public void SetTransformData()
  217. {
  218. DressPropNameList.Clear();
  219. TransformDataList.Clear();
  220. for (int i =0;i<itemGameObjs.Count;i++)
  221. {
  222. if(itemGameObjs[i].name == "Role")
  223. {
  224. TransformData itemData = new TransformData();
  225. roleTransFormData.position = itemGameObjs[i].transform.position;
  226. roleTransFormData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  227. roleTransFormData.scale = itemGameObjs[i].transform.localScale;
  228. TransformDataList.Add(roleTransFormData);
  229. DressPropNameList.Add(itemGameObjs[i].name);
  230. }
  231. else
  232. {
  233. TransformData itemData = new TransformData();
  234. itemData.position = itemGameObjs[i].transform.position;
  235. itemData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  236. itemData.scale = itemGameObjs[i].transform.localScale;
  237. TransformDataList.Add(itemData);
  238. DressPropNameList.Add(itemGameObjs[i].name);
  239. }
  240. }
  241. SetNameToIdList();
  242. }
  243. //将名字转换成道具id
  244. public void SetNameToIdList()
  245. {
  246. DressPropIdList.Clear();
  247. int flog_prefix = 0;
  248. int flog_suffix = 0;
  249. for (int i = 0; i < DressPropNameList.Count; i++)
  250. {
  251. bool containsUnderscore = Regex.IsMatch(DressPropNameList[i], "_");
  252. if(!containsUnderscore)
  253. {
  254. if (DressPropNameList[i] == "Role")
  255. {
  256. DressPropIdList.Add(roleID);
  257. }
  258. else if (DressPropNameList[i] == "Border")
  259. {
  260. if (BorderID != 0)
  261. {
  262. DressPropIdList.Add(BorderID);
  263. }
  264. }
  265. else if (DressPropNameList[i] == "Npc")
  266. {
  267. if (NpcID != 0)
  268. {
  269. DressPropIdList.Add(NpcID);
  270. }
  271. }
  272. }
  273. else
  274. {
  275. // 使用正则表达式分割字符串
  276. string[] parts = Regex.Split(DressPropNameList[i], "_");
  277. int partID = int.Parse(parts[0]);
  278. if(flog_prefix == int.Parse(parts[0]))
  279. {
  280. if((flog_suffix == 3 && int.Parse(parts[1]) == 1)|| (flog_suffix == 1 && int.Parse(parts[1]) == 3))
  281. {
  282. flog_prefix = 0;
  283. flog_suffix = 0;
  284. continue;
  285. }
  286. }
  287. flog_prefix = int.Parse(parts[0]);
  288. flog_suffix = int.Parse(parts[1]);
  289. DressPropIdList.Add(partID);
  290. }
  291. }
  292. }
  293. //将穿戴数据分类
  294. //public void ClassifyEquipData()
  295. //{
  296. // _equipSceneData.Clear();
  297. // PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  298. // //for (int i = 0; i < MathingDressDate.itemList.Count; i++)
  299. // //{
  300. // // int itemId = MathingDressDate.itemList[i];
  301. // // if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId, false))
  302. // // {
  303. // // if (!_equipSceneData.ContainsKey(itemId))
  304. // // {
  305. // // _equipSceneData.Add(itemId, new List<int>());
  306. // // }
  307. // // _equipSceneData[itemId].Add(itemId);
  308. // // }
  309. // //}
  310. // for(int i =0;i<DressPropIdList.Count;i++)
  311. // {
  312. // int itemId = DressPropIdList[i];
  313. // if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId, false))
  314. // {
  315. // _equipSceneData.Add(itemId);
  316. // }
  317. // }
  318. //}
  319. public void InsertGameObjectList()
  320. {
  321. for(int i=0;i< DressPropIdList.Count;i++)
  322. {
  323. if (DressPropIdList[i] == roleID)
  324. {
  325. indexRoleData = i;
  326. }
  327. }
  328. if(itemGameObjs.Count ==0)
  329. {
  330. itemGameObjs.Add(roleGameobj);
  331. }
  332. else
  333. {
  334. if (indexRoleData > itemGameObjs.Count)
  335. {
  336. itemGameObjs.Add(roleGameobj);
  337. }
  338. else
  339. {
  340. itemGameObjs.Insert(indexRoleData, roleGameobj);
  341. }
  342. }
  343. }
  344. public void SetNumToRank(int index,UI_Component4 rankCom)
  345. {
  346. int c1 = 0;
  347. int c2 = 0;
  348. if(index<=3&& index >=1)
  349. {
  350. c2 = index;
  351. }
  352. if (index > 3 && index <= 9)
  353. {
  354. c1 = 0;
  355. }
  356. else if(index >9 && index <= 50)
  357. {
  358. c1 = 1;
  359. }
  360. else
  361. {
  362. c1 = 2;
  363. }
  364. rankCom.m_c1.selectedIndex = c1;
  365. rankCom.m_c2.selectedIndex = c2;
  366. if(c1 == 0)
  367. {
  368. rankCom.m_num3.url = string.Format("ui://MatchingCompetition/{0}",index.ToString());
  369. }
  370. else if(c1 == 1)
  371. {
  372. int one = index / 10;
  373. int two = index % 10;
  374. rankCom.m_num1.url = string.Format("ui://MatchingCompetition/{0}", one.ToString());
  375. rankCom.m_num2.url = string.Format("ui://MatchingCompetition/{0}", two.ToString());
  376. }
  377. else
  378. {
  379. if (index == 0)
  380. {
  381. rankCom.m_RankText.text = "--";
  382. }
  383. else
  384. {
  385. for (int i = 11; i < JudgingRoundRewardCfgArray.Instance.dataArray.Length-1; i++)
  386. {
  387. JudgingRoundRewardCfg judgingCfg = JudgingRoundRewardCfgArray.Instance.GetCfg(i);
  388. JudgingRoundRewardCfg judgingNextCfg = JudgingRoundRewardCfgArray.Instance.GetCfg(i+1);
  389. if (index >= judgingCfg.rank && index < judgingNextCfg.rank)
  390. {
  391. rankCom.m_RankText.text = judgingNextCfg.desc;
  392. }
  393. else
  394. {
  395. rankCom.m_RankText.text = index.ToString();
  396. }
  397. }
  398. }
  399. }
  400. }
  401. public async void AddSceneItem(ItemCfg itemCfg, bool setLayer,int isLeft = 0)
  402. {
  403. Vector3 pos = Vector3.zero;
  404. if (!string.IsNullOrEmpty(itemCfg.resLayer3))
  405. {
  406. GameObject parentGameObj3 = new GameObject(string.Format("{0}_{1}", itemCfg.id, 3));
  407. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj3, itemCfg, 3, setLayer,false,isLeft);
  408. if (setLayer)
  409. {
  410. if (parentGameObj3.transform.childCount > 0)
  411. {
  412. parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
  413. pos = parentGameObj3.transform.localPosition;
  414. }
  415. }
  416. }
  417. if (!string.IsNullOrEmpty(itemCfg.resLayer2))
  418. {
  419. GameObject parentGameObj2 = new GameObject(string.Format("{0}_{1}", itemCfg.id, 2));
  420. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj2, itemCfg, 2, setLayer,false, isLeft);
  421. if (setLayer)
  422. {
  423. if (parentGameObj2.transform.childCount > 0)
  424. {
  425. parentGameObj2.transform.localPosition = pos == Vector3.zero ? -parentGameObj2.transform.GetChild(0).localPosition : pos;
  426. pos = parentGameObj2.transform.localPosition;
  427. }
  428. }
  429. }
  430. if (!string.IsNullOrEmpty(itemCfg.resLayer1))
  431. {
  432. GameObject parentGameObj1 = new GameObject(string.Format("{0}_{1}", itemCfg.id, 1));
  433. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj1, itemCfg, 1, setLayer, false, isLeft);
  434. if (setLayer)
  435. {
  436. if (parentGameObj1.transform.childCount > 0)
  437. {
  438. parentGameObj1.transform.localPosition = pos == Vector3.zero ? -parentGameObj1.transform.GetChild(0).localPosition : pos;
  439. pos = parentGameObj1.transform.localPosition;
  440. }
  441. }
  442. }
  443. }
  444. public void OnClickBtnRule()
  445. {
  446. ViewManager.Show<MatchingCompetitionRuleTipsView>();
  447. }
  448. }
  449. class MatchingOneDataManager : SingletonBase<MatchingOneDataManager>
  450. {
  451. //其他玩家信息用于展示
  452. public MatchingPhotoWorksData OneRoleInfo = new MatchingPhotoWorksData();
  453. //人物位置信息
  454. public TransformData roleTransFormData = new TransformData();
  455. public GameObject roleGameobj;
  456. public int roleID = -1;
  457. //*********************搭配数据*********************************
  458. //需要传输的数据:MathingDressDate,DressUpBgID,DressPropIdList,TransformDataList,
  459. public DressUpData MathingDressDate = DressUpData.CreateDefault();
  460. public int DressUpBgID = 0;
  461. //*****这两个id放列表的最后面
  462. //边框id
  463. public int BorderID = 0;
  464. //NpcId
  465. public int NpcID = 0;
  466. //道具数据,一一对应
  467. //道具id
  468. public List<int> DressPropIdList = new List<int>();
  469. //道具位置信息
  470. public List<TransformData> TransformDataList = new List<TransformData>();
  471. public List<GameObject> itemGameObjs = new List<GameObject>();
  472. //***************************************************************
  473. //解析后台获取的信息
  474. public void AnalysisInfoToList()
  475. {
  476. List<int> dressitemIDList = new List<int>();
  477. List<int> propIDList = new List<int>();
  478. List<TransformData> transDataList = new List<TransformData>();
  479. for (int i = 0; i < OneRoleInfo.JudgingInfo.CollocationInfoList.Count; i++)
  480. {
  481. if (OneRoleInfo.JudgingInfo.CollocationInfoList[i].ItemId == roleID)
  482. {
  483. propIDList.Add(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ItemId);
  484. transDataList.Add(MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ClientPosition));
  485. }
  486. else
  487. {
  488. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ItemId);
  489. if (itemCfg != null && itemCfg.itemType == ConstItemType.DRESS_UP)
  490. {
  491. if (itemCfg.subType == 19 || itemCfg.subType == 17 || itemCfg.subType == 21 || itemCfg.subType == 22)
  492. {
  493. //记录道具和位置信息
  494. propIDList.Add(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ItemId);
  495. transDataList.Add(MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ClientPosition));
  496. if(itemCfg.resLayer2 == "t" || itemCfg.resLayer3 == "t")
  497. {
  498. propIDList.Add(-3);
  499. transDataList.Add(MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ClientPosition));
  500. }
  501. }
  502. else if (itemCfg != null && itemCfg.subType == ConstDressUpItemType.BEI_JING)
  503. {
  504. DressUpBgID = itemCfg.id;
  505. }
  506. else
  507. {
  508. dressitemIDList.Add(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ItemId);
  509. }
  510. }
  511. else if (itemCfg != null && itemCfg.itemType == ConstItemType.PHOTOGRAPH)
  512. {
  513. //记录道具和位置信息
  514. propIDList.Add(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ItemId);
  515. transDataList.Add(MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(OneRoleInfo.JudgingInfo.CollocationInfoList[i].ClientPosition));
  516. }
  517. }
  518. }
  519. MathingDressDate.itemList = dressitemIDList;
  520. MathingDressDate.actionId = OneRoleInfo.JudgingInfo.ActionId;
  521. DressPropIdList = propIDList;
  522. TransformDataList = transDataList;
  523. DressUpBgID = OneRoleInfo.JudgingInfo.BagId;
  524. }
  525. public void InsertGameObjectList()
  526. {
  527. int indexRoleData = 0;
  528. for (int i = 0; i < DressPropIdList.Count; i++)
  529. {
  530. if (DressPropIdList[i] == roleID)
  531. {
  532. indexRoleData = i;
  533. }
  534. }
  535. if (itemGameObjs.Count == 0)
  536. {
  537. itemGameObjs.Add(roleGameobj);
  538. }
  539. else
  540. {
  541. if (indexRoleData > itemGameObjs.Count)
  542. {
  543. itemGameObjs.Add(roleGameobj);
  544. }
  545. else
  546. {
  547. itemGameObjs.Insert(indexRoleData, roleGameobj);
  548. }
  549. }
  550. }
  551. }
  552. }