Player.cs 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  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. for (int i = 0; i < currentDerssData.Count; i++)
  1015. {
  1016. if (!PlayerManager.CloseIDDictionary.ContainsKey(currentDerssData[i]))
  1017. {
  1018. continue;
  1019. }
  1020. int id = PlayerManager.CloseIDDictionary[currentDerssData[i]];
  1021. allBought = allBought && PlayerManager.CloseItemDictionary[id].IsBought;
  1022. //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
  1023. allSave = allSave && currentDerssData[i] == PlayerManager.DressDatas[i];
  1024. }
  1025. if (allBought)
  1026. {
  1027. if (allSave)
  1028. {
  1029. ExitDressRoom();
  1030. }
  1031. else
  1032. {
  1033. ResetDressDatas();
  1034. ExitDressRoom();
  1035. }
  1036. }
  1037. else
  1038. {
  1039. Bubble.Show
  1040. (
  1041. null, Language.GetStr(LanguageLabel.UI__P_Return), null, null,
  1042. () =>
  1043. {
  1044. ResetDressDatas();
  1045. ResourceManager.Get(CanvasLabel.K_Bubble).GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  1046. }
  1047. );
  1048. }
  1049. }
  1050. public void ExitDressRoom()
  1051. {
  1052. Manager.SceneSwitchFlag = false;
  1053. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1054. tweenRoot.AddEventOnetime
  1055. (
  1056. EventType.BackwardFinish,
  1057. () =>
  1058. {
  1059. transform.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
  1060. transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  1061. transform.localScale = ResourceManager.Get(GardenLabel.GardenPlayerPos).lossyScale;
  1062. ResourceManager.Get(ResourceLabel.Garden).TweenForSr();
  1063. ResourceManager.Get(DressroomLabel.DressRoom).TweenBacSr();
  1064. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  1065. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenBacCG();
  1066. }
  1067. );
  1068. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1069. tweenRoot.AddEventOnetime
  1070. (
  1071. EventType.BackwardFinish,
  1072. () =>
  1073. {
  1074. SetAllCollider(true);
  1075. InDressRoom = false;
  1076. JumpTimer = 0;
  1077. PlayAnim(IdleAnimationName);
  1078. DeactiveShadow();
  1079. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenForCG();
  1080. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1081. }
  1082. );
  1083. }
  1084. public void EnterDressRoom()
  1085. {
  1086. if (Manager.SceneSwitchFlag)
  1087. {
  1088. return;
  1089. }
  1090. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenBacCG();
  1091. InDressRoom = true;
  1092. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  1093. Manager.SceneSwitchFlag = true;
  1094. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  1095. SetAllCollider(false);
  1096. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1097. tweenRoot.AddEventOnetime
  1098. (
  1099. EventType.BackwardFinish,
  1100. () =>
  1101. {
  1102. GardenManager.RetrieveAllElf();
  1103. IAPManager.RetrieveADChest();
  1104. ActiveShadow();
  1105. transform.SetParent(ResourceManager.Get(DressroomLabel.DressRoom));
  1106. transform.position = ResourceManager.Get(DressroomLabel.DressRoomPos).position;
  1107. transform.localScale = ResourceManager.Get(DressroomLabel.DressRoomPos).lossyScale;
  1108. ResourceManager.Get(ResourceLabel.Garden).TweenBacSr();
  1109. ResourceManager.Get(DressroomLabel.DressRoom).TweenForSr();
  1110. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenForCG();
  1111. }
  1112. );
  1113. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1114. tweenRoot.AddEventOnetime
  1115. (
  1116. EventType.ForwardFinish,
  1117. () =>
  1118. {
  1119. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1120. }
  1121. );
  1122. }
  1123. public void ActiveShadow()
  1124. {
  1125. ChildDic[PlayerLabel.ShadowParent].SetActive(true);
  1126. ChildDic[PlayerLabel.ShadowParent].SetLZ(3);
  1127. }
  1128. public void DeactiveShadow()
  1129. {
  1130. Shadow.GetStreamScale().Pause();
  1131. Shadow.GetStreamScale().InOrigin = true;
  1132. ChildDic[PlayerLabel.ShadowParent].SetActive(false);
  1133. }
  1134. public void DisplayInUI(float scale)
  1135. {
  1136. MeshFilter[] meshFilters = UAC.GetComponentsInChildren<MeshFilter>(true);
  1137. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1138. for (int i = 0; i < meshRenderers.Length; i++)
  1139. {
  1140. MeshFilter meshFilter = meshFilters[i];
  1141. MeshRenderer meshRenderer = meshRenderers[i];
  1142. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1143. if (unityUGUIDisplay == null) unityUGUIDisplay = meshRenderer.AddComponent<UnityUGUIDisplay>();
  1144. unityUGUIDisplay.Enable(meshFilter, meshRenderer);
  1145. unityUGUIDisplay.raycastTarget = false;
  1146. meshRenderer.enabled = false;
  1147. UAC.transform.localScale = new Vector3(scale, scale, 1);
  1148. SetAllCollider(false);
  1149. DeactiveShadow();
  1150. }
  1151. IsDisplayInUGUI = true;
  1152. UGUIScale = scale;
  1153. ResetDepth();
  1154. }
  1155. public void DisplayInScene()
  1156. {
  1157. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1158. foreach (var meshRenderer in meshRenderers)
  1159. {
  1160. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1161. if (unityUGUIDisplay == null) continue;
  1162. unityUGUIDisplay.Disable();
  1163. meshRenderer.enabled = true;
  1164. UAC.transform.localScale = Vector3.one;
  1165. SetAllCollider(true);
  1166. ActiveShadow();
  1167. }
  1168. IsDisplayInUGUI = false;
  1169. ResetDepth();
  1170. }
  1171. #region 换装
  1172. public void CorrectPivot()
  1173. {
  1174. List<Transform> children = new List<Transform>();
  1175. while (transform.childCount > 0)
  1176. {
  1177. children.Add(transform.GetChild(0));
  1178. children.Back(0).parent = null;
  1179. }
  1180. Vector3 offset = Pivot.position - transform.position;
  1181. children[0].position += offset;
  1182. children[1].position += offset;
  1183. transform.position += offset;
  1184. foreach (var collider in GetComponents<BoxCollider2D>())
  1185. {
  1186. collider.offset -= new Vector2(offset.x, offset.y);
  1187. }
  1188. for (int i = 0; i < children.Count; i++)
  1189. {
  1190. children[i].parent = transform;
  1191. }
  1192. }
  1193. public UnityArmatureComponent Build()
  1194. {
  1195. if (!PlayerManager.Inited)
  1196. {
  1197. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  1198. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex, Folder.Config), ResourceLabel.StandTexture);
  1199. PlayerManager.Inited = true;
  1200. }
  1201. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  1202. UAC.transform.parent = transform;
  1203. UAC.transform.localScale = new Vector3(1, 1, 1);
  1204. UAC.transform.localPosition = new Vector3();
  1205. UAC.anim.Play(IdleAnimationName);
  1206. UAC.AddEventListener(EventObject.START, OnAnimStart);
  1207. Eye = "眼睛1";
  1208. Top = "上衣1";
  1209. Shoe = "鞋子1";
  1210. Head = "脑壳1";
  1211. Wing = "Empty";
  1212. Dress = "裙子1";
  1213. Mouse = "嘴巴1";
  1214. HeadWear = "头饰品1";
  1215. NeckSlot = UAC.armature.GetSlot("脖子");
  1216. LeftHandSlot = UAC.armature.GetSlot("左手");
  1217. RightHandSlot = UAC.armature.GetSlot("右手");
  1218. LeftLegSlot = UAC.armature.GetSlot("左腿");
  1219. RightLegSlot = UAC.armature.GetSlot("右腿");
  1220. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  1221. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  1222. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  1223. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  1224. EyeSlot = UAC.armature.GetSlot("眼睛");
  1225. TopSlot = UAC.armature.GetSlot("上衣");
  1226. HeadSlot = UAC.armature.GetSlot("脑壳");
  1227. WingSlot = UAC.armature.GetSlot("翅膀");
  1228. DressSlot = UAC.armature.GetSlot("裙子");
  1229. MouseSlot = UAC.armature.GetSlot("嘴巴");
  1230. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  1231. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  1232. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  1233. ChangeClose(BodyPart.Eye, "眼睛1", false);
  1234. ChangeClose(BodyPart.Top, "上衣1", false);
  1235. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  1236. ChangeClose(BodyPart.Head, "脑壳1", false);
  1237. ChangeClose(BodyPart.Dress, "裙子1", false);
  1238. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  1239. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  1240. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  1241. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  1242. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  1243. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  1244. CorrectPivot();
  1245. return UAC;
  1246. }
  1247. public UnityArmatureComponent BuildPink()
  1248. {
  1249. Build();
  1250. ChangeClose(BodyPart.Eye, "眼睛3", false);
  1251. ChangeClose(BodyPart.Top, "上衣3", false);
  1252. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  1253. ChangeClose(BodyPart.Head, "脑壳3", false);
  1254. ChangeClose(BodyPart.Wing, "Empty", false);
  1255. ChangeClose(BodyPart.Dress, "裙子3", false);
  1256. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  1257. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  1258. ResetDepth();
  1259. return UAC;
  1260. }
  1261. public UnityArmatureComponent BuildBlond()
  1262. {
  1263. Build();
  1264. ChangeClose(BodyPart.Wing, "Empty", false);
  1265. ResetDepth();
  1266. return UAC;
  1267. }
  1268. public UnityArmatureComponent BuildBrown()
  1269. {
  1270. Build();
  1271. ChangeClose(BodyPart.Eye, "眼睛2", false);
  1272. ChangeClose(BodyPart.Top, "上衣2", false);
  1273. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  1274. ChangeClose(BodyPart.Head, "脑壳2", false);
  1275. ChangeClose(BodyPart.Wing, "Empty", false);
  1276. ChangeClose(BodyPart.Dress, "裙子2", false);
  1277. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  1278. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  1279. ResetDepth();
  1280. return UAC;
  1281. }
  1282. public void ResetDepth()
  1283. {
  1284. if (IsDisplayInUGUI)
  1285. {
  1286. SetSlotAsFirstChild(TopSlot);
  1287. SetSlotAsFirstChild(DressSlot);
  1288. SetSlotAsFirstChild(LeftShortSleeveSlot);
  1289. SetSlotAsFirstChild(RightShortSleeveSlot);
  1290. LeftLongSleeveUAC.transform.SetAsFirstSibling();
  1291. RightLongSleeveUAC.transform.SetAsFirstSibling();
  1292. SetSlotAsFirstChild(EyeSlot);
  1293. SetSlotAsFirstChild(MouseSlot);
  1294. SetSlotAsFirstChild(LeftShoeSlot);
  1295. SetSlotAsFirstChild(RightShoeSlot);
  1296. SetSlotAsFirstChild(HeadWearSlot);
  1297. SetSlotAsFirstChild(LeftHandSlot);
  1298. SetSlotAsFirstChild(RightHandSlot);
  1299. SetSlotAsFirstChild(HeadSlot);
  1300. SetSlotAsFirstChild(LeftLegSlot);
  1301. SetSlotAsFirstChild(RightLegSlot);
  1302. SetSlotAsFirstChild(NeckSlot);
  1303. SetSlotAsFirstChild(WingSlot);
  1304. }
  1305. else
  1306. {
  1307. UAC.transform.SetLZ(2.5f);
  1308. SetSlotLocalZ(WingSlot, 0.00003f);
  1309. SetSlotLocalZ(EyeSlot, -0.00001f);
  1310. SetSlotLocalZ(TopSlot, -0.00003f);
  1311. SetSlotLocalZ(MouseSlot, -0.00001f);
  1312. SetSlotLocalZ(HeadWearSlot, -0.00001f);
  1313. SetSlotLocalZ(LeftShoeSlot, -0.00001f);
  1314. SetSlotLocalZ(RightShoeSlot, -0.00001f);
  1315. SetSlotLocalZ(LeftLegSlot, 0);
  1316. SetSlotLocalZ(RightLegSlot, 0);
  1317. SetSlotLocalZ(NeckSlot, 0.00001f);
  1318. SetSlotLocalZ(LeftHandSlot, -0.00001f);
  1319. SetSlotLocalZ(RightHandSlot, -0.00001f);
  1320. SetSlotLocalZ(LeftShortSleeveSlot, -0.000015f);
  1321. SetSlotLocalZ(RightShortSleeveSlot, -0.000015f);
  1322. SetSlotLocalZ(HeadSlot, 0);
  1323. if (HeadSlot.UnityTransform != null && HeadSlot.UnityTransform.childCount > 1)
  1324. {
  1325. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1326. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1327. }
  1328. SetSlotLocalZ(DressSlot, -0.00002f);
  1329. if (DressSlot.UnityTransform != null && DressSlot.UnityTransform.childCount > 1)
  1330. {
  1331. DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1332. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1333. }
  1334. LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1335. RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1336. //UAC.transform.SetLZ(2.5f);
  1337. //WingSlot.UnityTransform.SetLZ(0);
  1338. //EyeSlot.UnityTransform.SetLZ(0);
  1339. //TopSlot.UnityTransform.SetLZ(0);
  1340. //MouseSlot.UnityTransform.SetLZ(0);
  1341. //HeadWearSlot.UnityTransform.SetLZ(0);
  1342. //LeftShoeSlot.UnityTransform.SetLZ(0);
  1343. //RightShoeSlot.UnityTransform.SetLZ(0);
  1344. //LeftLegSlot.UnityTransform.SetLZ(0);
  1345. //RightLegSlot.UnityTransform.SetLZ(0);
  1346. //NeckSlot.UnityTransform.SetLZ(0);
  1347. //LeftHandSlot.UnityTransform.SetLZ(0);
  1348. //RightHandSlot.UnityTransform.SetLZ(0);
  1349. //LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  1350. //RightShortSleeveSlot.UnityTransform.SetLZ(0);
  1351. //WingSlot.SetLZ(0.00003f);
  1352. //EyeSlot.SetLZ(-0.00001f);
  1353. //TopSlot.SetLZ(-0.00003f);
  1354. //MouseSlot.SetLZ(-0.00001f);
  1355. //HeadWearSlot.SetLZ(-0.00001f);
  1356. //HeadSlot.UnityTransform.SetLZ(0);
  1357. //if (HeadSlot.UnityTransform.childCount > 1)
  1358. //{
  1359. // HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1360. // HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1361. //}
  1362. //DressSlot.UnityTransform.SetLZ(-0.00002f);
  1363. //if (DressSlot.UnityTransform.childCount > 1)
  1364. //{
  1365. // DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1366. // DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1367. //}
  1368. //LeftShoeSlot.SetLZ(-0.00001f);
  1369. //RightShoeSlot.SetLZ(-0.00001f);
  1370. //LeftLegSlot.SetLZ(0);
  1371. //RightLegSlot.SetLZ(0);
  1372. //NeckSlot.SetLZ(0.00001f);
  1373. //LeftHandSlot.SetLZ(-0.00001f);
  1374. //RightHandSlot.SetLZ(-0.00001f);
  1375. //LeftShortSleeveSlot.SetLZ(-0.000015f);
  1376. //RightShortSleeveSlot.SetLZ(-0.000015f);
  1377. //LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1378. //RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1379. }
  1380. }
  1381. private void SetSlotLocalZ(DragonBones.Slot slot, float z)
  1382. {
  1383. if (slot.UnityTransform == null)
  1384. {
  1385. UAC.transform.FindChild(slot.name).SetLZ(z);
  1386. }
  1387. else
  1388. {
  1389. slot.UnityTransform.SetLZ(z);
  1390. }
  1391. }
  1392. private void SetSlotAsFirstChild(DragonBones.Slot slot)
  1393. {
  1394. if (slot.UnityTransform == null)
  1395. {
  1396. UAC.transform.FindChild(slot.name).SetAsFirstSibling();
  1397. }
  1398. else
  1399. {
  1400. slot.UnityTransform.SetAsFirstSibling();
  1401. }
  1402. }
  1403. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  1404. {
  1405. // Debug.Log (bodyPart + " " + armatureName);
  1406. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  1407. if (bodyPart == BodyPart.Eye)
  1408. {
  1409. Eye = armatureName;
  1410. slotList.Add(EyeSlot);
  1411. }
  1412. else if (bodyPart == BodyPart.Top)
  1413. {
  1414. Top = armatureName;
  1415. slotList.Add(TopSlot);
  1416. }
  1417. else if (bodyPart == BodyPart.Shoe)
  1418. {
  1419. Shoe = armatureName;
  1420. slotList.Add(LeftShoeSlot);
  1421. slotList.Add(RightShoeSlot);
  1422. }
  1423. else if (bodyPart == BodyPart.Head)
  1424. {
  1425. Head = armatureName;
  1426. slotList.Add(HeadSlot);
  1427. }
  1428. else if (bodyPart == BodyPart.Wing)
  1429. {
  1430. if (Wing == armatureName)
  1431. {
  1432. return;
  1433. }
  1434. else
  1435. {
  1436. Wing = armatureName;
  1437. slotList.Add(WingSlot);
  1438. }
  1439. }
  1440. else if (bodyPart == BodyPart.Dress)
  1441. {
  1442. Dress = armatureName;
  1443. slotList.Add(DressSlot);
  1444. }
  1445. else if (bodyPart == BodyPart.Mouse)
  1446. {
  1447. Mouse = armatureName;
  1448. slotList.Add(MouseSlot);
  1449. }
  1450. else if (bodyPart == BodyPart.Headwear)
  1451. {
  1452. HeadWear = armatureName;
  1453. slotList.Add(HeadWearSlot);
  1454. }
  1455. else if (bodyPart == BodyPart.Leg)
  1456. {
  1457. slotList.Add(LeftLegSlot);
  1458. slotList.Add(RightLegSlot);
  1459. }
  1460. else if (bodyPart == BodyPart.LeftHand)
  1461. {
  1462. slotList.Add(LeftHandSlot);
  1463. }
  1464. else if (bodyPart == BodyPart.RightHand)
  1465. {
  1466. slotList.Add(RightHandSlot);
  1467. }
  1468. else if (bodyPart == BodyPart.Neck)
  1469. {
  1470. slotList.Add(NeckSlot);
  1471. }
  1472. else if (bodyPart == BodyPart.LeftLongSleeve)
  1473. {
  1474. LeftLongSleeve = armatureName;
  1475. ChangeClose(LeftLongSleeveUAC, armatureName);
  1476. return;
  1477. }
  1478. else if (bodyPart == BodyPart.LeftShortSleeve)
  1479. {
  1480. LeftShortSleeve = armatureName;
  1481. slotList.Add(LeftShortSleeveSlot);
  1482. }
  1483. else if (bodyPart == BodyPart.RightLongSleeve)
  1484. {
  1485. RightLongSleeve = armatureName;
  1486. ChangeClose(RightLongSleeveUAC, armatureName);
  1487. return;
  1488. }
  1489. else if (bodyPart == BodyPart.RightShortSleeve)
  1490. {
  1491. RightShortSleeve = armatureName;
  1492. slotList.Add(RightShortSleeveSlot);
  1493. }
  1494. else
  1495. {
  1496. throw new Exception();
  1497. }
  1498. ChangeClose(slotList, armatureName, setDepth);
  1499. if (bodyPart == BodyPart.Wing)
  1500. {
  1501. 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);
  1502. tweenRoot.PingPong = true;
  1503. tweenRoot.StartForward();
  1504. }
  1505. }
  1506. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1507. {
  1508. for (int i = 0; i < slotList.Count; i++)
  1509. {
  1510. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1511. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1512. }
  1513. if (setDepth)
  1514. {
  1515. DelayCall.Call
  1516. (
  1517. 1,
  1518. () =>
  1519. {
  1520. ResetDepth();
  1521. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1522. }
  1523. );
  1524. }
  1525. }
  1526. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1527. {
  1528. if (armatureName == "Empty")
  1529. {
  1530. uac.SetActive(false);
  1531. }
  1532. else
  1533. {
  1534. uac.SetActive(true);
  1535. }
  1536. if (setDepth)
  1537. {
  1538. DelayCall.Call
  1539. (
  1540. 1,
  1541. () =>
  1542. {
  1543. ResetDepth();
  1544. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1545. }
  1546. );
  1547. }
  1548. }
  1549. #endregion
  1550. }