Player.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. using DragonBones;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Linq;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using Animation = DragonBones.Animation;
  11. using Slot = DragonBones.Slot;
  12. using Random = UnityEngine.Random;
  13. using Transform = UnityEngine.Transform;
  14. public class PlayerLabel
  15. {
  16. public static string MessageBox = "MessageBox";
  17. public static string NickName = "NickName";
  18. public static string Pivot = "Pivot";
  19. public static string Shadow = "Shadow";
  20. public static string ExpressionMeshFilter = "ExpressionMeshFilter";
  21. public static string ShadowParent = "ShadowParent";
  22. public static string Player = "Player";
  23. public static string RightPos = "RightPos";
  24. public static string LeftPos = "LeftPos";
  25. public static string EnterGameTra = "EnterGameTra";
  26. }
  27. public enum BodyPart
  28. {
  29. Leg = 0,
  30. LeftHand = 1,
  31. RightHand = 2,
  32. LeftLongSleeve = 3,
  33. LeftShortSleeve = 4,
  34. RightLongSleeve = 5,
  35. RightShortSleeve = 6,
  36. Neck = 7,
  37. Eye = 8,
  38. Top = 9,
  39. Shoe = 10,
  40. Head = 11,
  41. Wing = 12,
  42. Dress = 13,
  43. Mouse = 14,
  44. Headwear = 15,
  45. }
  46. public class ExchangeInfo
  47. {
  48. public float ExchangeRate;
  49. public double Value;
  50. public Current Current;
  51. public static void GetExchangeValue(ExchangeInfo info, StaticsManager.ConsumeModule consumeModule)
  52. {
  53. if (info.Current == Current.Coin)
  54. {
  55. Manager.AddCoin(info.Value, StaticsManager.ItemID.获得金币, consumeModule);
  56. }
  57. else if (info.Current == Current.Diamond)
  58. {
  59. Manager.AddDiamond(info.Value, StaticsManager.ItemID.获得钻石, consumeModule);
  60. }
  61. }
  62. public static ExchangeInfo GetExchangeInfo(Current current, double amt, float rate)
  63. {
  64. ExchangeInfo info = new ExchangeInfo();
  65. info.ExchangeRate = rate;
  66. info.Value = amt * rate;
  67. info.Current = current;
  68. return info;
  69. }
  70. }
  71. public class CloseItemLabel
  72. {
  73. public static string Icon1 = "Icon1";
  74. public static string Icon2 = "Icon2";
  75. public static string Icon3 = "Icon3";
  76. public static string CloseItem = "CloseItem";
  77. public static string BuyBtn = "BuyBtn";
  78. public static string BuyBtnLab = "BuyBtnLab";
  79. }
  80. public class CloseItem
  81. {
  82. public enum CloseType
  83. {
  84. Top,
  85. Hair,
  86. Wing,
  87. Dress,
  88. Decarator,
  89. Shoe,
  90. }
  91. #region Config
  92. public string Name
  93. {
  94. get { return Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.DressRoom, FullID)); }
  95. }
  96. public static string IDPrefix = "Armature";
  97. public string FullID
  98. {
  99. get { return IDPrefix + ID; }
  100. }
  101. public int ID;
  102. public int Index;
  103. public int BuyLevel;
  104. public int PixelSize;
  105. public bool IsBought;
  106. public string ArmatureName;
  107. public string[] ExtraArmatureNames;
  108. public BodyPart[] ExtraBodyParts;
  109. public float SpriteAlpha;
  110. public float IconOffset;
  111. public TextPlus BuyBtnLab;
  112. public Sprite[] Sprites;
  113. public Image Icon1;
  114. public Image Icon2;
  115. public Image Icon3;
  116. public Button BuyBtn;
  117. public Button DressBtn;
  118. public Vector2 IconOffset1;
  119. public Vector2 IconOffset2;
  120. public BodyPart BodyPart;
  121. public Transform Transform;
  122. public CloseType Type;
  123. public bool Unavailable; //True-不显示
  124. public double BuyCost;
  125. public double BuyAdvanceCost;
  126. public Current BuyCurrent;
  127. public Current BuyAdvanceCurrent;
  128. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  129. #endregion
  130. public CloseItem(XmlAttributeCollection attribute)
  131. {
  132. Unavailable = Auxiliary.StringToBool(attribute[19].Value, false);
  133. ID = Auxiliary.StringToInt(attribute[0].Value, -1);
  134. BodyPart = BodyPartParse(attribute[4].Value);
  135. ArmatureName = attribute[16].Value;
  136. PlayerManager.CloseIDDictionary.Add(ArmatureName, ID);
  137. PlayerManager.CloseItemDictionary.Add(ID, this);
  138. if (Unavailable)
  139. {
  140. return;
  141. }
  142. Type = TypeParse(attribute[2].Value);
  143. Index = Auxiliary.StringToInt(attribute[3].Value, -1);
  144. BuyLevel = Auxiliary.StringToInt(attribute[5].Value, 0);
  145. BuyCurrent = Auxiliary.CurrentParse(attribute[6].Value);
  146. BuyCost = Auxiliary.StringToDouble(attribute[7].Value, 0);
  147. BuyAdvanceCurrent = Auxiliary.CurrentParse(attribute[8].Value);
  148. BuyAdvanceCost = Auxiliary.StringToDouble(attribute[9].Value, 0);
  149. PixelSize = Auxiliary.StringToInt(attribute[10].Value, 100);
  150. IconOffset = Auxiliary.StringToFloat(attribute[11].Value, 0);
  151. IconOffset1 = Auxiliary.StringToVector(',', attribute[12].Value, new Vector3());
  152. IconOffset2 = Auxiliary.StringToVector(',', attribute[13].Value, new Vector3());
  153. Sprites = SpriteParse(attribute[14].Value);
  154. SpriteAlpha = Auxiliary.StringToFloat(attribute[15].Value, 1);
  155. ExtraBodyParts = BodyPartParses(attribute[17].Value);
  156. ExtraArmatureNames = Auxiliary.StringToStrings(',', attribute[18].Value, new List<string>()).ToArray();
  157. CreateItem();
  158. }
  159. protected void CreateItem()
  160. {
  161. Transform = ResourceManager.Get(ResourceLabel.CloseItem, Folder.UI, false, ResourceManager.Get(CanvasLabel.Canvas), false);
  162. if (Type == CloseType.Top)
  163. {
  164. Transform.SetParent(ResourceManager.Get(CanvasLabel.Pb_TopGrid));
  165. }
  166. else if (Type == CloseType.Hair)
  167. {
  168. Transform.SetParent(ResourceManager.Get(CanvasLabel.Pa_HairGrid));
  169. }
  170. else if (Type == CloseType.Dress)
  171. {
  172. Transform.SetParent(ResourceManager.Get(CanvasLabel.Pc_DressGrid));
  173. }
  174. else if (Type == CloseType.Wing)
  175. {
  176. Transform.SetParent(ResourceManager.Get(CanvasLabel.Pe_WingGrid));
  177. }
  178. else if (Type == CloseType.Decarator)
  179. {
  180. Transform.SetParent(ResourceManager.Get(CanvasLabel.Pd_DecaratorGrid));
  181. }
  182. else if (Type == CloseType.Shoe)
  183. {
  184. Transform.SetParent(ResourceManager.Get(CanvasLabel.Pf_ShoeGrid));
  185. }
  186. else
  187. {
  188. throw new Exception();
  189. }
  190. Transform.SetSiblingIndex(Index);
  191. Auxiliary.CompileDic(Transform, ChildDic);
  192. Icon1 = ChildDic[CloseItemLabel.Icon1].GetComponent<Image>();
  193. Icon2 = ChildDic[CloseItemLabel.Icon2].GetComponent<Image>();
  194. Icon3 = ChildDic[CloseItemLabel.Icon3].GetComponent<Image>();
  195. DressBtn = ChildDic[CloseItemLabel.CloseItem].GetComponent<Button>();
  196. BuyBtn = ChildDic[CloseItemLabel.BuyBtn].GetComponent<Button>();
  197. BuyBtnLab = ChildDic[CloseItemLabel.BuyBtnLab].GetComponent<TextPlus>();
  198. SetupStandardItem(Icon1, Icon2, Icon3, BuyBtn, BuyBtnLab);
  199. //BuyBtnLab.GetComponent<TextPlus>().SetY = true;
  200. //float newSize = PixelSize / Sprites[0].rect.width;
  201. //SetupUI(newSize, new Vector2(), Icon1, Icon2, Icon3);
  202. //if (BuyCurrent != Current.Free)
  203. //{
  204. // BuyBtnLab.text = Auxiliary.ImageParse(BuyCurrent) + Auxiliary.ShrinkNumberStr(BuyCost);
  205. //}
  206. //if (BuyLevel > Manager.GardenLevel)
  207. //{
  208. // BuyBtn.interactable = false;
  209. // BuyBtn.image.material = Lib.GrayMat;
  210. //}
  211. BuyBtn.onClick.AddListener
  212. (
  213. () =>
  214. {
  215. AudioManager.PlayClip(AudioLabel.ClickButton);
  216. OpenBuyPanel(null, NavigateToChargeFromDressroom);
  217. //ResourceManager.Get(CanvasLabel.Pa_Info).TweenForCG();
  218. //float newSize = PixelSize / Sprites[0].rect.width;
  219. //SetupUI(newSize, new Vector2(0, 22), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon1), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon3), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon2));
  220. //ResourceManager.SetText(CanvasLabel.Pa_Lab, Name);
  221. //ResourceManager.SetText(CanvasLabel.Pa_BtnLab, Language.GetStr(LanguageLabel.UI__Pa_BtnLab) + Auxiliary.ImageParse(BuyCurrent) + BuyCost);
  222. //ResourceManager.SetButtonEvent
  223. //(
  224. // CanvasLabel.Pa_Btn,
  225. // () => OnBuy
  226. //);
  227. }
  228. );
  229. DressBtn.onClick.AddListener
  230. (
  231. () =>
  232. {
  233. AudioManager.PlayClip(AudioLabel.ClickButton);
  234. if (BuyLevel > Manager.GardenLevel)
  235. {
  236. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__P_Unlock));
  237. return;
  238. }
  239. ChangeDress(PlayerManager.Player);
  240. }
  241. );
  242. }
  243. protected Sprite[] SpriteParse(string str)
  244. {
  245. string[] spriteNames = str.Split(',');
  246. Sprite[] sprites = new Sprite[spriteNames.Length];
  247. for (int i = 0; i < spriteNames.Length; i++)
  248. {
  249. if (!PlayerManager.CloseSpriteDictionary.ContainsKey(spriteNames[i]))
  250. {
  251. Debug.Log(spriteNames[i]);
  252. }
  253. sprites[i] = PlayerManager.CloseSpriteDictionary[spriteNames[i]];
  254. }
  255. return sprites;
  256. }
  257. protected BodyPart BodyPartParse(string str)
  258. {
  259. int type = Auxiliary.StringToInt(str, -1);
  260. if (type == 1)
  261. {
  262. return BodyPart.Head;
  263. }
  264. else if (type == 2)
  265. {
  266. return BodyPart.Dress;
  267. }
  268. else if (type == 3)
  269. {
  270. return BodyPart.Shoe;
  271. }
  272. else if (type == 4)
  273. {
  274. return BodyPart.Headwear;
  275. }
  276. else if (type == 5)
  277. {
  278. return BodyPart.Top;
  279. }
  280. else if (type == 6)
  281. {
  282. return BodyPart.Wing;
  283. }
  284. else if (type == 7)
  285. {
  286. return BodyPart.LeftLongSleeve;
  287. }
  288. else if (type == 8)
  289. {
  290. return BodyPart.RightLongSleeve;
  291. }
  292. else if (type == 9)
  293. {
  294. return BodyPart.LeftShortSleeve;
  295. }
  296. else if (type == 10)
  297. {
  298. return BodyPart.RightShortSleeve;
  299. }
  300. else if (type == 11)
  301. {
  302. return BodyPart.Eye;
  303. }
  304. else if (type == 12)
  305. {
  306. return BodyPart.Mouse;
  307. }
  308. else
  309. {
  310. throw new Exception();
  311. }
  312. }
  313. protected BodyPart[] BodyPartParses(string str)
  314. {
  315. List<string> typeIDs = Auxiliary.StringToStrings(',', str, new List<string>());
  316. BodyPart[] bodyParts = new BodyPart[typeIDs.Count];
  317. for (int i = 0; i < typeIDs.Count; i++)
  318. {
  319. bodyParts[i] = BodyPartParse(typeIDs[i]);
  320. }
  321. return bodyParts;
  322. }
  323. protected CloseType TypeParse(string str)
  324. {
  325. int type = Auxiliary.StringToInt(str, -1);
  326. if (type == 1)
  327. {
  328. return CloseType.Hair;
  329. }
  330. else if (type == 2)
  331. {
  332. return CloseType.Top;
  333. }
  334. else if (type == 3)
  335. {
  336. return CloseType.Dress;
  337. }
  338. else if (type == 4)
  339. {
  340. return CloseType.Decarator;
  341. }
  342. else if (type == 5)
  343. {
  344. return CloseType.Wing;
  345. }
  346. else if (type == 6)
  347. {
  348. return CloseType.Shoe;
  349. }
  350. else
  351. {
  352. throw new Exception();
  353. }
  354. }
  355. public void SetupUI(float newSize, Vector2 offset, Image icon1, Image icon2, Image icon3)
  356. {
  357. icon1.SetActive(false);
  358. icon3.SetActive(false);
  359. icon2.SetActive(true);
  360. icon2.sprite = Sprites[0];
  361. icon2.Resize(true, new Vector2(newSize, newSize));
  362. icon2.SetAlpha(SpriteAlpha);
  363. icon2.transform.localPosition = offset + new Vector2(0, IconOffset);
  364. if (Sprites.Length >= 2)
  365. {
  366. icon1.SetActive(true);
  367. icon1.sprite = Sprites[1];
  368. icon1.Resize(true, new Vector2(newSize, newSize));
  369. icon1.SetAlpha(SpriteAlpha);
  370. icon1.transform.localPosition = IconOffset1 * newSize + offset + new Vector2(0, IconOffset);
  371. }
  372. if (Sprites.Length >= 3)
  373. {
  374. icon3.SetActive(true);
  375. icon3.sprite = Sprites[2];
  376. icon3.Resize(true, new Vector2(newSize, newSize));
  377. icon3.SetAlpha(SpriteAlpha);
  378. icon3.transform.localPosition = IconOffset2 * newSize + offset + new Vector2(0, IconOffset);
  379. }
  380. }
  381. public void SetupStandardItem(Image icon1, Image icon2, Image icon3, Button buyButton, TextPlus buyButtonText)
  382. {
  383. buyButtonText.GetComponent<TextPlus>().SetY = true;
  384. float newSize = PixelSize / Sprites[0].rect.width;
  385. SetupUI(newSize, new Vector2(), icon1, icon2, icon3);
  386. if (BuyCurrent != Current.Free)
  387. {
  388. buyButtonText.text = Auxiliary.ImageParse(BuyCurrent) + Auxiliary.ShrinkNumberStr(BuyCost);
  389. buyButton.interactable = true;
  390. }
  391. if (BuyLevel > Manager.GardenLevel)
  392. {
  393. buyButton.interactable = false;
  394. buyButton.image.material = Lib.GrayMat;
  395. }
  396. }
  397. public void OpenBuyPanel(Action buySucceedCallback, Action navigateAction)
  398. {
  399. ResourceManager.Get(CanvasLabel.Pa_Info).TweenForCG();
  400. float newSize = PixelSize / Sprites[0].rect.width;
  401. SetupUI(newSize, new Vector2(0, 22), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon1), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon3), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon2));
  402. ResourceManager.SetText(CanvasLabel.Pa_Lab, Name);
  403. ResourceManager.SetText(CanvasLabel.Pa_BtnLab, Language.GetStr(LanguageLabel.UI__Pa_BtnLab) + Auxiliary.ImageParse(BuyCurrent) + BuyCost);
  404. ResourceManager.SetButtonEvent
  405. (
  406. CanvasLabel.Pa_Btn,
  407. () => OnBuy(buySucceedCallback, navigateAction)
  408. );
  409. }
  410. public void Unlock()
  411. {
  412. if (Unavailable)
  413. {
  414. return;
  415. }
  416. IsBought = true;
  417. BuyBtn.interactable = false;
  418. BuyBtn.image.material = Lib.GrayMat;
  419. BuyBtnLab.text = Language.GetStr(LanguageLabel.UI__P_BtnLab2);
  420. Manager.CloseAmt++;
  421. }
  422. public void OnBuy(Action buySucceedCallback, Action navigateAction)
  423. {
  424. bool navigate = navigateAction != null;
  425. Manager.Pay
  426. (
  427. "",
  428. BuyCost,
  429. BuyCurrent,
  430. () =>
  431. {
  432. OnBuySucceed();
  433. ResourceManager.Get(CanvasLabel.Pa_Info).TweenBacCG();
  434. ChangeDress(PlayerManager.Player);
  435. SaveDressData();
  436. buySucceedCallback.SafeInvoke();
  437. },
  438. StaticsManager.ItemID.解锁服装,
  439. StaticsManager.ConsumeModule.Shop,
  440. navigate,
  441. false,
  442. () =>
  443. {
  444. PlayerManager.Player.ResetDressDatas();
  445. navigateAction.SafeInvoke();
  446. }
  447. );
  448. }
  449. public void OnBuySucceed()
  450. {
  451. Unlock();
  452. AudioManager.PlayClip(AudioLabel.GetCurrent);
  453. PlayerManager.BoughtCloseIDs.UniqueAdd(ID);
  454. HttpManager.UploadConfig();
  455. }
  456. public void NavigateToChargeFromDressroom()
  457. {
  458. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.Pa_Info).TweenBacCG();
  459. tweenRoot.AddEventOnetime
  460. (
  461. EventType.BackwardFinish,
  462. () =>
  463. {
  464. PlayerManager.Player.LeaveDressroom();
  465. }
  466. );
  467. ResourceManager.Get(CanvasLabel.B_SignIn0).GetTweenCG().AddEventOnetime
  468. (
  469. EventType.ForwardFinish,
  470. () =>
  471. {
  472. ResourceManager.Get(CanvasLabel.F_Manage0).TweenForVec();
  473. }
  474. );
  475. }
  476. public void ChangeDress(Player player, bool resetDepth = true)
  477. {
  478. player.ChangeClose(BodyPart, ArmatureName, resetDepth);
  479. if (Unavailable)
  480. {
  481. return;
  482. }
  483. if (ExtraBodyParts.Length > 0)
  484. {
  485. player.ChangeClose(BodyPart.LeftLongSleeve, "Empty", resetDepth);
  486. player.ChangeClose(BodyPart.LeftShortSleeve, "Empty", resetDepth);
  487. player.ChangeClose(BodyPart.RightLongSleeve, "Empty", resetDepth);
  488. player.ChangeClose(BodyPart.RightShortSleeve, "Empty", resetDepth);
  489. }
  490. for (int i = 0; i < ExtraArmatureNames.Length; i++)
  491. {
  492. player.ChangeClose(ExtraBodyParts[i], ExtraArmatureNames[i], resetDepth);
  493. }
  494. }
  495. public void SaveDressData() //仅在购买完成时调用
  496. {
  497. SaveDressData(BodyPart);
  498. if (BodyPart == BodyPart.Top)
  499. {
  500. PlayerManager.DressDatas[8] = "Empty";
  501. PlayerManager.DressDatas[9] = "Empty";
  502. PlayerManager.DressDatas[10] = "Empty";
  503. PlayerManager.DressDatas[11] = "Empty";
  504. foreach (var bodyPart in ExtraBodyParts)
  505. {
  506. SaveDressData(bodyPart);
  507. }
  508. }
  509. }
  510. public void SaveDressData(BodyPart bodyPart) //仅在购买完成时调用
  511. {
  512. if (bodyPart == BodyPart.LeftLongSleeve)
  513. {
  514. PlayerManager.DressDatas[8] = PlayerManager.Player.LeftLongSleeve;
  515. }
  516. else if (bodyPart == BodyPart.LeftShortSleeve)
  517. {
  518. PlayerManager.DressDatas[9] = PlayerManager.Player.LeftShortSleeve;
  519. }
  520. else if (bodyPart == BodyPart.RightLongSleeve)
  521. {
  522. PlayerManager.DressDatas[10] = PlayerManager.Player.RightLongSleeve;
  523. }
  524. else if (bodyPart == BodyPart.RightShortSleeve)
  525. {
  526. PlayerManager.DressDatas[11] = PlayerManager.Player.RightShortSleeve;
  527. }
  528. else if (bodyPart == BodyPart.Top)
  529. {
  530. PlayerManager.DressDatas[4] = PlayerManager.Player.Top;
  531. }
  532. else if (bodyPart == BodyPart.Shoe)
  533. {
  534. PlayerManager.DressDatas[2] = PlayerManager.Player.Shoe;
  535. }
  536. else if (bodyPart == BodyPart.Head)
  537. {
  538. PlayerManager.DressDatas[0] = PlayerManager.Player.Head;
  539. }
  540. else if (bodyPart == BodyPart.Wing)
  541. {
  542. PlayerManager.DressDatas[7] = PlayerManager.Player.Wing;
  543. }
  544. else if (bodyPart == BodyPart.Dress)
  545. {
  546. PlayerManager.DressDatas[1] = PlayerManager.Player.Dress;
  547. }
  548. else if (bodyPart == BodyPart.Headwear)
  549. {
  550. PlayerManager.DressDatas[3] = PlayerManager.Player.HeadWear;
  551. }
  552. else
  553. {
  554. throw new Exception();
  555. }
  556. }
  557. public void OnLevelChange()
  558. {
  559. if (Unavailable)
  560. {
  561. return;
  562. }
  563. if (IsBought)
  564. {
  565. return;
  566. }
  567. if (BuyLevel < Manager.GardenLevel)
  568. {
  569. BuyBtn.interactable = true;
  570. BuyBtn.image.material = null;
  571. }
  572. }
  573. public ExchangeInfo GetExchangeValue(float rate, StaticsManager.ConsumeModule consumeModule)
  574. {
  575. ExchangeInfo info = ExchangeInfo.GetExchangeInfo(BuyCurrent, BuyCost, rate);
  576. ExchangeInfo.GetExchangeValue(info, consumeModule);
  577. return info;
  578. }
  579. public static List<KV<Current, KV<int, double>>> GetTotalBuyCost(bool excludeBought, List<int> closeIDs)
  580. {
  581. int coinAmount = 0;
  582. int diamondAmount = 0;
  583. double totalCoin = 0;
  584. double totalDiamond = 0;
  585. foreach (var closeID in closeIDs)
  586. {
  587. if (PlayerManager.CloseItemDictionary[closeID].Sprites == null) continue;
  588. if (PlayerManager.CloseItemDictionary[closeID].ArmatureName == "Empty") continue;
  589. CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
  590. if (closeItem.IsBought && excludeBought) continue;
  591. if (closeItem.BuyCurrent == Current.Coin)
  592. {
  593. totalCoin += closeItem.BuyCost;
  594. coinAmount++;
  595. }
  596. if (closeItem.BuyCurrent == Current.Diamond)
  597. {
  598. totalDiamond += closeItem.BuyCost;
  599. diamondAmount++;
  600. }
  601. }
  602. List<KV<Current, KV<int, double>>> results = new List<KV<Current, KV<int, double>>>();
  603. results.Add(new KV<Current, KV<int, double>>(Current.Coin, new KV<int, double>(coinAmount, totalCoin)));
  604. results.Add(new KV<Current, KV<int, double>>(Current.Diamond, new KV<int, double>(diamondAmount, totalDiamond)));
  605. return results;
  606. }
  607. }
  608. public enum PlayerDirection
  609. {
  610. Left = 0,
  611. Right = 1,
  612. }
  613. public class Player : Regist , IPointerClickHandler
  614. {
  615. #region Config
  616. public static string IdleAnimationName = "newAnimation";
  617. public static string JumpAnimationName = "newAnimation1";
  618. public static string WalkAnimationName = "newAnimation2";
  619. public static string RunAnimationName = "newAnimation3";
  620. public static bool InDressRoom;
  621. public static float InDressRoomJumpFrequency;
  622. public float JumpTime;
  623. public float JumpTimer;
  624. public PlayerDirection PlayerDirection
  625. {
  626. get { return playerDirection; }
  627. set
  628. {
  629. playerDirection = value;
  630. Flip(playerDirection);
  631. }
  632. }
  633. public PlayerDirection playerDirection = PlayerDirection.Left;
  634. public bool IsDisplayInUGUI;
  635. public float UGUIScale;
  636. public bool PlayAnimFlag1;
  637. public bool PlayAnimFlag2;
  638. public string CurrentAnimationName;
  639. public MeshFilter ExpressionMeshFilter;
  640. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  641. private string ExpressionName;
  642. private Coroutine ResetExpressionCoroutine;
  643. public static Dictionary<string, Vector3> LeftExpressionPositionDictionary = new Dictionary<string, Vector3>
  644. {
  645. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  646. {"汗颜", new Vector3(0.35f, 0.91f, -0.00001f)},
  647. {"惊讶", new Vector3(0.09f, -0.07f, -0.00001f)},
  648. {"开心", new Vector3(0.1f, -0.22f, -0.00001f)},
  649. {"哭", new Vector3(0.07f, -0.64f, -0.00001f)},
  650. {"期待", new Vector3(0.04f, -0.20f, -0.00001f)},
  651. {"色咪咪", new Vector3(0.03f, -0.09f, -0.00001f)},
  652. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  653. };
  654. public static Dictionary<string, Vector3> RightExpressionPositionDictionary = new Dictionary<string, Vector3>
  655. {
  656. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  657. {"汗颜", new Vector3(-0.22f, 0.91f, -0.00001f)},
  658. {"惊讶", new Vector3(-0.09f, -0.07f, -0.00001f)},
  659. {"开心", new Vector3(-0.1f, -0.22f, -0.00001f)},
  660. {"哭", new Vector3(-0.07f, -0.64f, -0.00001f)},
  661. {"期待", new Vector3(-0.04f, -0.20f, -0.00001f)},
  662. {"色咪咪", new Vector3(-0.03f, -0.09f, -0.00001f)},
  663. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  664. };
  665. #region 换装
  666. public Transform Shadow;
  667. private Transform Pivot
  668. {
  669. get
  670. {
  671. if (pivot == null)
  672. {
  673. pivot = UAC.transform.FindChild(PlayerLabel.Pivot);
  674. }
  675. return pivot;
  676. }
  677. }
  678. private Transform pivot;
  679. public string Eye;
  680. public string Top;
  681. public string Shoe;
  682. public string Head;
  683. public string Wing;
  684. public string Dress;
  685. public string Mouse;
  686. public string HeadWear;
  687. public string LeftLongSleeve;
  688. public string LeftShortSleeve;
  689. public string RightLongSleeve;
  690. public string RightShortSleeve;
  691. private string TempClose;
  692. public DragonBones.Slot NeckSlot;
  693. public DragonBones.Slot LeftHandSlot;
  694. public DragonBones.Slot RightHandSlot;
  695. public DragonBones.Slot LeftLegSlot;
  696. public DragonBones.Slot RightLegSlot;
  697. public DragonBones.Slot LeftShortSleeveSlot;
  698. public DragonBones.Slot RightShortSleeveSlot;
  699. public DragonBones.Slot EyeSlot;
  700. public DragonBones.Slot TopSlot;
  701. public DragonBones.Slot HeadSlot;
  702. public DragonBones.Slot DressSlot;
  703. public DragonBones.Slot WingSlot;
  704. public DragonBones.Slot MouseSlot;
  705. public DragonBones.Slot LeftShoeSlot;
  706. public DragonBones.Slot RightShoeSlot;
  707. public DragonBones.Slot HeadWearSlot;
  708. public UnityArmatureComponent UAC;
  709. //public UnityArmatureComponent LeftShortSleeveUAC;
  710. //public UnityArmatureComponent RightShortSleeveUAC;
  711. public UnityArmatureComponent LeftLongSleeveUAC;
  712. public UnityArmatureComponent RightLongSleeveUAC;
  713. #endregion
  714. #endregion
  715. public override bool InitAtOnce()
  716. {
  717. if (base.InitAtOnce())
  718. {
  719. return true;
  720. }
  721. enabled = true;
  722. Auxiliary.CompileDic(transform, ChildDic);
  723. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  724. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  725. Shadow = ChildDic[PlayerLabel.Shadow];
  726. Shadow.CreateStreamScale
  727. (
  728. new List<float>() {0, 0, 0},
  729. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  730. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  731. true,
  732. true,
  733. Curve.EaseOutQuad
  734. );
  735. MeshFilter meshFilter = Shadow.GetComponent<MeshFilter>();
  736. meshFilter.mesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(ResourceLabel.FlowerShadow, Folder.Scene));
  737. meshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), meshFilter.mesh.vertices.Length).ToList());
  738. Shadow.GetComponent<MeshRenderer>().sharedMaterial = UnityFactory.Materials[0];
  739. ExpressionMeshFilter = ChildDic[PlayerLabel.ExpressionMeshFilter].GetComponent<MeshFilter>();
  740. ExpressionMeshFilter.GetComponent<MeshRenderer>().sharedMaterial = UnityFactory.Materials[0];
  741. return false;
  742. }
  743. public void Update()
  744. {
  745. if (InDressRoom)
  746. {
  747. JumpTimer += Time.deltaTime;
  748. if (JumpTimer > JumpTime)
  749. {
  750. if (!PlayAnimFlag1 && !PlayAnimFlag2)
  751. {
  752. PlayAnim(JumpAnimationName);
  753. }
  754. PlayAnimFlag2 = true;
  755. }
  756. if (JumpTimer > InDressRoomJumpFrequency)
  757. {
  758. PlayAnimFlag2 = false;
  759. JumpTime = Mathf.Lerp(0, InDressRoomJumpFrequency, Random.Range(0f, 1f));
  760. JumpTimer = 0;
  761. }
  762. }
  763. //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  764. //{
  765. // MoveThread();
  766. //}
  767. }
  768. public void OnAnimStart(string str, EventObject eventObject)
  769. {
  770. if (eventObject.animationState.name == JumpAnimationName)
  771. {
  772. Shadow.StreamReForScale();
  773. PlayAnimFlag1 = true;
  774. TempClose = Eye;
  775. ChangeClose(BodyPart.Eye, "眼睛表情1");
  776. }
  777. else if (eventObject.animationState.name == IdleAnimationName)
  778. {
  779. PlayAnimFlag1 = false;
  780. if (TempClose != null)
  781. {
  782. ChangeClose(BodyPart.Eye, TempClose);
  783. }
  784. }
  785. }
  786. public void PlayAnim(string animName)
  787. {
  788. if (PlayAnimFlag1)
  789. {
  790. return;
  791. }
  792. if (UAC.anim.lastAnimationName == animName)
  793. {
  794. return;
  795. }
  796. if (SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
  797. {
  798. CurrentAnimationName = animName;
  799. }
  800. UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
  801. }
  802. public float GetFadeInTime(string lastAnimation, string targetAnimation)
  803. {
  804. if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
  805. return -1f;
  806. else
  807. return 0.1f;
  808. //throw new Exception();
  809. }
  810. public void SetAllCollider(bool enable)
  811. {
  812. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  813. for (int i = 0; i < colliders.Length; i++)
  814. {
  815. colliders[i].enabled = enable;
  816. }
  817. }
  818. public void OnPointerClick(PointerEventData eventData)
  819. {
  820. AudioManager.PlayClip(AudioLabel.GetCurrent);
  821. PlayAnim(JumpAnimationName);
  822. }
  823. public void ResetExpression()
  824. {
  825. ExpressionMeshFilter.SetActive(false);
  826. EyeSlot.UnityTransform.GetChild(0).SetActive(true);
  827. MouseSlot.UnityTransform.GetChild(0).SetActive(true);
  828. }
  829. public void ChangeExpression(string expressionName, float duration)
  830. {
  831. ExpressionName = expressionName;
  832. ExpressionMeshFilter.sharedMesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(expressionName, Folder.Scene));
  833. ExpressionMeshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), ExpressionMeshFilter.mesh.vertices.Length).ToList());
  834. ExpressionMeshFilter.transform.parent = EyeSlot.UnityTransform;
  835. ExpressionMeshFilter.SetActive(true);
  836. EyeSlot.UnityTransform.GetChild(0).SetActive(false);
  837. MouseSlot.UnityTransform.GetChild(0).SetActive(false);
  838. FlipExpression(expressionName, PlayerDirection);
  839. if (ResetExpressionCoroutine != null)
  840. Auxiliary.Instance.StopCoroutine(ResetExpressionCoroutine);
  841. ResetExpressionCoroutine = Auxiliary.Instance.DelayCall
  842. (
  843. () =>
  844. {
  845. ResetExpression();
  846. },
  847. duration
  848. );
  849. }
  850. public void Flip(PlayerDirection direction)
  851. {
  852. FlipExpression(ExpressionName, direction);
  853. if (direction == PlayerDirection.Left)
  854. {
  855. UAC.armature.flipX = false;
  856. playerDirection = PlayerDirection.Left;
  857. }
  858. else if (direction == PlayerDirection.Right)
  859. {
  860. UAC.armature.flipX = true;
  861. playerDirection = PlayerDirection.Right;
  862. }
  863. else
  864. {
  865. throw new Exception();
  866. }
  867. DelayCall.Call(1, () => Shadow.SetX(Pivot.position.x));
  868. }
  869. public void FlipExpression(string expressionName, PlayerDirection direction)
  870. {
  871. if (string.IsNullOrEmpty(ExpressionName))
  872. {
  873. return;
  874. }
  875. if (direction == PlayerDirection.Left)
  876. {
  877. ExpressionMeshFilter.transform.eulerAngles = new Vector3();
  878. ExpressionMeshFilter.transform.localPosition = LeftExpressionPositionDictionary[ExpressionName];
  879. }
  880. else if (direction == PlayerDirection.Right)
  881. {
  882. UAC.armature.flipX = true;
  883. ExpressionMeshFilter.transform.eulerAngles = new Vector3(0, 180, 0);
  884. ExpressionMeshFilter.transform.localPosition = RightExpressionPositionDictionary[ExpressionName];
  885. playerDirection = PlayerDirection.Right;
  886. }
  887. else
  888. {
  889. throw new Exception();
  890. }
  891. }
  892. public void SaveDressDatas(bool showNavigate)
  893. {
  894. AudioManager.PlayClip(AudioLabel.ClickButton);
  895. List<CloseItem> closeUnitList = new List<CloseItem>();
  896. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Head]]);
  897. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Dress]]);
  898. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Shoe]]);
  899. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[HeadWear]]);
  900. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Top]]);
  901. if (Wing != "Empty")
  902. {
  903. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Wing]]);
  904. }
  905. for (int i = 0; i < closeUnitList.Count; i++)
  906. {
  907. if (!closeUnitList[i].IsBought)
  908. {
  909. if (showNavigate)
  910. {
  911. BuyDressNavigate(closeUnitList);
  912. }
  913. return;
  914. }
  915. }
  916. PlayerManager.DressDatas[0] = Head;
  917. PlayerManager.DressDatas[1] = Dress;
  918. PlayerManager.DressDatas[2] = Shoe;
  919. PlayerManager.DressDatas[3] = HeadWear;
  920. PlayerManager.DressDatas[4] = Top;
  921. PlayerManager.DressDatas[7] = Wing;
  922. PlayerManager.DressDatas[8] = LeftLongSleeve;
  923. PlayerManager.DressDatas[9] = LeftShortSleeve;
  924. PlayerManager.DressDatas[10] = RightLongSleeve;
  925. PlayerManager.DressDatas[11] = RightShortSleeve;
  926. Toast.Show(1.5f, Language.GetStr(LanguageLabel.UI__P_SaveSucceed));
  927. }
  928. public void ResetDressDatas()
  929. {
  930. AudioManager.PlayClip(AudioLabel.ClickButton);
  931. List<string> dressData = new List<string>(PlayerManager.DressDatas);
  932. dressData[5] = Eye;
  933. PlayerManager.BuildPlayer(dressData);
  934. }
  935. public List<int> GetCurrentChangableDressIDs()
  936. {
  937. List<int> ids = new List<int>();
  938. ids.Add(PlayerManager.CloseIDDictionary[Head]);
  939. ids.Add(PlayerManager.CloseIDDictionary[Dress]);
  940. ids.Add(PlayerManager.CloseIDDictionary[Shoe]);
  941. ids.Add(PlayerManager.CloseIDDictionary[HeadWear]);
  942. ids.Add(PlayerManager.CloseIDDictionary[Top]);
  943. ids.Add(PlayerManager.CloseIDDictionary[Wing]);
  944. ids.Add(PlayAnimFlag1 ? PlayerManager.CloseIDDictionary[TempClose] : PlayerManager.CloseIDDictionary[Eye]);
  945. ids.Add(PlayerManager.CloseIDDictionary[Mouse]);
  946. ids.Add(PlayerManager.CloseIDDictionary[Wing]);
  947. return ids;
  948. }
  949. public static List<string> DressIDToDressName(List<int> ids)
  950. {
  951. List<string> names = new List<string>();
  952. foreach (var id in ids)
  953. {
  954. names.Add(PlayerManager.CloseItemDictionary[id].ArmatureName);
  955. }
  956. return names;
  957. }
  958. public List<string> GetCurrentDressNames()
  959. {
  960. List<string> names = new List<string>();
  961. return names;
  962. }
  963. public List<string> GetCurrentChangableDressNames()
  964. {
  965. List<string> names = new List<string>();
  966. names.Add(Head);
  967. names.Add(Dress);
  968. names.Add(Shoe);
  969. names.Add(HeadWear);
  970. names.Add(Top);
  971. names.Add(Wing);
  972. if (PlayAnimFlag1) names.Add(TempClose);
  973. else names.Add(Eye);
  974. names.Add(Mouse);
  975. names.Add(Wing);
  976. return names;
  977. }
  978. public void BuyDressNavigate(List<CloseItem> closeUnitList)
  979. {
  980. for (int i = 0; i < closeUnitList.Count; i++)
  981. {
  982. if (closeUnitList[i].IsBought)
  983. {
  984. closeUnitList.RemoveAt(i--);
  985. }
  986. else
  987. {
  988. closeUnitList[i].BuyBtn.onClick.Invoke();
  989. closeUnitList.RemoveAt(i--);
  990. ResourceManager.Get(CanvasLabel.Pa_Info).GetTweenCG().AddEventOnetime
  991. (
  992. EventType.BackwardFinish,
  993. () =>
  994. {
  995. if (closeUnitList.Count == 0)
  996. {
  997. SaveDressDatas(false);
  998. }
  999. else
  1000. {
  1001. BuyDressNavigate(closeUnitList);
  1002. }
  1003. }
  1004. );
  1005. return;
  1006. }
  1007. }
  1008. }
  1009. public void LeaveDressroom()
  1010. {
  1011. bool allSave = true;
  1012. bool allBought = true;
  1013. List<string> currentDerssData = new List<string>() { Head, Dress, Shoe, HeadWear, Top, Wing };
  1014. if (currentDerssData[0] != PlayerManager.DressDatas[0]) allSave = false;
  1015. if (currentDerssData[1] != PlayerManager.DressDatas[1]) allSave = false;
  1016. if (currentDerssData[2] != PlayerManager.DressDatas[2]) allSave = false;
  1017. if (currentDerssData[3] != PlayerManager.DressDatas[3]) allSave = false;
  1018. if (currentDerssData[4] != PlayerManager.DressDatas[4]) allSave = false;
  1019. if (currentDerssData[5] != PlayerManager.DressDatas[7]) allSave = false;
  1020. for (int i = 0; i < currentDerssData.Count; i++)
  1021. {
  1022. if (!PlayerManager.CloseIDDictionary.ContainsKey(currentDerssData[i]))
  1023. {
  1024. continue;
  1025. }
  1026. int id = PlayerManager.CloseIDDictionary[currentDerssData[i]];
  1027. allBought = allBought && PlayerManager.CloseItemDictionary[id].IsBought;
  1028. //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
  1029. //allSave = allSave && currentDerssData[i] == PlayerManager.DressDatas[i];
  1030. //Debug.Log(currentDerssData[i] + " " + PlayerManager.DressDatas[i]);
  1031. }
  1032. //Debug.Log(allBought);
  1033. //Debug.Log(allSave);
  1034. if (allBought)
  1035. {
  1036. if (allSave)
  1037. {
  1038. ExitDressRoom();
  1039. }
  1040. else
  1041. {
  1042. ResetDressDatas();
  1043. ExitDressRoom();
  1044. }
  1045. }
  1046. else
  1047. {
  1048. Bubble.Show
  1049. (
  1050. null, Language.GetStr(LanguageLabel.UI__P_Return), null, null,
  1051. () =>
  1052. {
  1053. ResetDressDatas();
  1054. ResourceManager.Get(CanvasLabel.K_Bubble).GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  1055. }
  1056. );
  1057. }
  1058. }
  1059. public void ExitDressRoom()
  1060. {
  1061. Manager.SceneSwitchFlag = false;
  1062. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1063. tweenRoot.AddEventOnetime
  1064. (
  1065. EventType.BackwardFinish,
  1066. () =>
  1067. {
  1068. transform.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
  1069. transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  1070. transform.localScale = ResourceManager.Get(GardenLabel.GardenPlayerPos).lossyScale;
  1071. ResourceManager.Get(ResourceLabel.Garden).TweenForSr();
  1072. ResourceManager.Get(DressroomLabel.DressRoom).TweenBacSr();
  1073. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  1074. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenBacCG();
  1075. }
  1076. );
  1077. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1078. tweenRoot.AddEventOnetime
  1079. (
  1080. EventType.BackwardFinish,
  1081. () =>
  1082. {
  1083. SetAllCollider(true);
  1084. InDressRoom = false;
  1085. JumpTimer = 0;
  1086. PlayAnim(IdleAnimationName);
  1087. DeactiveShadow();
  1088. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenForCG();
  1089. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1090. }
  1091. );
  1092. }
  1093. public void EnterDressRoom()
  1094. {
  1095. if (Manager.SceneSwitchFlag)
  1096. {
  1097. return;
  1098. }
  1099. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenBacCG();
  1100. InDressRoom = true;
  1101. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  1102. Manager.SceneSwitchFlag = true;
  1103. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  1104. SetAllCollider(false);
  1105. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1106. tweenRoot.AddEventOnetime
  1107. (
  1108. EventType.BackwardFinish,
  1109. () =>
  1110. {
  1111. GardenManager.RetrieveAllElf();
  1112. IAPManager.RetrieveADChest();
  1113. ActiveShadow();
  1114. transform.SetParent(ResourceManager.Get(DressroomLabel.DressRoom));
  1115. transform.position = ResourceManager.Get(DressroomLabel.DressRoomPos).position;
  1116. transform.localScale = ResourceManager.Get(DressroomLabel.DressRoomPos).lossyScale;
  1117. ResourceManager.Get(ResourceLabel.Garden).TweenBacSr();
  1118. ResourceManager.Get(DressroomLabel.DressRoom).TweenForSr();
  1119. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenForCG();
  1120. }
  1121. );
  1122. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1123. tweenRoot.AddEventOnetime
  1124. (
  1125. EventType.ForwardFinish,
  1126. () =>
  1127. {
  1128. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1129. }
  1130. );
  1131. }
  1132. public void ActiveShadow()
  1133. {
  1134. ChildDic[PlayerLabel.ShadowParent].SetActive(true);
  1135. ChildDic[PlayerLabel.ShadowParent].SetLZ(3);
  1136. }
  1137. public void DeactiveShadow()
  1138. {
  1139. Shadow.GetStreamScale().Pause();
  1140. Shadow.GetStreamScale().InOrigin = true;
  1141. ChildDic[PlayerLabel.ShadowParent].SetActive(false);
  1142. }
  1143. public void DisplayInUI(float scale)
  1144. {
  1145. UGUIScale = scale;
  1146. scale *= ResourceManager.Get<Canvas>(CanvasLabel.Canvas).scaleFactor;
  1147. MeshFilter[] meshFilters = UAC.GetComponentsInChildren<MeshFilter>(true);
  1148. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1149. for (int i = 0; i < meshRenderers.Length; i++)
  1150. {
  1151. MeshFilter meshFilter = meshFilters[i];
  1152. MeshRenderer meshRenderer = meshRenderers[i];
  1153. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1154. if (unityUGUIDisplay == null) unityUGUIDisplay = meshRenderer.AddComponent<UnityUGUIDisplay>();
  1155. unityUGUIDisplay.Enable(meshFilter, meshRenderer);
  1156. unityUGUIDisplay.raycastTarget = false;
  1157. meshRenderer.enabled = false;
  1158. UAC.transform.localScale = new Vector3(scale, scale, 1);
  1159. SetAllCollider(false);
  1160. DeactiveShadow();
  1161. }
  1162. IsDisplayInUGUI = true;
  1163. ResetDepth();
  1164. }
  1165. public void DisplayInScene()
  1166. {
  1167. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1168. foreach (var meshRenderer in meshRenderers)
  1169. {
  1170. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1171. if (unityUGUIDisplay == null) continue;
  1172. unityUGUIDisplay.Disable();
  1173. meshRenderer.enabled = true;
  1174. UAC.transform.localScale = Vector3.one;
  1175. SetAllCollider(true);
  1176. ActiveShadow();
  1177. }
  1178. IsDisplayInUGUI = false;
  1179. ResetDepth();
  1180. }
  1181. #region 换装
  1182. public void CorrectPivot()
  1183. {
  1184. List<Transform> children = new List<Transform>();
  1185. while (transform.childCount > 0)
  1186. {
  1187. children.Add(transform.GetChild(0));
  1188. children.Back(0).parent = null;
  1189. }
  1190. Vector3 offset = Pivot.position - transform.position;
  1191. children[0].position += offset;
  1192. children[1].position += offset;
  1193. transform.position += offset;
  1194. foreach (var collider in GetComponents<BoxCollider2D>())
  1195. {
  1196. collider.offset -= new Vector2(offset.x, offset.y);
  1197. }
  1198. for (int i = 0; i < children.Count; i++)
  1199. {
  1200. children[i].parent = transform;
  1201. }
  1202. }
  1203. public UnityArmatureComponent Build()
  1204. {
  1205. if (!PlayerManager.Inited)
  1206. {
  1207. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  1208. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex, Folder.Config), ResourceLabel.StandTexture);
  1209. PlayerManager.Inited = true;
  1210. }
  1211. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  1212. UAC.transform.parent = transform;
  1213. UAC.transform.localScale = new Vector3(1, 1, 1);
  1214. UAC.transform.localPosition = new Vector3();
  1215. UAC.anim.Play(IdleAnimationName);
  1216. UAC.AddEventListener(EventObject.START, OnAnimStart);
  1217. Eye = "眼睛1";
  1218. Top = "上衣1";
  1219. Shoe = "鞋子1";
  1220. Head = "脑壳1";
  1221. Wing = "Empty";
  1222. Dress = "裙子1";
  1223. Mouse = "嘴巴1";
  1224. HeadWear = "头饰品1";
  1225. NeckSlot = UAC.armature.GetSlot("脖子");
  1226. LeftHandSlot = UAC.armature.GetSlot("左手");
  1227. RightHandSlot = UAC.armature.GetSlot("右手");
  1228. LeftLegSlot = UAC.armature.GetSlot("左腿");
  1229. RightLegSlot = UAC.armature.GetSlot("右腿");
  1230. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  1231. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  1232. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  1233. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  1234. EyeSlot = UAC.armature.GetSlot("眼睛");
  1235. TopSlot = UAC.armature.GetSlot("上衣");
  1236. HeadSlot = UAC.armature.GetSlot("脑壳");
  1237. WingSlot = UAC.armature.GetSlot("翅膀");
  1238. DressSlot = UAC.armature.GetSlot("裙子");
  1239. MouseSlot = UAC.armature.GetSlot("嘴巴");
  1240. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  1241. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  1242. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  1243. ChangeClose(BodyPart.Eye, "眼睛1", false);
  1244. ChangeClose(BodyPart.Top, "上衣1", false);
  1245. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  1246. ChangeClose(BodyPart.Head, "脑壳1", false);
  1247. ChangeClose(BodyPart.Dress, "裙子1", false);
  1248. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  1249. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  1250. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  1251. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  1252. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  1253. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  1254. CorrectPivot();
  1255. return UAC;
  1256. }
  1257. public UnityArmatureComponent BuildPink()
  1258. {
  1259. Build();
  1260. ChangeClose(BodyPart.Eye, "眼睛3", false);
  1261. ChangeClose(BodyPart.Top, "上衣3", false);
  1262. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  1263. ChangeClose(BodyPart.Head, "脑壳3", false);
  1264. ChangeClose(BodyPart.Wing, "Empty", false);
  1265. ChangeClose(BodyPart.Dress, "裙子3", false);
  1266. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  1267. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  1268. ResetDepth();
  1269. return UAC;
  1270. }
  1271. public UnityArmatureComponent BuildBlond()
  1272. {
  1273. Build();
  1274. ChangeClose(BodyPart.Wing, "Empty", false);
  1275. ResetDepth();
  1276. return UAC;
  1277. }
  1278. public UnityArmatureComponent BuildBrown()
  1279. {
  1280. Build();
  1281. ChangeClose(BodyPart.Eye, "眼睛2", false);
  1282. ChangeClose(BodyPart.Top, "上衣2", false);
  1283. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  1284. ChangeClose(BodyPart.Head, "脑壳2", false);
  1285. ChangeClose(BodyPart.Wing, "Empty", false);
  1286. ChangeClose(BodyPart.Dress, "裙子2", false);
  1287. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  1288. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  1289. ResetDepth();
  1290. return UAC;
  1291. }
  1292. public void ResetDepth()
  1293. {
  1294. if (IsDisplayInUGUI)
  1295. {
  1296. SetSlotAsFirstChild(TopSlot);
  1297. SetSlotAsFirstChild(DressSlot);
  1298. SetSlotAsFirstChild(LeftShortSleeveSlot);
  1299. SetSlotAsFirstChild(RightShortSleeveSlot);
  1300. LeftLongSleeveUAC.transform.SetAsFirstSibling();
  1301. RightLongSleeveUAC.transform.SetAsFirstSibling();
  1302. SetSlotAsFirstChild(EyeSlot);
  1303. SetSlotAsFirstChild(MouseSlot);
  1304. SetSlotAsFirstChild(LeftShoeSlot);
  1305. SetSlotAsFirstChild(RightShoeSlot);
  1306. SetSlotAsFirstChild(HeadWearSlot);
  1307. SetSlotAsFirstChild(LeftHandSlot);
  1308. SetSlotAsFirstChild(RightHandSlot);
  1309. SetSlotAsFirstChild(HeadSlot);
  1310. SetSlotAsFirstChild(LeftLegSlot);
  1311. SetSlotAsFirstChild(RightLegSlot);
  1312. SetSlotAsFirstChild(NeckSlot);
  1313. SetSlotAsFirstChild(WingSlot);
  1314. }
  1315. else
  1316. {
  1317. UAC.transform.SetLZ(2.5f);
  1318. SetSlotLocalZ(WingSlot, 0.00003f);
  1319. SetSlotLocalZ(EyeSlot, -0.00001f);
  1320. SetSlotLocalZ(TopSlot, -0.00003f);
  1321. SetSlotLocalZ(MouseSlot, -0.00001f);
  1322. SetSlotLocalZ(HeadWearSlot, -0.00001f);
  1323. SetSlotLocalZ(LeftShoeSlot, -0.00001f);
  1324. SetSlotLocalZ(RightShoeSlot, -0.00001f);
  1325. SetSlotLocalZ(LeftLegSlot, 0);
  1326. SetSlotLocalZ(RightLegSlot, 0);
  1327. SetSlotLocalZ(NeckSlot, 0.00001f);
  1328. SetSlotLocalZ(LeftHandSlot, -0.00001f);
  1329. SetSlotLocalZ(RightHandSlot, -0.00001f);
  1330. SetSlotLocalZ(LeftShortSleeveSlot, -0.000015f);
  1331. SetSlotLocalZ(RightShortSleeveSlot, -0.000015f);
  1332. SetSlotLocalZ(HeadSlot, 0);
  1333. if (HeadSlot.UnityTransform != null && HeadSlot.UnityTransform.childCount > 1)
  1334. {
  1335. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1336. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1337. }
  1338. SetSlotLocalZ(DressSlot, -0.00002f);
  1339. if (DressSlot.UnityTransform != null && DressSlot.UnityTransform.childCount > 1)
  1340. {
  1341. DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1342. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1343. }
  1344. LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1345. RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1346. //UAC.transform.SetLZ(2.5f);
  1347. //WingSlot.UnityTransform.SetLZ(0);
  1348. //EyeSlot.UnityTransform.SetLZ(0);
  1349. //TopSlot.UnityTransform.SetLZ(0);
  1350. //MouseSlot.UnityTransform.SetLZ(0);
  1351. //HeadWearSlot.UnityTransform.SetLZ(0);
  1352. //LeftShoeSlot.UnityTransform.SetLZ(0);
  1353. //RightShoeSlot.UnityTransform.SetLZ(0);
  1354. //LeftLegSlot.UnityTransform.SetLZ(0);
  1355. //RightLegSlot.UnityTransform.SetLZ(0);
  1356. //NeckSlot.UnityTransform.SetLZ(0);
  1357. //LeftHandSlot.UnityTransform.SetLZ(0);
  1358. //RightHandSlot.UnityTransform.SetLZ(0);
  1359. //LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  1360. //RightShortSleeveSlot.UnityTransform.SetLZ(0);
  1361. //WingSlot.SetLZ(0.00003f);
  1362. //EyeSlot.SetLZ(-0.00001f);
  1363. //TopSlot.SetLZ(-0.00003f);
  1364. //MouseSlot.SetLZ(-0.00001f);
  1365. //HeadWearSlot.SetLZ(-0.00001f);
  1366. //HeadSlot.UnityTransform.SetLZ(0);
  1367. //if (HeadSlot.UnityTransform.childCount > 1)
  1368. //{
  1369. // HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1370. // HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1371. //}
  1372. //DressSlot.UnityTransform.SetLZ(-0.00002f);
  1373. //if (DressSlot.UnityTransform.childCount > 1)
  1374. //{
  1375. // DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1376. // DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1377. //}
  1378. //LeftShoeSlot.SetLZ(-0.00001f);
  1379. //RightShoeSlot.SetLZ(-0.00001f);
  1380. //LeftLegSlot.SetLZ(0);
  1381. //RightLegSlot.SetLZ(0);
  1382. //NeckSlot.SetLZ(0.00001f);
  1383. //LeftHandSlot.SetLZ(-0.00001f);
  1384. //RightHandSlot.SetLZ(-0.00001f);
  1385. //LeftShortSleeveSlot.SetLZ(-0.000015f);
  1386. //RightShortSleeveSlot.SetLZ(-0.000015f);
  1387. //LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1388. //RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1389. }
  1390. }
  1391. private void SetSlotLocalZ(DragonBones.Slot slot, float z)
  1392. {
  1393. if (slot.UnityTransform == null)
  1394. {
  1395. UAC.transform.FindChild(slot.name).SetLZ(z);
  1396. }
  1397. else
  1398. {
  1399. slot.UnityTransform.SetLZ(z);
  1400. }
  1401. }
  1402. private void SetSlotAsFirstChild(DragonBones.Slot slot)
  1403. {
  1404. if (slot.UnityTransform == null)
  1405. {
  1406. UAC.transform.FindChild(slot.name).SetAsFirstSibling();
  1407. }
  1408. else
  1409. {
  1410. slot.UnityTransform.SetAsFirstSibling();
  1411. }
  1412. }
  1413. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  1414. {
  1415. // Debug.Log (bodyPart + " " + armatureName);
  1416. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  1417. if (bodyPart == BodyPart.Eye)
  1418. {
  1419. Eye = armatureName;
  1420. slotList.Add(EyeSlot);
  1421. }
  1422. else if (bodyPart == BodyPart.Top)
  1423. {
  1424. Top = armatureName;
  1425. slotList.Add(TopSlot);
  1426. }
  1427. else if (bodyPart == BodyPart.Shoe)
  1428. {
  1429. Shoe = armatureName;
  1430. slotList.Add(LeftShoeSlot);
  1431. slotList.Add(RightShoeSlot);
  1432. }
  1433. else if (bodyPart == BodyPart.Head)
  1434. {
  1435. Head = armatureName;
  1436. slotList.Add(HeadSlot);
  1437. }
  1438. else if (bodyPart == BodyPart.Wing)
  1439. {
  1440. if (Wing == armatureName)
  1441. {
  1442. return;
  1443. }
  1444. else
  1445. {
  1446. Wing = armatureName;
  1447. slotList.Add(WingSlot);
  1448. }
  1449. }
  1450. else if (bodyPart == BodyPart.Dress)
  1451. {
  1452. Dress = armatureName;
  1453. slotList.Add(DressSlot);
  1454. }
  1455. else if (bodyPart == BodyPart.Mouse)
  1456. {
  1457. Mouse = armatureName;
  1458. slotList.Add(MouseSlot);
  1459. }
  1460. else if (bodyPart == BodyPart.Headwear)
  1461. {
  1462. HeadWear = armatureName;
  1463. slotList.Add(HeadWearSlot);
  1464. }
  1465. else if (bodyPart == BodyPart.Leg)
  1466. {
  1467. slotList.Add(LeftLegSlot);
  1468. slotList.Add(RightLegSlot);
  1469. }
  1470. else if (bodyPart == BodyPart.LeftHand)
  1471. {
  1472. slotList.Add(LeftHandSlot);
  1473. }
  1474. else if (bodyPart == BodyPart.RightHand)
  1475. {
  1476. slotList.Add(RightHandSlot);
  1477. }
  1478. else if (bodyPart == BodyPart.Neck)
  1479. {
  1480. slotList.Add(NeckSlot);
  1481. }
  1482. else if (bodyPart == BodyPart.LeftLongSleeve)
  1483. {
  1484. LeftLongSleeve = armatureName;
  1485. ChangeClose(LeftLongSleeveUAC, armatureName);
  1486. return;
  1487. }
  1488. else if (bodyPart == BodyPart.LeftShortSleeve)
  1489. {
  1490. LeftShortSleeve = armatureName;
  1491. slotList.Add(LeftShortSleeveSlot);
  1492. }
  1493. else if (bodyPart == BodyPart.RightLongSleeve)
  1494. {
  1495. RightLongSleeve = armatureName;
  1496. ChangeClose(RightLongSleeveUAC, armatureName);
  1497. return;
  1498. }
  1499. else if (bodyPart == BodyPart.RightShortSleeve)
  1500. {
  1501. RightShortSleeve = armatureName;
  1502. slotList.Add(RightShortSleeveSlot);
  1503. }
  1504. else
  1505. {
  1506. throw new Exception();
  1507. }
  1508. ChangeClose(slotList, armatureName, setDepth);
  1509. if (bodyPart == BodyPart.Wing)
  1510. {
  1511. TweenRoot tweenRoot = transform.FindChild("Armature/" + Wing).GetChild(0).CreateTweenScale(new Vector3(1, 1, 1), new Vector3(0.6f, 1, 1), 0.75f, true, true, Curve.Linear);
  1512. tweenRoot.PingPong = true;
  1513. tweenRoot.StartForward();
  1514. }
  1515. }
  1516. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1517. {
  1518. for (int i = 0; i < slotList.Count; i++)
  1519. {
  1520. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1521. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1522. }
  1523. if (setDepth)
  1524. {
  1525. DelayCall.Call
  1526. (
  1527. 1,
  1528. () =>
  1529. {
  1530. ResetDepth();
  1531. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1532. }
  1533. );
  1534. }
  1535. }
  1536. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1537. {
  1538. if (armatureName == "Empty")
  1539. {
  1540. uac.SetActive(false);
  1541. }
  1542. else
  1543. {
  1544. uac.SetActive(true);
  1545. }
  1546. if (setDepth)
  1547. {
  1548. DelayCall.Call
  1549. (
  1550. 1,
  1551. () =>
  1552. {
  1553. ResetDepth();
  1554. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1555. }
  1556. );
  1557. }
  1558. }
  1559. #endregion
  1560. }