MatchingCompetitionDataManager.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. //*********************搭配数据*********************************
  22. //需要传输的数据:MathingDressDate,DressUpBgID,DressPropIdList,TransformDataList,
  23. public DressUpData MathingDressDate = DressUpData.CreateDefault();
  24. public int DressUpBgID = 0;
  25. //道具数据,一一对应
  26. //场景名字,自己搭配的数据
  27. public List<string> DressPropNameList = new List<string>();
  28. //道具id
  29. public List<int> DressPropIdList = new List<int>();
  30. //道具位置信息
  31. public List<TransformData> TransformDataList = new List<TransformData>();
  32. public List<GameObject> itemGameObjs = new List<GameObject>();
  33. public List<int> _equipSceneData = new List<int>();//当前穿戴的场景数据(从套装获得)
  34. //***************************************************************
  35. public int MatchingCompetitionSeason = 1;
  36. public int MatchingRemainingTimes = 1;
  37. //本期排行榜数据
  38. public List<MatchingPlayerData> _currentRankList = new List<MatchingPlayerData>() { new MatchingPlayerData()};
  39. //往期排行榜数据
  40. public Dictionary<int, MatchingPlayerData> _beforeRankDic = new Dictionary<int, MatchingPlayerData>();
  41. //根据时间判断:1:集结期 2:评选期 3;结算期
  42. public int CheckCompetitionState()
  43. {
  44. long currentTime = TimeHelper.ServerNow();
  45. DateTime dateTime = DateTimeOffset.FromUnixTimeSeconds(currentTime).DateTime;
  46. // 获取星期几
  47. DayOfWeek dayOfWeek = dateTime.DayOfWeek;
  48. int week = (int)dayOfWeek;
  49. int hour = dateTime.Hour;
  50. if(week == 0)
  51. {
  52. if(hour >= 21)
  53. {
  54. return 3;
  55. }
  56. else
  57. {
  58. return 2;
  59. }
  60. }
  61. if(week <= 3 && week >= 1)
  62. {
  63. if(week == 3 && hour >= 5)
  64. {
  65. return 2;
  66. }
  67. if(week == 1 && hour < 5)
  68. {
  69. return 3;
  70. }
  71. return 1;
  72. }
  73. else if(week > 3 && week <= 6)
  74. {
  75. return 2;
  76. }
  77. return -1;
  78. }
  79. //存储道具信息
  80. public void SetTransformData()
  81. {
  82. DressPropNameList.Clear();
  83. TransformDataList.Clear();
  84. for (int i =0;i<itemGameObjs.Count;i++)
  85. {
  86. if(itemGameObjs[i].name == "Role")
  87. {
  88. TransformData itemData = new TransformData();
  89. roleTransFormData.position = itemGameObjs[i].transform.position;
  90. roleTransFormData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  91. roleTransFormData.scale = itemGameObjs[i].transform.localScale;
  92. TransformDataList.Add(roleTransFormData);
  93. DressPropNameList.Add(itemGameObjs[i].name);
  94. }
  95. else
  96. {
  97. TransformData itemData = new TransformData();
  98. itemData.position = itemGameObjs[i].transform.position;
  99. itemData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  100. itemData.scale = itemGameObjs[i].transform.localScale;
  101. TransformDataList.Add(itemData);
  102. DressPropNameList.Add(itemGameObjs[i].name);
  103. }
  104. }
  105. SetNameToIdList();
  106. }
  107. //将名字转换成道具id
  108. public void SetNameToIdList()
  109. {
  110. DressPropIdList.Clear();
  111. int flog_id = 0;
  112. for (int i = 0; i < DressPropNameList.Count; i++)
  113. {
  114. bool containsUnderscore = Regex.IsMatch(DressPropNameList[i], "_");
  115. if(!containsUnderscore)
  116. {
  117. indexRoleData = i;
  118. }
  119. else
  120. {
  121. // 使用正则表达式分割字符串
  122. string[] parts = Regex.Split(DressPropNameList[i], "_");
  123. int partID = int.Parse(parts[0]);
  124. if(flog_id == 3 && int.Parse(parts[1]) == 1)
  125. {
  126. continue;
  127. }
  128. flog_id = int.Parse(parts[1]);
  129. DressPropIdList.Add(partID);
  130. }
  131. }
  132. }
  133. //将穿戴数据分类
  134. public void ClassifyEquipData()
  135. {
  136. _equipSceneData.Clear();
  137. PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  138. //for (int i = 0; i < MathingDressDate.itemList.Count; i++)
  139. //{
  140. // int itemId = MathingDressDate.itemList[i];
  141. // if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId, false))
  142. // {
  143. // if (!_equipSceneData.ContainsKey(itemId))
  144. // {
  145. // _equipSceneData.Add(itemId, new List<int>());
  146. // }
  147. // _equipSceneData[itemId].Add(itemId);
  148. // }
  149. //}
  150. for(int i =0;i<DressPropIdList.Count;i++)
  151. {
  152. int itemId = DressPropIdList[i];
  153. if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId, false))
  154. {
  155. _equipSceneData.Add(itemId);
  156. }
  157. }
  158. }
  159. public void InsertGameObjectList()
  160. {
  161. if(itemGameObjs.Count ==0)
  162. {
  163. itemGameObjs.Add(roleGameobj);
  164. }
  165. else
  166. {
  167. itemGameObjs.Insert(indexRoleData, roleGameobj);
  168. }
  169. }
  170. public void SetNumToRank(int index,UI_Component4 rankCom)
  171. {
  172. int c1 = 0;
  173. int c2 = 0;
  174. if(index<=3&& index >=1)
  175. {
  176. c2 = index;
  177. }
  178. if (index > 3 && index <= 9)
  179. {
  180. c1 = 0;
  181. }
  182. else if(index >9 && index <= 20)
  183. {
  184. c1 = 1;
  185. }
  186. else
  187. {
  188. c1 = 2;
  189. }
  190. rankCom.m_c1.selectedIndex = c1;
  191. rankCom.m_c2.selectedIndex = c2;
  192. if(c1 == 0)
  193. {
  194. rankCom.m_num3.url = string.Format("ui://MatchingCompetition/{0}",index.ToString());
  195. }
  196. else if(c1 == 1)
  197. {
  198. int one = index / 10;
  199. int two = index % 10;
  200. rankCom.m_num1.url = string.Format("ui://MatchingCompetition/{0}", one.ToString());
  201. rankCom.m_num2.url = string.Format("ui://MatchingCompetition/{0}", two.ToString());
  202. }
  203. else
  204. {
  205. rankCom.m_RankText.text = index.ToString();
  206. }
  207. }
  208. public async void AddSceneItem(ItemCfg itemCfg, bool setLayer)
  209. {
  210. Vector3 pos = Vector3.zero;
  211. if (!string.IsNullOrEmpty(itemCfg.resLayer3))
  212. {
  213. GameObject parentGameObj3 = new GameObject(string.Format("{0}_{1}", itemCfg.id, 3));
  214. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj3, itemCfg, 3, setLayer);
  215. if (setLayer)
  216. {
  217. if (parentGameObj3.transform.childCount > 0)
  218. {
  219. parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
  220. pos = parentGameObj3.transform.localPosition;
  221. }
  222. }
  223. }
  224. if (!string.IsNullOrEmpty(itemCfg.resLayer2))
  225. {
  226. GameObject parentGameObj2 = new GameObject(string.Format("{0}_{1}", itemCfg.id, 2));
  227. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj2, itemCfg, 2, setLayer);
  228. if (setLayer)
  229. {
  230. if (parentGameObj2.transform.childCount > 0)
  231. {
  232. parentGameObj2.transform.localPosition = pos == Vector3.zero ? -parentGameObj2.transform.GetChild(0).localPosition : pos;
  233. pos = parentGameObj2.transform.localPosition;
  234. }
  235. }
  236. }
  237. if (!string.IsNullOrEmpty(itemCfg.resLayer1))
  238. {
  239. GameObject parentGameObj1 = new GameObject(string.Format("{0}_{1}", itemCfg.id, 1));
  240. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj1, itemCfg, 1, setLayer);
  241. if (setLayer)
  242. {
  243. if (parentGameObj1.transform.childCount > 0)
  244. {
  245. parentGameObj1.transform.localPosition = pos == Vector3.zero ? -parentGameObj1.transform.GetChild(0).localPosition : pos;
  246. pos = parentGameObj1.transform.localPosition;
  247. }
  248. }
  249. }
  250. }
  251. public void OnClickBtnRule()
  252. {
  253. ViewManager.Show<MatchingCompetitionRuleTipsView>();
  254. }
  255. }
  256. class OtherMatchingCompetitionDataManager : SingletonBase<OtherMatchingCompetitionDataManager>
  257. {
  258. //其他玩家信息用于展示
  259. //人物位置信息
  260. public TransformData roleTransFormData = new TransformData();
  261. public GameObject roleGameobj;
  262. //*********************搭配数据*********************************
  263. //需要传输的数据:MathingDressDate,DressUpBgID,DressPropIdList,TransformDataList,
  264. public DressUpData MathingDressDate = DressUpData.CreateDefault();
  265. public int DressUpBgID = 0;
  266. //道具数据,一一对应
  267. //场景名字,自己搭配的数据
  268. public List<string> DressPropNameList = new List<string>();
  269. //道具id
  270. public List<int> DressPropIdList = new List<int>();
  271. //道具位置信息
  272. public List<TransformData> TransformDataList = new List<TransformData>();
  273. public List<GameObject> itemGameObjs = new List<GameObject>();
  274. public List<int> _equipSceneData = new List<int>();//当前穿戴的场景数据
  275. //***************************************************************
  276. }
  277. }