MatchingCompetitionDataManager.cs 21 KB

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