MatchingCompetitionDataManager.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. 
  2. using ET;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Text.RegularExpressions;
  7. using UnityEngine;
  8. using Live2D.Cubism.Rendering;
  9. using FairyGUI;
  10. using UI.MatchingCompetition;
  11. using System.IO;
  12. namespace GFGGame
  13. {
  14. class MatchingCompetitionDataManager : SingletonBase<MatchingCompetitionDataManager>
  15. {
  16. ////搭配赛标记
  17. //public int type = 2;
  18. //位置信息数据索引
  19. public int indexRoleData = 0;
  20. //人物位置信息
  21. public TransformData roleTransFormData = new TransformData();
  22. public GameObject roleGameobj;
  23. public string roleID = "Role";
  24. //*********************搭配数据*********************************
  25. //需要传输的数据:MathingDressDate,DressUpBgID,DressPropIdList,TransformDataList,
  26. public DressUpData MathingDressDate = DressUpData.CreateDefault();
  27. public int DressUpBgID = 0;
  28. //*****这两个id放列表的最后面
  29. //边框id
  30. public int BorderID = 0;
  31. //NpcId
  32. public int NpcID = 0;
  33. //*************=**************
  34. //道具数据,一一对应
  35. //场景名字,自己搭配的数据
  36. public List<string> DressPropNameList = new List<string>();
  37. //道具id
  38. //public List<int> DressPropIdList = new List<int>();
  39. //道具索引
  40. public int DressPropIndex = 0;
  41. //道具索引字典
  42. public Dictionary<string, TransformData> DressPropTransInfoDic = new Dictionary<string, TransformData>();
  43. //道具位置信息
  44. public List<TransformData> TransformDataList = new List<TransformData>();
  45. public List<GameObject> itemGameObjs = new List<GameObject>();
  46. //所有信息的列表,用于前后端交互
  47. public List<CollocationInfo> AllDressIDInfoList = new List<CollocationInfo>();
  48. //public List<int> _equipSceneData = new List<int>();//当前穿戴的场景数据(从套装获得)
  49. //***************************************************************
  50. public int MatchingCompetitionSeason = 1;
  51. public int MatchingState = 1;
  52. public long MatchingEndTimes = 0;
  53. public long WorksID = 0;
  54. public string TempPictureUrl = "";
  55. public int MatchingRemainingTimes = 1;
  56. public MyWorksIdInfo myWorks = new MyWorksIdInfo();
  57. public List<ItemInfoProto> SpecialBonusList = new List<ItemInfoProto>();
  58. /// <summary>
  59. /// 搭配赛相册
  60. /// </summary>
  61. /// <typeparam name="PoemPhotoData"></typeparam>
  62. /// <returns></returns>
  63. public List<PoemPhotoData> MatchingPhotoInfos = new List<PoemPhotoData>();
  64. //角色详情界面图片信息
  65. public NTexture DetailNtexture;
  66. //自己的搭配图片
  67. public NTexture MyNtextture;
  68. public byte[] MyBytes;
  69. //本期排行榜数据
  70. public List<MatchingPhotoWorksData> _currentRankList = new List<MatchingPhotoWorksData>();
  71. //往期作品集
  72. public List<MatchingWorksData> _BeforeWorksList = new List<MatchingWorksData>();
  73. //往期排行榜数据
  74. public List<MatchingPhotoWorksData> _BeforeRankList = new List<MatchingPhotoWorksData>();
  75. //根据时间判断:1:集结期 2:评选期 3;结算期
  76. //public int CheckCompetitionState()
  77. //{
  78. // long currentTime = TimeHelper.ServerNow();
  79. // DateTime dateTime = DateTimeOffset.FromUnixTimeSeconds(currentTime).DateTime;
  80. // // 获取星期几
  81. // DayOfWeek dayOfWeek = dateTime.DayOfWeek;
  82. // int week = (int)dayOfWeek;
  83. // int hour = dateTime.Hour;
  84. // if(week == 0)
  85. // {
  86. // if(hour >= 21)
  87. // {
  88. // return 3;
  89. // }
  90. // else
  91. // {
  92. // return 2;
  93. // }
  94. // }
  95. // if(week <= 3 && week >= 1)
  96. // {
  97. // if(week == 3 && hour >= 5)
  98. // {
  99. // return 2;
  100. // }
  101. // if(week == 1 && hour < 5)
  102. // {
  103. // return 3;
  104. // }
  105. // return 1;
  106. // }
  107. // else if(week > 3 && week <= 6)
  108. // {
  109. // return 2;
  110. // }
  111. // return -1;
  112. //}
  113. public void ConvertInfoToList()
  114. {
  115. //将所有需要存储的信息转换成list
  116. AllDressIDInfoList.Clear();
  117. foreach(var item in MathingDressDate.itemList)
  118. {
  119. CollocationInfo itemInfo = new CollocationInfo();
  120. itemInfo.ItemId = item.ToString();
  121. itemInfo.ClientPosition = "";
  122. AllDressIDInfoList.Add(itemInfo);
  123. }
  124. foreach (var item in DressPropTransInfoDic)
  125. {
  126. CollocationInfo itemInfo = new CollocationInfo();
  127. itemInfo.ItemId = item.Key;
  128. string transStr = item.Value.position.x.ToString() + "_" + item.Value.position.y.ToString() + "_"
  129. + item.Value.position.z.ToString()
  130. + "_" + item.Value.rotationZ.ToString()
  131. + "_" + item.Value.scale.x.ToString() + "_" +
  132. item.Value.scale.y.ToString() + "_" + item.Value.scale.z.ToString();
  133. itemInfo.ClientPosition = transStr;
  134. AllDressIDInfoList.Add(itemInfo);
  135. }
  136. //for(int i = 0;i< DressPropIdList.Count;i++)
  137. //{
  138. // CollocationInfo itemInfo = new CollocationInfo();
  139. // itemInfo.ItemId = DressPropIdList[i];
  140. // string transStr = TransformDataList[i].position.x.ToString()+"_" + TransformDataList[i].position.y.ToString() + "_"
  141. // + TransformDataList[i].position.z.ToString()
  142. // + "_" + TransformDataList[i].rotationZ.ToString()
  143. // + "_" + TransformDataList[i].scale.x.ToString() + "_" +
  144. // TransformDataList[i].scale.y.ToString() + "_" + TransformDataList[i].scale.z.ToString();
  145. // itemInfo.ClientPosition = transStr;
  146. // AllDressIDInfoList.Add(itemInfo);
  147. //}
  148. CollocationInfo itemBgInfo = new CollocationInfo();
  149. itemBgInfo.ItemId = MatchingCompetitionDataManager.Instance.DressUpBgID.ToString();
  150. itemBgInfo.ClientPosition = "";
  151. AllDressIDInfoList.Add(itemBgInfo);
  152. CollocationInfo itemActionInfo = new CollocationInfo();
  153. itemActionInfo.ItemId = MatchingCompetitionDataManager.Instance.MathingDressDate.actionId.ToString();
  154. itemActionInfo.ClientPosition = "";
  155. AllDressIDInfoList.Add(itemActionInfo);
  156. }
  157. //解析后台获取的信息
  158. public void AnalysisInfoToList()
  159. {
  160. List<int> dressitemIDList = new List<int>();
  161. List<int> propIDList = new List<int>();
  162. List<TransformData> transDataList = new List<TransformData>();
  163. DressUpBgID = 180001;
  164. MathingDressDate.bgId = 180001;
  165. MathingDressDate.actionId = 0;
  166. DressPropTransInfoDic.Clear();
  167. for (int i = 0; i < AllDressIDInfoList.Count; i++)
  168. {
  169. if(AllDressIDInfoList[i].ItemId == roleID)
  170. {
  171. //propIDList.Add(AllDressIDInfoList[i].ItemId);
  172. //transDataList.Add(AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  173. if (!DressPropTransInfoDic.ContainsKey(AllDressIDInfoList[i].ItemId))
  174. {
  175. DressPropTransInfoDic.Add(AllDressIDInfoList[i].ItemId.ToString(), AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  176. }
  177. }
  178. else
  179. {
  180. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(GetIDByString(AllDressIDInfoList[i].ItemId));
  181. if (itemCfg != null && itemCfg.itemType == ConstItemType.DRESS_UP)
  182. {
  183. if(itemCfg.subType == 19 || itemCfg.subType == 17 || itemCfg.subType == 21|| itemCfg.subType == 22)
  184. {
  185. //记录道具和位置信息
  186. //propIDList.Add(GetIDByString(AllDressIDInfoList[i].ItemId));
  187. //transDataList.Add(AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  188. if(GetIDListByString(AllDressIDInfoList[i].ItemId).Count > 1)
  189. {
  190. if (!DressPropTransInfoDic.ContainsKey(AllDressIDInfoList[i].ItemId))
  191. {
  192. DressPropTransInfoDic.Add(AllDressIDInfoList[i].ItemId.ToString(), AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  193. }
  194. }
  195. }
  196. else if (itemCfg != null && itemCfg.subType == ConstDressUpItemType.BEI_JING)
  197. {
  198. DressUpBgID = itemCfg.id;
  199. MathingDressDate.bgId = itemCfg.id;
  200. }
  201. else
  202. {
  203. dressitemIDList.Add(GetIDByString(AllDressIDInfoList[i].ItemId));
  204. }
  205. }
  206. else if (itemCfg != null && itemCfg.itemType == ConstItemType.PHOTOGRAPH)
  207. {
  208. //记录道具和位置信息
  209. //propIDList.Add(GetIDByString(AllDressIDInfoList[i].ItemId));
  210. //transDataList.Add(AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  211. if (!DressPropTransInfoDic.ContainsKey(AllDressIDInfoList[i].ItemId))
  212. {
  213. DressPropTransInfoDic.Add(AllDressIDInfoList[i].ItemId.ToString(), AnalysisStringToTransform(AllDressIDInfoList[i].ClientPosition));
  214. }
  215. }
  216. else if(itemCfg == null)
  217. {
  218. SuitCfg actionId = SuitCfgArray.Instance.GetCfg(GetIDByString(AllDressIDInfoList[i].ItemId));
  219. if(actionId !=null)
  220. {
  221. MathingDressDate.actionId = GetIDByString(AllDressIDInfoList[i].ItemId);
  222. }
  223. }
  224. }
  225. }
  226. MathingDressDate.itemList = dressitemIDList;
  227. //DressPropIdList = propIDList;
  228. //TransformDataList = transDataList;
  229. }
  230. public TransformData AnalysisStringToTransform(string strTrans)
  231. {
  232. TransformData transData = new TransformData();
  233. string[] parts = Regex.Split(strTrans, "_");
  234. if(parts.Length > 6)
  235. {
  236. transData.position.x = float.Parse(parts[0]);
  237. transData.position.y = float.Parse(parts[1]);
  238. transData.position.z = float.Parse(parts[2]);
  239. transData.rotationZ = float.Parse(parts[3]);
  240. transData.scale.x = float.Parse(parts[4]);
  241. transData.scale.y = float.Parse(parts[5]);
  242. transData.scale.z = float.Parse(parts[6]);
  243. }
  244. return transData;
  245. }
  246. //存储道具信息
  247. public void SetTransformData()
  248. {
  249. DressPropNameList.Clear();
  250. TransformDataList.Clear();
  251. DressPropTransInfoDic.Clear();
  252. for (int i =0;i<itemGameObjs.Count;i++)
  253. {
  254. TransformData itemData = new TransformData();
  255. if (itemGameObjs[i].name == "Role")
  256. {
  257. roleTransFormData.position = itemGameObjs[i].transform.position;
  258. roleTransFormData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  259. roleTransFormData.scale = itemGameObjs[i].transform.localScale;
  260. TransformDataList.Add(roleTransFormData);
  261. DressPropNameList.Add(itemGameObjs[i].name);
  262. if (!DressPropTransInfoDic.ContainsKey(itemGameObjs[i].name))
  263. {
  264. DressPropTransInfoDic.Add(itemGameObjs[i].name, roleTransFormData);
  265. }
  266. }
  267. else if (itemGameObjs[i].name == "Border")
  268. {
  269. itemData.position = itemGameObjs[i].transform.position;
  270. itemData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  271. itemData.scale = itemGameObjs[i].transform.localScale;
  272. TransformDataList.Add(roleTransFormData);
  273. DressPropNameList.Add(itemGameObjs[i].name);
  274. if (!DressPropTransInfoDic.ContainsKey(itemGameObjs[i].name))
  275. {
  276. DressPropTransInfoDic.Add(BorderID.ToString(), itemData);
  277. }
  278. }
  279. else if (itemGameObjs[i].name == "Npc")
  280. {
  281. itemData.position = itemGameObjs[i].transform.position;
  282. itemData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  283. itemData.scale = itemGameObjs[i].transform.localScale;
  284. TransformDataList.Add(roleTransFormData);
  285. DressPropNameList.Add(itemGameObjs[i].name);
  286. if (!DressPropTransInfoDic.ContainsKey(itemGameObjs[i].name))
  287. {
  288. DressPropTransInfoDic.Add(NpcID.ToString(), itemData);
  289. }
  290. }
  291. else
  292. {
  293. itemData.position = itemGameObjs[i].transform.position;
  294. itemData.rotationZ = itemGameObjs[i].transform.eulerAngles.z;
  295. itemData.scale = itemGameObjs[i].transform.localScale;
  296. TransformDataList.Add(itemData);
  297. DressPropNameList.Add(itemGameObjs[i].name);
  298. if(!DressPropTransInfoDic.ContainsKey(itemGameObjs[i].name))
  299. {
  300. DressPropTransInfoDic.Add(itemGameObjs[i].name, itemData);
  301. }
  302. }
  303. }
  304. //SetNameToIdList();
  305. }
  306. public int GetIDByString(string name)
  307. {
  308. int id = 0;
  309. //使用正则表达式分割字符串
  310. string[] parts = Regex.Split(name, "_");
  311. if (parts.Length > 0)
  312. {
  313. string vl = parts[0];
  314. bool isNumeric = int.TryParse(vl, out _);
  315. if (vl == "Role")
  316. {
  317. return -1;
  318. }
  319. else if (vl == "Border")
  320. {
  321. return -2;
  322. }
  323. else if (vl == "Npc")
  324. {
  325. return -3;
  326. }
  327. else if(!isNumeric)
  328. {
  329. return -4;
  330. }
  331. id = int.Parse(parts[0]);
  332. }
  333. return id;
  334. }
  335. public List<int> GetIDListByString(string name)
  336. {
  337. List<int> idList = new List<int>();
  338. string[] parts = Regex.Split(name, "_");
  339. foreach(string id in parts)
  340. {
  341. idList.Add(int.Parse(id));
  342. }
  343. return idList;
  344. }
  345. //将名字转换成道具id
  346. //public void SetNameToIdList()
  347. //{
  348. // //DressPropIdList.Clear();
  349. // int flog_prefix = 0;
  350. // int flog_suffix = 0;
  351. // for (int i = 0; i < DressPropNameList.Count; i++)
  352. // {
  353. // bool containsUnderscore = Regex.IsMatch(DressPropNameList[i], "_");
  354. // if(!containsUnderscore)
  355. // {
  356. // if (DressPropNameList[i] == "Role")
  357. // {
  358. // DressPropIdList.Add(roleID);
  359. // }
  360. // else if (DressPropNameList[i] == "Border")
  361. // {
  362. // if (BorderID != 0)
  363. // {
  364. // DressPropIdList.Add(BorderID);
  365. // }
  366. // }
  367. // else if (DressPropNameList[i] == "Npc")
  368. // {
  369. // if (NpcID != 0)
  370. // {
  371. // DressPropIdList.Add(NpcID);
  372. // }
  373. // }
  374. // }
  375. // else
  376. // {
  377. // // 使用正则表达式分割字符串
  378. // string[] parts = Regex.Split(DressPropNameList[i], "_");
  379. // int partID = int.Parse(parts[0]);
  380. // if(flog_prefix == int.Parse(parts[0]))
  381. // {
  382. // if((flog_suffix == 3 && int.Parse(parts[1]) == 1)|| (flog_suffix == 1 && int.Parse(parts[1]) == 3))
  383. // {
  384. // flog_prefix = 0;
  385. // flog_suffix = 0;
  386. // continue;
  387. // }
  388. // if ((flog_suffix == 2 && int.Parse(parts[1]) == 1) || (flog_suffix == 1 && int.Parse(parts[1]) == 2))
  389. // {
  390. // flog_prefix = 0;
  391. // flog_suffix = 0;
  392. // continue;
  393. // }
  394. // }
  395. // flog_prefix = int.Parse(parts[0]);
  396. // flog_suffix = int.Parse(parts[1]);
  397. // DressPropIdList.Add(partID);
  398. // }
  399. // }
  400. //}
  401. //将穿戴数据分类
  402. //public void ClassifyEquipData()
  403. //{
  404. // _equipSceneData.Clear();
  405. // PhotographDataManager.Instance.dressUpObj = new DressUpObj();
  406. // //for (int i = 0; i < MathingDressDate.itemList.Count; i++)
  407. // //{
  408. // // int itemId = MathingDressDate.itemList[i];
  409. // // if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId, false))
  410. // // {
  411. // // if (!_equipSceneData.ContainsKey(itemId))
  412. // // {
  413. // // _equipSceneData.Add(itemId, new List<int>());
  414. // // }
  415. // // _equipSceneData[itemId].Add(itemId);
  416. // // }
  417. // //}
  418. // for(int i =0;i<DressPropIdList.Count;i++)
  419. // {
  420. // int itemId = DressPropIdList[i];
  421. // if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId, false))
  422. // {
  423. // _equipSceneData.Add(itemId);
  424. // }
  425. // }
  426. //}
  427. public void InsertGameObjectList()
  428. {
  429. int i = 0;
  430. foreach(var item in DressPropTransInfoDic)
  431. {
  432. i++;
  433. if (item.Key == roleID)
  434. {
  435. indexRoleData = i;
  436. break;
  437. }
  438. indexRoleData = i;
  439. }
  440. if(itemGameObjs.Count ==0)
  441. {
  442. itemGameObjs.Add(roleGameobj);
  443. }
  444. else
  445. {
  446. if (indexRoleData > itemGameObjs.Count)
  447. {
  448. itemGameObjs.Add(roleGameobj);
  449. }
  450. else
  451. {
  452. itemGameObjs.Insert(indexRoleData, roleGameobj);
  453. }
  454. }
  455. }
  456. public void SetNumToRank(int index,UI_Component4 rankCom)
  457. {
  458. int c1 = 0;
  459. int c2 = 0;
  460. if(index<=3&& index >=1)
  461. {
  462. c2 = index;
  463. }
  464. if (index > 3 && index <= 9)
  465. {
  466. c1 = 0;
  467. }
  468. else if(index >9 && index <= 50)
  469. {
  470. c1 = 1;
  471. }
  472. else
  473. {
  474. c1 = 2;
  475. }
  476. rankCom.m_c1.selectedIndex = c1;
  477. rankCom.m_c2.selectedIndex = c2;
  478. if(c1 == 0)
  479. {
  480. rankCom.m_num3.url = string.Format("ui://MatchingCompetition/{0}",index.ToString());
  481. }
  482. else if(c1 == 1)
  483. {
  484. int one = index / 10;
  485. int two = index % 10;
  486. rankCom.m_num1.url = string.Format("ui://MatchingCompetition/{0}", one.ToString());
  487. rankCom.m_num2.url = string.Format("ui://MatchingCompetition/{0}", two.ToString());
  488. }
  489. else
  490. {
  491. if (index == 0)
  492. {
  493. rankCom.m_RankText.text = "--";
  494. }
  495. else
  496. {
  497. for (int i = 11; i < JudgingRoundRewardCfgArray.Instance.dataArray.Length-1; i++)
  498. {
  499. JudgingRoundRewardCfg judgingCfg = JudgingRoundRewardCfgArray.Instance.GetCfg(i);
  500. JudgingRoundRewardCfg judgingNextCfg = JudgingRoundRewardCfgArray.Instance.GetCfg(i+1);
  501. if (index >= judgingCfg.rank && index < judgingNextCfg.rank)
  502. {
  503. rankCom.m_RankText.text = judgingNextCfg.desc;
  504. }
  505. else
  506. {
  507. rankCom.m_RankText.text = index.ToString();
  508. }
  509. }
  510. }
  511. }
  512. }
  513. public async void AddSceneItem(ItemCfg itemCfg, bool setLayer,int isLeft = 0)
  514. {
  515. Vector3 pos = Vector3.zero;
  516. if (!string.IsNullOrEmpty(itemCfg.resLayer3))
  517. {
  518. DressPropIndex++;
  519. GameObject parentGameObj3 = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, 3,DressPropIndex));
  520. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj3, itemCfg, 3, setLayer,false,isLeft);
  521. if (setLayer)
  522. {
  523. if (parentGameObj3.transform.childCount > 0)
  524. {
  525. parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
  526. pos = parentGameObj3.transform.localPosition;
  527. }
  528. }
  529. }
  530. if (!string.IsNullOrEmpty(itemCfg.resLayer2))
  531. {
  532. DressPropIndex++;
  533. GameObject parentGameObj2 = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, 2,DressPropIndex));
  534. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj2, itemCfg, 2, setLayer,false, isLeft);
  535. if (setLayer)
  536. {
  537. if (parentGameObj2.transform.childCount > 0)
  538. {
  539. parentGameObj2.transform.localPosition = pos == Vector3.zero ? -parentGameObj2.transform.GetChild(0).localPosition : pos;
  540. pos = parentGameObj2.transform.localPosition;
  541. }
  542. }
  543. }
  544. if (!string.IsNullOrEmpty(itemCfg.resLayer1))
  545. {
  546. DressPropIndex++;
  547. GameObject parentGameObj1 = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, 1, DressPropIndex));
  548. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj1, itemCfg, 1, setLayer, false, isLeft);
  549. if (setLayer)
  550. {
  551. if (parentGameObj1.transform.childCount > 0)
  552. {
  553. parentGameObj1.transform.localPosition = pos == Vector3.zero ? -parentGameObj1.transform.GetChild(0).localPosition : pos;
  554. pos = parentGameObj1.transform.localPosition;
  555. }
  556. }
  557. }
  558. }
  559. public async void AddSceneItemOne(ItemCfg itemCfg, int layer,int index, int isLeft = 0, bool setLayer = true)
  560. {
  561. Vector3 pos = Vector3.zero;
  562. if(DressPropIndex <= index)
  563. {
  564. DressPropIndex = index + 1;
  565. }
  566. GameObject parentGameObj3 = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, layer, index));
  567. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj3, itemCfg, layer, setLayer, false, isLeft);
  568. if (setLayer)
  569. {
  570. if (parentGameObj3.transform.childCount > 0)
  571. {
  572. parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
  573. pos = parentGameObj3.transform.localPosition;
  574. }
  575. }
  576. }
  577. public void OnClickBtnRule()
  578. {
  579. ViewManager.Show<MatchingCompetitionRuleTipsView>();
  580. }
  581. //**********下面接口只针对于搭配赛排行榜*************
  582. //不建议频繁修改用户设备上的文件。
  583. //需要在移动平台上管理文件,最好是在应用的沙盒目录内操作
  584. public string LocalRankPath = Application.streamingAssetsPath + "/ImageDPSRank";
  585. public string LocalBeforePath = Application.streamingAssetsPath + "/ImageDPSBe";
  586. public string LoaclMy = Application.streamingAssetsPath + "/ImageMy";
  587. //将获取的图片下载到本地,通过排行榜判断,如果该图片不存在于最新的排行榜内就删除
  588. public void DownloadImageListToLocal(List<Byte[]> imageBytesList, List<long> ImageName,string targerPath)
  589. {
  590. // 检查目录是否存在
  591. if (!Directory.Exists(targerPath))
  592. {
  593. // 目录不存在,创建目录
  594. Directory.CreateDirectory(targerPath);
  595. }
  596. else
  597. {
  598. // 目录已存在
  599. }
  600. for (int i = 0; i < imageBytesList.Count; i++)
  601. {
  602. //判断手机内是否存在该图片
  603. string path = Path.Combine(targerPath, string.Format("/{0}.jpg", ImageName[i].ToString()));
  604. bool fileExists = File.Exists(path);
  605. if (!fileExists)
  606. {
  607. string outputImagePath = targerPath + string.Format("/{0}.jpg", ImageName[i].ToString());
  608. // 保存到磁盘
  609. File.WriteAllBytes(outputImagePath, imageBytesList[i]);
  610. }
  611. }
  612. }
  613. //将获取的图片下载到本地
  614. public void DownloadImageToLocal(Byte[] imageBytesList, long ImageName, string targerPath)
  615. {
  616. // 检查目录是否存在
  617. if (!Directory.Exists(targerPath))
  618. {
  619. // 目录不存在,创建目录
  620. Directory.CreateDirectory(targerPath);
  621. }
  622. else
  623. {
  624. // 目录已存在
  625. }
  626. //判断手机内是否存在该图片
  627. string path = Path.Combine(targerPath, string.Format("/{0}.jpg", ImageName.ToString()));
  628. bool fileExists = File.Exists(path);
  629. if (!fileExists)
  630. {
  631. string outputImagePath = targerPath + string.Format("/{0}.jpg", ImageName.ToString());
  632. // 保存到磁盘
  633. File.WriteAllBytes(outputImagePath, imageBytesList);
  634. }
  635. }
  636. //获取指定目录下所有图片文件
  637. public List<string> GetImageFileNames(string directoryPath)
  638. {
  639. // 检查目录是否存在
  640. if (!Directory.Exists(directoryPath))
  641. {
  642. // 目录不存在,创建目录
  643. Directory.CreateDirectory(directoryPath);
  644. }
  645. else
  646. {
  647. // 目录已存在
  648. }
  649. List<string> imageFileNames = new List<string>();
  650. string[] imageExtensions = { ".png", ".jpg", ".jpeg", ".gif", ".bmp" }; // 支持的图片格式
  651. // 获取目录中所有文件
  652. string[] files = Directory.GetFiles(directoryPath);
  653. // 遍历文件,检查扩展名是否为图片格式
  654. foreach (string file in files)
  655. {
  656. foreach (string extension in imageExtensions)
  657. {
  658. if (Path.GetExtension(file).Equals(extension, StringComparison.OrdinalIgnoreCase))
  659. {
  660. imageFileNames.Add(Path.GetFileName(file));
  661. break; // 找到匹配的扩展名,跳出循环
  662. }
  663. }
  664. }
  665. return imageFileNames;
  666. }
  667. //获取指定图片
  668. public NTexture GetTargetImage(string ImageName,string Path)
  669. {
  670. string AllPath = Path +"/"+ ImageName;
  671. byte[] fileData = File.ReadAllBytes(AllPath);
  672. Texture2D texture = new Texture2D(1, 1);
  673. texture.LoadImage(fileData);
  674. return new NTexture(texture);
  675. }
  676. //删除指定图片
  677. public void DeleteImage(string imagePath)
  678. {
  679. // 检查文件是否存在
  680. if (File.Exists(imagePath))
  681. {
  682. try
  683. {
  684. // 删除文件
  685. File.Delete(imagePath);
  686. //Debug.Log("图片已删除: " + imagePath);
  687. }
  688. catch (Exception e)
  689. {
  690. // 如果出现异常,打印错误信息
  691. Debug.LogError("删除图片时出错: " + e.Message);
  692. }
  693. }
  694. else
  695. {
  696. // 文件不存在
  697. Debug.LogWarning("图片不存在,无法删除: " + imagePath);
  698. }
  699. }
  700. //判断本地图片是否在新获取到的排行榜内
  701. public bool ImageIdIsInRank(string ImageName)
  702. {
  703. foreach (var item in _currentRankList)
  704. {
  705. string rankImageName = item.JudgingInfo.WorksId.ToString() + ".jpg";
  706. if (rankImageName == ImageName)
  707. {
  708. return true;
  709. }
  710. }
  711. return false;
  712. }
  713. //判断排行榜id是否存在本地图片
  714. public bool RankIdisInLocal(string ImageName, List<string> LoaclList)
  715. {
  716. foreach (var item in LoaclList)
  717. {
  718. if (item == ImageName)
  719. {
  720. return true;
  721. }
  722. }
  723. return false;
  724. }
  725. //通过作品id从本地获取下载的图片如果没有则下载到本地保存,如果有直接加载
  726. //这个接口只对搭配赛有用,因为只修改了搭配赛的数据
  727. public NTexture GetNtextrueByLocal(string ImageName)
  728. {
  729. NTexture LocalNtextture = null;
  730. return LocalNtextture;
  731. }
  732. //****************************************************
  733. }
  734. class MatchingOneDataManager : SingletonBase<MatchingOneDataManager>
  735. {
  736. //其他玩家信息用于展示
  737. public MatchingPhotoWorksData OneRoleInfo = new MatchingPhotoWorksData();
  738. //人物位置信息
  739. public TransformData roleTransFormData = new TransformData();
  740. public GameObject roleGameobj;
  741. public string roleID = "Role";
  742. //*********************搭配数据*********************************
  743. //需要传输的数据:MathingDressDate,DressUpBgID,DressPropIdList,TransformDataList,
  744. public DressUpData MathingDressDate = DressUpData.CreateDefault();
  745. public int DressUpBgID = 0;
  746. //*****这两个id放列表的最后面
  747. //边框id
  748. public int BorderID = 0;
  749. //NpcId
  750. public int NpcID = 0;
  751. //道具数据,一一对应
  752. //道具id
  753. //public List<int> DressPropIdList = new List<int>();
  754. //道具位置信息
  755. public List<TransformData> TransformDataList = new List<TransformData>();
  756. //道具索引
  757. public int DressPropIndex = 0;
  758. //道具索引字典
  759. public Dictionary<string, TransformData> DressPropTransInfoDic = new Dictionary<string, TransformData>();
  760. public List<GameObject> itemGameObjs = new List<GameObject>();
  761. //***************************************************************
  762. //解析后台获取的信息
  763. public void AnalysisInfoToList()
  764. {
  765. List<int> dressitemIDList = new List<int>();
  766. List<int> propIDList = new List<int>();
  767. List<TransformData> transDataList = new List<TransformData>();
  768. DressPropTransInfoDic.Clear();
  769. for (int i = 0; i < OneRoleInfo.JudgingInfo.CollocationInfoList.Count; i++)
  770. {
  771. CollocationInfo colloctItemInfo = OneRoleInfo.JudgingInfo.CollocationInfoList[i];
  772. if (colloctItemInfo.ItemId == roleID)
  773. {
  774. //propIDList.Add(colloctItemInfo.ItemId);
  775. //transDataList.Add(MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(colloctItemInfo.ClientPosition));
  776. if(!DressPropTransInfoDic.ContainsKey(colloctItemInfo.ItemId))
  777. {
  778. DressPropTransInfoDic.Add(colloctItemInfo.ItemId, MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(colloctItemInfo.ClientPosition));
  779. }
  780. }
  781. else
  782. {
  783. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(MatchingCompetitionDataManager.Instance.GetIDByString( colloctItemInfo.ItemId));
  784. if (itemCfg != null && itemCfg.itemType == ConstItemType.DRESS_UP)
  785. {
  786. if (itemCfg.subType == 19 || itemCfg.subType == 17 || itemCfg.subType == 21 || itemCfg.subType == 22)
  787. {
  788. //记录道具和位置信息
  789. //propIDList.Add(colloctItemInfo.ItemId);
  790. //transDataList.Add(MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(colloctItemInfo.ClientPosition));
  791. if (!DressPropTransInfoDic.ContainsKey(colloctItemInfo.ItemId))
  792. {
  793. DressPropTransInfoDic.Add(colloctItemInfo.ItemId, MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(colloctItemInfo.ClientPosition));
  794. }
  795. }
  796. else if (itemCfg != null && itemCfg.subType == ConstDressUpItemType.BEI_JING)
  797. {
  798. DressUpBgID = itemCfg.id;
  799. }
  800. else
  801. {
  802. dressitemIDList.Add(MatchingCompetitionDataManager.Instance.GetIDByString(colloctItemInfo.ItemId));
  803. }
  804. }
  805. else if (itemCfg != null && itemCfg.itemType == ConstItemType.PHOTOGRAPH)
  806. {
  807. //记录道具和位置信息
  808. //propIDList.Add(colloctItemInfo.ItemId);
  809. //transDataList.Add(MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(colloctItemInfo.ClientPosition));
  810. if (!DressPropTransInfoDic.ContainsKey(colloctItemInfo.ItemId))
  811. {
  812. DressPropTransInfoDic.Add(colloctItemInfo.ItemId, MatchingCompetitionDataManager.Instance.AnalysisStringToTransform(colloctItemInfo.ClientPosition));
  813. }
  814. }
  815. }
  816. }
  817. MathingDressDate.itemList = dressitemIDList;
  818. MathingDressDate.actionId = OneRoleInfo.JudgingInfo.ActionId;
  819. //DressPropIdList = propIDList;
  820. //TransformDataList = transDataList;
  821. DressUpBgID = OneRoleInfo.JudgingInfo.BagId;
  822. }
  823. public void InsertGameObjectList()
  824. {
  825. int indexRoleData = 0;
  826. int i = 0;
  827. foreach (var item in DressPropTransInfoDic)
  828. {
  829. i++;
  830. if (item.Key == roleID)
  831. {
  832. indexRoleData = i;
  833. }
  834. }
  835. if (itemGameObjs.Count == 0)
  836. {
  837. itemGameObjs.Add(roleGameobj);
  838. }
  839. else
  840. {
  841. if (indexRoleData > itemGameObjs.Count)
  842. {
  843. itemGameObjs.Add(roleGameobj);
  844. }
  845. else
  846. {
  847. itemGameObjs.Insert(indexRoleData, roleGameobj);
  848. }
  849. }
  850. }
  851. }
  852. }