MatchingCompetitionDataManager.cs 19 KB

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