MatchingCompetitionDataManager.cs 38 KB

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