Player.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  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.ShrinkBigNumberStr(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. ConfigManager.SaveConfigDocument();
  455. ConfigManager.SaveConfigDocumentToDisk();
  456. }
  457. public void NavigateToChargeFromDressroom()
  458. {
  459. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.Pa_Info).TweenBacCG();
  460. tweenRoot.AddEventOnetime
  461. (
  462. EventType.BackwardFinish,
  463. () =>
  464. {
  465. PlayerManager.Player.LeaveDressroom();
  466. }
  467. );
  468. ResourceManager.Get(CanvasLabel.B_SignIn0).GetTweenCG().AddEventOnetime
  469. (
  470. EventType.ForwardFinish,
  471. () =>
  472. {
  473. ResourceManager.Get(CanvasLabel.F_Manage0).TweenForVec();
  474. }
  475. );
  476. }
  477. public void ChangeDress(Player player, bool resetDepth = true)
  478. {
  479. player.ChangeClose(BodyPart, ArmatureName, resetDepth);
  480. if (Unavailable)
  481. {
  482. return;
  483. }
  484. if (ExtraBodyParts.Length > 0)
  485. {
  486. player.ChangeClose(BodyPart.LeftLongSleeve, "Empty", resetDepth);
  487. player.ChangeClose(BodyPart.LeftShortSleeve, "Empty", resetDepth);
  488. player.ChangeClose(BodyPart.RightLongSleeve, "Empty", resetDepth);
  489. player.ChangeClose(BodyPart.RightShortSleeve, "Empty", resetDepth);
  490. }
  491. for (int i = 0; i < ExtraArmatureNames.Length; i++)
  492. {
  493. player.ChangeClose(ExtraBodyParts[i], ExtraArmatureNames[i], resetDepth);
  494. }
  495. }
  496. public void SaveDressData() //仅在购买完成时调用
  497. {
  498. SaveDressData(BodyPart);
  499. if (BodyPart == BodyPart.Top)
  500. {
  501. PlayerManager.DressDatas[8] = "Empty";
  502. PlayerManager.DressDatas[9] = "Empty";
  503. PlayerManager.DressDatas[10] = "Empty";
  504. PlayerManager.DressDatas[11] = "Empty";
  505. foreach (var bodyPart in ExtraBodyParts)
  506. {
  507. SaveDressData(bodyPart);
  508. }
  509. }
  510. }
  511. public void SaveDressData(BodyPart bodyPart) //仅在购买完成时调用
  512. {
  513. if (bodyPart == BodyPart.LeftLongSleeve)
  514. {
  515. PlayerManager.DressDatas[8] = PlayerManager.Player.LeftLongSleeve;
  516. }
  517. else if (bodyPart == BodyPart.LeftShortSleeve)
  518. {
  519. PlayerManager.DressDatas[9] = PlayerManager.Player.LeftShortSleeve;
  520. }
  521. else if (bodyPart == BodyPart.RightLongSleeve)
  522. {
  523. PlayerManager.DressDatas[10] = PlayerManager.Player.RightLongSleeve;
  524. }
  525. else if (bodyPart == BodyPart.RightShortSleeve)
  526. {
  527. PlayerManager.DressDatas[11] = PlayerManager.Player.RightShortSleeve;
  528. }
  529. else if (bodyPart == BodyPart.Top)
  530. {
  531. PlayerManager.DressDatas[4] = PlayerManager.Player.Top;
  532. }
  533. else if (bodyPart == BodyPart.Shoe)
  534. {
  535. PlayerManager.DressDatas[2] = PlayerManager.Player.Shoe;
  536. }
  537. else if (bodyPart == BodyPart.Head)
  538. {
  539. PlayerManager.DressDatas[0] = PlayerManager.Player.Head;
  540. }
  541. else if (bodyPart == BodyPart.Wing)
  542. {
  543. PlayerManager.DressDatas[7] = PlayerManager.Player.Wing;
  544. }
  545. else if (bodyPart == BodyPart.Dress)
  546. {
  547. PlayerManager.DressDatas[1] = PlayerManager.Player.Dress;
  548. }
  549. else if (bodyPart == BodyPart.Headwear)
  550. {
  551. PlayerManager.DressDatas[3] = PlayerManager.Player.HeadWear;
  552. }
  553. else
  554. {
  555. throw new Exception();
  556. }
  557. }
  558. public void OnLevelChange()
  559. {
  560. if (Unavailable)
  561. {
  562. return;
  563. }
  564. if (IsBought)
  565. {
  566. return;
  567. }
  568. if (BuyLevel <= Manager.GardenLevel)
  569. {
  570. BuyBtn.interactable = true;
  571. BuyBtn.image.material = null;
  572. }
  573. }
  574. public ExchangeInfo GetExchangeValue(float rate, StaticsManager.ConsumeModule consumeModule)
  575. {
  576. ExchangeInfo info = ExchangeInfo.GetExchangeInfo(BuyCurrent, BuyCost, rate);
  577. ExchangeInfo.GetExchangeValue(info, consumeModule);
  578. return info;
  579. }
  580. public static List<KV<Current, KV<int, double>>> GetTotalBuyCost(bool excludeBought, List<int> closeIDs)
  581. {
  582. int coinAmount = 0;
  583. int diamondAmount = 0;
  584. double totalCoin = 0;
  585. double totalDiamond = 0;
  586. foreach (var closeID in closeIDs)
  587. {
  588. if (PlayerManager.CloseItemDictionary[closeID].Sprites == null) continue;
  589. if (PlayerManager.CloseItemDictionary[closeID].ArmatureName == "Empty") continue;
  590. CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
  591. if (closeItem.IsBought && excludeBought) continue;
  592. if (closeItem.BuyCurrent == Current.Coin)
  593. {
  594. totalCoin += closeItem.BuyCost;
  595. coinAmount++;
  596. }
  597. if (closeItem.BuyCurrent == Current.Diamond)
  598. {
  599. totalDiamond += closeItem.BuyCost;
  600. diamondAmount++;
  601. }
  602. }
  603. List<KV<Current, KV<int, double>>> results = new List<KV<Current, KV<int, double>>>();
  604. results.Add(new KV<Current, KV<int, double>>(Current.Coin, new KV<int, double>(coinAmount, totalCoin)));
  605. results.Add(new KV<Current, KV<int, double>>(Current.Diamond, new KV<int, double>(diamondAmount, totalDiamond)));
  606. return results;
  607. }
  608. }
  609. public enum PlayerDirection
  610. {
  611. Left = 0,
  612. Right = 1,
  613. }
  614. public class Player : Regist , IPointerClickHandler
  615. {
  616. #region Config
  617. public static string IdleAnimationName = "newAnimation";
  618. public static string JumpAnimationName = "newAnimation1";
  619. public static string WalkAnimationName = "newAnimation2";
  620. public static string RunAnimationName = "newAnimation3";
  621. public static bool InDressRoom;
  622. public static float InDressRoomJumpFrequency;
  623. public float JumpTime;
  624. public float JumpTimer;
  625. public PlayerDirection PlayerDirection
  626. {
  627. get { return playerDirection; }
  628. set
  629. {
  630. playerDirection = value;
  631. Flip(playerDirection);
  632. }
  633. }
  634. public PlayerDirection playerDirection = PlayerDirection.Left;
  635. public bool IsDisplayInUGUI;
  636. public float UGUIScale;
  637. public bool PlayAnimFlag1;
  638. public bool PlayAnimFlag2;
  639. public string CurrentAnimationName;
  640. public Material Material;
  641. public MeshFilter ExpressionMeshFilter;
  642. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  643. private string ExpressionName;
  644. private Coroutine ResetExpressionCoroutine;
  645. public static Dictionary<string, Vector3> LeftExpressionPositionDictionary = new Dictionary<string, Vector3>
  646. {
  647. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  648. {"汗颜", new Vector3(0.35f, 0.91f, -0.00001f)},
  649. {"惊讶", new Vector3(0.09f, -0.07f, -0.00001f)},
  650. {"开心", new Vector3(0.1f, -0.22f, -0.00001f)},
  651. {"哭", new Vector3(0.07f, -0.64f, -0.00001f)},
  652. {"期待", new Vector3(0.04f, -0.20f, -0.00001f)},
  653. {"色咪咪", new Vector3(0.03f, -0.09f, -0.00001f)},
  654. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  655. };
  656. public static Dictionary<string, Vector3> RightExpressionPositionDictionary = new Dictionary<string, Vector3>
  657. {
  658. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  659. {"汗颜", new Vector3(-0.22f, 0.91f, -0.00001f)},
  660. {"惊讶", new Vector3(-0.09f, -0.07f, -0.00001f)},
  661. {"开心", new Vector3(-0.1f, -0.22f, -0.00001f)},
  662. {"哭", new Vector3(-0.07f, -0.64f, -0.00001f)},
  663. {"期待", new Vector3(-0.04f, -0.20f, -0.00001f)},
  664. {"色咪咪", new Vector3(-0.03f, -0.09f, -0.00001f)},
  665. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  666. };
  667. #region 换装
  668. public Transform Shadow;
  669. private Transform Pivot
  670. {
  671. get
  672. {
  673. if (pivot == null)
  674. {
  675. pivot = UAC.transform.FindChild(PlayerLabel.Pivot);
  676. }
  677. return pivot;
  678. }
  679. }
  680. private Transform pivot;
  681. public string Eye;
  682. public string Top;
  683. public string Shoe;
  684. public string Head;
  685. public string Wing;
  686. public string Dress;
  687. public string Mouse;
  688. public string HeadWear;
  689. public string LeftLongSleeve;
  690. public string LeftShortSleeve;
  691. public string RightLongSleeve;
  692. public string RightShortSleeve;
  693. private string TempClose;
  694. public DragonBones.Slot NeckSlot;
  695. public DragonBones.Slot LeftHandSlot;
  696. public DragonBones.Slot RightHandSlot;
  697. public DragonBones.Slot LeftLegSlot;
  698. public DragonBones.Slot RightLegSlot;
  699. public DragonBones.Slot LeftShortSleeveSlot;
  700. public DragonBones.Slot RightShortSleeveSlot;
  701. public DragonBones.Slot EyeSlot;
  702. public DragonBones.Slot TopSlot;
  703. public DragonBones.Slot HeadSlot;
  704. public DragonBones.Slot DressSlot;
  705. public DragonBones.Slot WingSlot;
  706. public DragonBones.Slot MouseSlot;
  707. public DragonBones.Slot LeftShoeSlot;
  708. public DragonBones.Slot RightShoeSlot;
  709. public DragonBones.Slot HeadWearSlot;
  710. public UnityArmatureComponent UAC;
  711. //public UnityArmatureComponent LeftShortSleeveUAC;
  712. //public UnityArmatureComponent RightShortSleeveUAC;
  713. public UnityArmatureComponent LeftLongSleeveUAC;
  714. public UnityArmatureComponent RightLongSleeveUAC;
  715. #endregion
  716. #endregion
  717. public override bool InitAtOnce()
  718. {
  719. if (base.InitAtOnce())
  720. {
  721. return true;
  722. }
  723. enabled = true;
  724. Auxiliary.CompileDic(transform, ChildDic);
  725. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  726. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  727. Shadow = ChildDic[PlayerLabel.Shadow];
  728. Shadow.CreateStreamScale
  729. (
  730. new List<float>() {0, 0, 0},
  731. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  732. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  733. true,
  734. true,
  735. Curve.EaseOutQuad
  736. );
  737. MeshFilter meshFilter = Shadow.GetComponent<MeshFilter>();
  738. meshFilter.mesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(ResourceLabel.FlowerShadow, Folder.Scene));
  739. meshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), meshFilter.mesh.vertices.Length).ToList());
  740. return false;
  741. }
  742. public void Update()
  743. {
  744. if (InDressRoom)
  745. {
  746. JumpTimer += Time.deltaTime;
  747. if (JumpTimer > JumpTime)
  748. {
  749. if (!PlayAnimFlag1 && !PlayAnimFlag2)
  750. {
  751. PlayAnim(JumpAnimationName);
  752. }
  753. PlayAnimFlag2 = true;
  754. }
  755. if (JumpTimer > InDressRoomJumpFrequency)
  756. {
  757. PlayAnimFlag2 = false;
  758. JumpTime = Mathf.Lerp(0, InDressRoomJumpFrequency, Random.Range(0f, 1f));
  759. JumpTimer = 0;
  760. }
  761. }
  762. //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  763. //{
  764. // MoveThread();
  765. //}
  766. }
  767. public void OnAnimStart(string str, EventObject eventObject)
  768. {
  769. if (eventObject.animationState.name == JumpAnimationName)
  770. {
  771. Shadow.StreamReForScale();
  772. PlayAnimFlag1 = true;
  773. TempClose = Eye;
  774. ChangeClose(BodyPart.Eye, "眼睛表情1");
  775. }
  776. else if (eventObject.animationState.name == IdleAnimationName)
  777. {
  778. PlayAnimFlag1 = false;
  779. if (TempClose != null)
  780. {
  781. ChangeClose(BodyPart.Eye, TempClose);
  782. }
  783. }
  784. }
  785. public void PlayAnim(string animName)
  786. {
  787. if (PlayAnimFlag1)
  788. {
  789. return;
  790. }
  791. if (UAC.anim.lastAnimationName == animName)
  792. {
  793. return;
  794. }
  795. if (SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
  796. {
  797. CurrentAnimationName = animName;
  798. }
  799. UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
  800. }
  801. public float GetFadeInTime(string lastAnimation, string targetAnimation)
  802. {
  803. if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
  804. return -1f;
  805. else
  806. return 0.1f;
  807. //throw new Exception();
  808. }
  809. public void SetAllCollider(bool enable)
  810. {
  811. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  812. for (int i = 0; i < colliders.Length; i++)
  813. {
  814. colliders[i].enabled = enable;
  815. }
  816. }
  817. public void OnPointerClick(PointerEventData eventData)
  818. {
  819. AudioManager.PlayClip(AudioLabel.GetCurrent);
  820. PlayAnim(JumpAnimationName);
  821. }
  822. public void ResetExpression()
  823. {
  824. ExpressionMeshFilter.SetActive(false);
  825. EyeSlot.UnityTransform.GetChild(0).SetActive(true);
  826. MouseSlot.UnityTransform.GetChild(0).SetActive(true);
  827. }
  828. public void ChangeExpression(string expressionName, float duration)
  829. {
  830. ExpressionName = expressionName;
  831. ExpressionMeshFilter.sharedMesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(expressionName, Folder.Scene));
  832. ExpressionMeshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), ExpressionMeshFilter.mesh.vertices.Length).ToList());
  833. ExpressionMeshFilter.transform.parent = EyeSlot.UnityTransform;
  834. ExpressionMeshFilter.SetActive(true);
  835. EyeSlot.UnityTransform.GetChild(0).SetActive(false);
  836. MouseSlot.UnityTransform.GetChild(0).SetActive(false);
  837. FlipExpression(expressionName, PlayerDirection);
  838. if (ResetExpressionCoroutine != null)
  839. Auxiliary.Instance.StopCoroutine(ResetExpressionCoroutine);
  840. ResetExpressionCoroutine = Auxiliary.Instance.DelayCall
  841. (
  842. () =>
  843. {
  844. ResetExpression();
  845. },
  846. duration
  847. );
  848. }
  849. public void Flip(PlayerDirection direction)
  850. {
  851. FlipExpression(ExpressionName, direction);
  852. if (direction == PlayerDirection.Left)
  853. {
  854. UAC.armature.flipX = false;
  855. playerDirection = PlayerDirection.Left;
  856. }
  857. else if (direction == PlayerDirection.Right)
  858. {
  859. UAC.armature.flipX = true;
  860. playerDirection = PlayerDirection.Right;
  861. }
  862. else
  863. {
  864. throw new Exception();
  865. }
  866. DelayCall.Call(1, () => Shadow.SetX(Pivot.position.x));
  867. }
  868. public void FlipExpression(string expressionName, PlayerDirection direction)
  869. {
  870. if (string.IsNullOrEmpty(ExpressionName))
  871. {
  872. return;
  873. }
  874. if (direction == PlayerDirection.Left)
  875. {
  876. ExpressionMeshFilter.transform.eulerAngles = new Vector3();
  877. ExpressionMeshFilter.transform.localPosition = LeftExpressionPositionDictionary[ExpressionName];
  878. }
  879. else if (direction == PlayerDirection.Right)
  880. {
  881. UAC.armature.flipX = true;
  882. ExpressionMeshFilter.transform.eulerAngles = new Vector3(0, 180, 0);
  883. ExpressionMeshFilter.transform.localPosition = RightExpressionPositionDictionary[ExpressionName];
  884. playerDirection = PlayerDirection.Right;
  885. }
  886. else
  887. {
  888. throw new Exception();
  889. }
  890. }
  891. public void SaveDressDatas(bool showNavigate)
  892. {
  893. AudioManager.PlayClip(AudioLabel.ClickButton);
  894. List<CloseItem> closeUnitList = new List<CloseItem>();
  895. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Head]]);
  896. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Dress]]);
  897. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Shoe]]);
  898. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[HeadWear]]);
  899. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Top]]);
  900. if (Wing != "Empty")
  901. {
  902. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Wing]]);
  903. }
  904. for (int i = 0; i < closeUnitList.Count; i++)
  905. {
  906. if (!closeUnitList[i].IsBought)
  907. {
  908. if (showNavigate)
  909. {
  910. BuyDressNavigate(closeUnitList);
  911. }
  912. return;
  913. }
  914. }
  915. PlayerManager.DressDatas[0] = Head;
  916. PlayerManager.DressDatas[1] = Dress;
  917. PlayerManager.DressDatas[2] = Shoe;
  918. PlayerManager.DressDatas[3] = HeadWear;
  919. PlayerManager.DressDatas[4] = Top;
  920. PlayerManager.DressDatas[7] = Wing;
  921. PlayerManager.DressDatas[8] = LeftLongSleeve;
  922. PlayerManager.DressDatas[9] = LeftShortSleeve;
  923. PlayerManager.DressDatas[10] = RightLongSleeve;
  924. PlayerManager.DressDatas[11] = RightShortSleeve;
  925. Toast.Show(1.5f, Language.GetStr(LanguageLabel.UI__P_SaveSucceed));
  926. }
  927. public void ResetDressDatas()
  928. {
  929. AudioManager.PlayClip(AudioLabel.ClickButton);
  930. List<string> dressData = new List<string>(PlayerManager.DressDatas);
  931. dressData[5] = Eye;
  932. PlayerManager.BuildPlayer(dressData);
  933. }
  934. public List<int> GetCurrentChangableDressIDs()
  935. {
  936. List<int> ids = new List<int>();
  937. ids.Add(PlayerManager.CloseIDDictionary[Head]);
  938. ids.Add(PlayerManager.CloseIDDictionary[Dress]);
  939. ids.Add(PlayerManager.CloseIDDictionary[Shoe]);
  940. ids.Add(PlayerManager.CloseIDDictionary[HeadWear]);
  941. ids.Add(PlayerManager.CloseIDDictionary[Top]);
  942. ids.Add(PlayerManager.CloseIDDictionary[Wing]);
  943. ids.Add(PlayAnimFlag1 ? PlayerManager.CloseIDDictionary[TempClose] : PlayerManager.CloseIDDictionary[Eye]);
  944. ids.Add(PlayerManager.CloseIDDictionary[Mouse]);
  945. ids.Add(PlayerManager.CloseIDDictionary[Wing]);
  946. return ids;
  947. }
  948. public static List<string> DressIDToDressName(List<int> ids)
  949. {
  950. List<string> names = new List<string>();
  951. foreach (var id in ids)
  952. {
  953. names.Add(PlayerManager.CloseItemDictionary[id].ArmatureName);
  954. }
  955. return names;
  956. }
  957. public List<string> GetCurrentDressNames()
  958. {
  959. List<string> names = new List<string>();
  960. return names;
  961. }
  962. public List<string> GetCurrentChangableDressNames()
  963. {
  964. List<string> names = new List<string>();
  965. names.Add(Head);
  966. names.Add(Dress);
  967. names.Add(Shoe);
  968. names.Add(HeadWear);
  969. names.Add(Top);
  970. names.Add(Wing);
  971. if (PlayAnimFlag1) names.Add(TempClose);
  972. else names.Add(Eye);
  973. names.Add(Mouse);
  974. names.Add(Wing);
  975. return names;
  976. }
  977. public void BuyDressNavigate(List<CloseItem> closeUnitList)
  978. {
  979. for (int i = 0; i < closeUnitList.Count; i++)
  980. {
  981. if (closeUnitList[i].IsBought)
  982. {
  983. closeUnitList.RemoveAt(i--);
  984. }
  985. else
  986. {
  987. closeUnitList[i].BuyBtn.onClick.Invoke();
  988. closeUnitList.RemoveAt(i--);
  989. ResourceManager.Get(CanvasLabel.Pa_Info).GetTweenCG().AddEventOnetime
  990. (
  991. EventType.BackwardFinish,
  992. () =>
  993. {
  994. if (closeUnitList.Count == 0)
  995. {
  996. SaveDressDatas(false);
  997. }
  998. else
  999. {
  1000. BuyDressNavigate(closeUnitList);
  1001. }
  1002. }
  1003. );
  1004. return;
  1005. }
  1006. }
  1007. }
  1008. public void LeaveDressroom()
  1009. {
  1010. bool allSave = true;
  1011. bool allBought = true;
  1012. List<string> currentDerssData = new List<string>() { Head, Dress, Shoe, HeadWear, Top, Wing };
  1013. if (currentDerssData[0] != PlayerManager.DressDatas[0]) allSave = false;
  1014. if (currentDerssData[1] != PlayerManager.DressDatas[1]) allSave = false;
  1015. if (currentDerssData[2] != PlayerManager.DressDatas[2]) allSave = false;
  1016. if (currentDerssData[3] != PlayerManager.DressDatas[3]) allSave = false;
  1017. if (currentDerssData[4] != PlayerManager.DressDatas[4]) allSave = false;
  1018. if (currentDerssData[5] != PlayerManager.DressDatas[7]) allSave = false;
  1019. for (int i = 0; i < currentDerssData.Count; i++)
  1020. {
  1021. if (!PlayerManager.CloseIDDictionary.ContainsKey(currentDerssData[i]))
  1022. {
  1023. continue;
  1024. }
  1025. int id = PlayerManager.CloseIDDictionary[currentDerssData[i]];
  1026. allBought = allBought && PlayerManager.CloseItemDictionary[id].IsBought;
  1027. //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
  1028. //allSave = allSave && currentDerssData[i] == PlayerManager.DressDatas[i];
  1029. //Debug.Log(currentDerssData[i] + " " + PlayerManager.DressDatas[i]);
  1030. }
  1031. //Debug.Log(allBought);
  1032. //Debug.Log(allSave);
  1033. if (allBought)
  1034. {
  1035. if (allSave)
  1036. {
  1037. ExitDressRoom();
  1038. }
  1039. else
  1040. {
  1041. ResetDressDatas();
  1042. ExitDressRoom();
  1043. }
  1044. }
  1045. else
  1046. {
  1047. Bubble.Show
  1048. (
  1049. null, Language.GetStr(LanguageLabel.UI__P_Return), null, null,
  1050. () =>
  1051. {
  1052. ResetDressDatas();
  1053. ResourceManager.Get(CanvasLabel.K_Bubble).GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  1054. }
  1055. );
  1056. }
  1057. }
  1058. public void ExitDressRoom()
  1059. {
  1060. Manager.SceneSwitchFlag = false;
  1061. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1062. tweenRoot.AddEventOnetime
  1063. (
  1064. EventType.BackwardFinish,
  1065. () =>
  1066. {
  1067. transform.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
  1068. transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  1069. transform.localScale = ResourceManager.Get(GardenLabel.GardenPlayerPos).lossyScale;
  1070. ResourceManager.Get(ResourceLabel.Garden).TweenForSr();
  1071. ResourceManager.Get(DressroomLabel.DressRoom).TweenBacSr();
  1072. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  1073. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenBacCG();
  1074. }
  1075. );
  1076. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1077. tweenRoot.AddEventOnetime
  1078. (
  1079. EventType.BackwardFinish,
  1080. () =>
  1081. {
  1082. SetAllCollider(true);
  1083. InDressRoom = false;
  1084. JumpTimer = 0;
  1085. PlayAnim(IdleAnimationName);
  1086. DeactiveShadow();
  1087. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenForCG();
  1088. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1089. }
  1090. );
  1091. }
  1092. public void EnterDressRoom()
  1093. {
  1094. if (Manager.SceneSwitchFlag)
  1095. {
  1096. return;
  1097. }
  1098. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenBacCG();
  1099. InDressRoom = true;
  1100. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  1101. Manager.SceneSwitchFlag = true;
  1102. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  1103. SetAllCollider(false);
  1104. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1105. tweenRoot.AddEventOnetime
  1106. (
  1107. EventType.BackwardFinish,
  1108. () =>
  1109. {
  1110. GardenManager.RetrieveAllElf();
  1111. IAPManager.RetrieveADChest();
  1112. ActiveShadow();
  1113. transform.SetParent(ResourceManager.Get(DressroomLabel.DressRoom));
  1114. transform.position = ResourceManager.Get(DressroomLabel.DressRoomPos).position;
  1115. transform.localScale = ResourceManager.Get(DressroomLabel.DressRoomPos).lossyScale;
  1116. ResourceManager.Get(ResourceLabel.Garden).TweenBacSr();
  1117. ResourceManager.Get(DressroomLabel.DressRoom).TweenForSr();
  1118. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenForCG();
  1119. }
  1120. );
  1121. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1122. tweenRoot.AddEventOnetime
  1123. (
  1124. EventType.ForwardFinish,
  1125. () =>
  1126. {
  1127. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1128. }
  1129. );
  1130. }
  1131. public void ActiveShadow()
  1132. {
  1133. ChildDic[PlayerLabel.ShadowParent].SetActive(true);
  1134. ChildDic[PlayerLabel.ShadowParent].SetLZ(3);
  1135. }
  1136. public void DeactiveShadow()
  1137. {
  1138. Shadow.GetStreamScale().Pause();
  1139. Shadow.GetStreamScale().InOrigin = true;
  1140. ChildDic[PlayerLabel.ShadowParent].SetActive(false);
  1141. }
  1142. public void DisplayInUI(float scale)
  1143. {
  1144. UGUIScale = scale;
  1145. scale *= ResourceManager.Get<Canvas>(CanvasLabel.Canvas).scaleFactor;
  1146. MeshFilter[] meshFilters = UAC.GetComponentsInChildren<MeshFilter>(true);
  1147. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1148. for (int i = 0; i < meshRenderers.Length; i++)
  1149. {
  1150. MeshFilter meshFilter = meshFilters[i];
  1151. MeshRenderer meshRenderer = meshRenderers[i];
  1152. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1153. if (unityUGUIDisplay == null) unityUGUIDisplay = meshRenderer.AddComponent<UnityUGUIDisplay>();
  1154. unityUGUIDisplay.Enable(meshFilter, meshRenderer);
  1155. unityUGUIDisplay.raycastTarget = false;
  1156. meshRenderer.enabled = false;
  1157. UAC.transform.localScale = new Vector3(scale, scale, 1);
  1158. SetAllCollider(false);
  1159. DeactiveShadow();
  1160. }
  1161. IsDisplayInUGUI = true;
  1162. ResetDepth();
  1163. }
  1164. public void DisplayInScene()
  1165. {
  1166. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1167. foreach (var meshRenderer in meshRenderers)
  1168. {
  1169. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1170. if (unityUGUIDisplay == null) continue;
  1171. unityUGUIDisplay.Disable();
  1172. meshRenderer.enabled = true;
  1173. UAC.transform.localScale = Vector3.one;
  1174. SetAllCollider(true);
  1175. ActiveShadow();
  1176. }
  1177. IsDisplayInUGUI = false;
  1178. ResetDepth();
  1179. }
  1180. #region 换装
  1181. public void CorrectPivot()
  1182. {
  1183. List<Transform> children = new List<Transform>();
  1184. while (transform.childCount > 0)
  1185. {
  1186. children.Add(transform.GetChild(0));
  1187. children.Back(0).parent = null;
  1188. }
  1189. Vector3 offset = Pivot.position - transform.position;
  1190. children[0].position += offset;
  1191. children[1].position += offset;
  1192. transform.position += offset;
  1193. foreach (var collider in GetComponents<BoxCollider2D>())
  1194. {
  1195. collider.offset -= new Vector2(offset.x, offset.y);
  1196. }
  1197. for (int i = 0; i < children.Count; i++)
  1198. {
  1199. children[i].parent = transform;
  1200. }
  1201. }
  1202. public UnityArmatureComponent Build()
  1203. {
  1204. if (!PlayerManager.Inited)
  1205. {
  1206. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  1207. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex, Folder.Config), ResourceLabel.StandTexture);
  1208. PlayerManager.Inited = true;
  1209. }
  1210. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  1211. UAC.transform.parent = transform;
  1212. UAC.transform.localScale = new Vector3(1, 1, 1);
  1213. UAC.transform.localPosition = new Vector3();
  1214. UAC.anim.Play(IdleAnimationName);
  1215. UAC.AddEventListener(EventObject.START, OnAnimStart);
  1216. Eye = "眼睛1";
  1217. Top = "上衣1";
  1218. Shoe = "鞋子1";
  1219. Head = "脑壳1";
  1220. Wing = "Empty";
  1221. Dress = "裙子1";
  1222. Mouse = "嘴巴1";
  1223. HeadWear = "头饰品1";
  1224. NeckSlot = UAC.armature.GetSlot("脖子");
  1225. LeftHandSlot = UAC.armature.GetSlot("左手");
  1226. RightHandSlot = UAC.armature.GetSlot("右手");
  1227. LeftLegSlot = UAC.armature.GetSlot("左腿");
  1228. RightLegSlot = UAC.armature.GetSlot("右腿");
  1229. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  1230. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  1231. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  1232. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  1233. EyeSlot = UAC.armature.GetSlot("眼睛");
  1234. TopSlot = UAC.armature.GetSlot("上衣");
  1235. HeadSlot = UAC.armature.GetSlot("脑壳");
  1236. WingSlot = UAC.armature.GetSlot("翅膀");
  1237. DressSlot = UAC.armature.GetSlot("裙子");
  1238. MouseSlot = UAC.armature.GetSlot("嘴巴");
  1239. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  1240. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  1241. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  1242. ChangeClose(BodyPart.Eye, "眼睛1", false);
  1243. ChangeClose(BodyPart.Top, "上衣1", false);
  1244. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  1245. ChangeClose(BodyPart.Head, "脑壳1", false);
  1246. ChangeClose(BodyPart.Dress, "裙子1", false);
  1247. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  1248. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  1249. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  1250. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  1251. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  1252. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  1253. CorrectPivot();
  1254. Material = UAC.GetComponentInChildren<MeshRenderer>().sharedMaterial;
  1255. Shadow.GetComponent<MeshRenderer>().sharedMaterial = Material;
  1256. ExpressionMeshFilter = ChildDic[PlayerLabel.ExpressionMeshFilter].GetComponent<MeshFilter>();
  1257. ExpressionMeshFilter.GetComponent<MeshRenderer>().sharedMaterial = Material;
  1258. return UAC;
  1259. }
  1260. public UnityArmatureComponent BuildPink()
  1261. {
  1262. Build();
  1263. ChangeClose(BodyPart.Eye, "眼睛3", false);
  1264. ChangeClose(BodyPart.Top, "上衣3", false);
  1265. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  1266. ChangeClose(BodyPart.Head, "脑壳3", false);
  1267. ChangeClose(BodyPart.Wing, "Empty", false);
  1268. ChangeClose(BodyPart.Dress, "裙子3", false);
  1269. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  1270. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  1271. ResetDepth();
  1272. return UAC;
  1273. }
  1274. public UnityArmatureComponent BuildBlond()
  1275. {
  1276. Build();
  1277. ChangeClose(BodyPart.Wing, "Empty", false);
  1278. ResetDepth();
  1279. return UAC;
  1280. }
  1281. public UnityArmatureComponent BuildBrown()
  1282. {
  1283. Build();
  1284. ChangeClose(BodyPart.Eye, "眼睛2", false);
  1285. ChangeClose(BodyPart.Top, "上衣2", false);
  1286. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  1287. ChangeClose(BodyPart.Head, "脑壳2", false);
  1288. ChangeClose(BodyPart.Wing, "Empty", false);
  1289. ChangeClose(BodyPart.Dress, "裙子2", false);
  1290. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  1291. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  1292. ResetDepth();
  1293. return UAC;
  1294. }
  1295. public void ResetDepth()
  1296. {
  1297. if (IsDisplayInUGUI)
  1298. {
  1299. SetSlotAsFirstChild(TopSlot);
  1300. SetSlotAsFirstChild(DressSlot);
  1301. SetSlotAsFirstChild(LeftShortSleeveSlot);
  1302. SetSlotAsFirstChild(RightShortSleeveSlot);
  1303. LeftLongSleeveUAC.transform.SetAsFirstSibling();
  1304. RightLongSleeveUAC.transform.SetAsFirstSibling();
  1305. SetSlotAsFirstChild(EyeSlot);
  1306. SetSlotAsFirstChild(MouseSlot);
  1307. SetSlotAsFirstChild(LeftShoeSlot);
  1308. SetSlotAsFirstChild(RightShoeSlot);
  1309. SetSlotAsFirstChild(HeadWearSlot);
  1310. SetSlotAsFirstChild(LeftHandSlot);
  1311. SetSlotAsFirstChild(RightHandSlot);
  1312. SetSlotAsFirstChild(HeadSlot);
  1313. SetSlotAsFirstChild(LeftLegSlot);
  1314. SetSlotAsFirstChild(RightLegSlot);
  1315. SetSlotAsFirstChild(NeckSlot);
  1316. SetSlotAsFirstChild(WingSlot);
  1317. }
  1318. else
  1319. {
  1320. //UAC.transform.SetLZ(2.5f);
  1321. UAC.transform.SetLZ(0.7f);
  1322. SetSlotLocalZ(WingSlot, 0.00003f);
  1323. SetSlotLocalZ(EyeSlot, -0.00001f);
  1324. SetSlotLocalZ(TopSlot, -0.00003f);
  1325. SetSlotLocalZ(MouseSlot, -0.00001f);
  1326. SetSlotLocalZ(HeadWearSlot, -0.00001f);
  1327. SetSlotLocalZ(LeftShoeSlot, -0.00001f);
  1328. SetSlotLocalZ(RightShoeSlot, -0.00001f);
  1329. SetSlotLocalZ(LeftLegSlot, 0);
  1330. SetSlotLocalZ(RightLegSlot, 0);
  1331. SetSlotLocalZ(NeckSlot, 0.00001f);
  1332. SetSlotLocalZ(LeftHandSlot, -0.00001f);
  1333. SetSlotLocalZ(RightHandSlot, -0.00001f);
  1334. SetSlotLocalZ(LeftShortSleeveSlot, -0.000015f);
  1335. SetSlotLocalZ(RightShortSleeveSlot, -0.000015f);
  1336. SetSlotLocalZ(HeadSlot, 0);
  1337. if (HeadSlot.UnityTransform != null && HeadSlot.UnityTransform.childCount > 1)
  1338. {
  1339. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1340. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1341. }
  1342. SetSlotLocalZ(DressSlot, -0.00002f);
  1343. if (DressSlot.UnityTransform != null && DressSlot.UnityTransform.childCount > 1)
  1344. {
  1345. DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1346. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1347. }
  1348. LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1349. RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1350. //UAC.transform.SetLZ(2.5f);
  1351. //WingSlot.UnityTransform.SetLZ(0);
  1352. //EyeSlot.UnityTransform.SetLZ(0);
  1353. //TopSlot.UnityTransform.SetLZ(0);
  1354. //MouseSlot.UnityTransform.SetLZ(0);
  1355. //HeadWearSlot.UnityTransform.SetLZ(0);
  1356. //LeftShoeSlot.UnityTransform.SetLZ(0);
  1357. //RightShoeSlot.UnityTransform.SetLZ(0);
  1358. //LeftLegSlot.UnityTransform.SetLZ(0);
  1359. //RightLegSlot.UnityTransform.SetLZ(0);
  1360. //NeckSlot.UnityTransform.SetLZ(0);
  1361. //LeftHandSlot.UnityTransform.SetLZ(0);
  1362. //RightHandSlot.UnityTransform.SetLZ(0);
  1363. //LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  1364. //RightShortSleeveSlot.UnityTransform.SetLZ(0);
  1365. //WingSlot.SetLZ(0.00003f);
  1366. //EyeSlot.SetLZ(-0.00001f);
  1367. //TopSlot.SetLZ(-0.00003f);
  1368. //MouseSlot.SetLZ(-0.00001f);
  1369. //HeadWearSlot.SetLZ(-0.00001f);
  1370. //HeadSlot.UnityTransform.SetLZ(0);
  1371. //if (HeadSlot.UnityTransform.childCount > 1)
  1372. //{
  1373. // HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1374. // HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1375. //}
  1376. //DressSlot.UnityTransform.SetLZ(-0.00002f);
  1377. //if (DressSlot.UnityTransform.childCount > 1)
  1378. //{
  1379. // DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1380. // DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1381. //}
  1382. //LeftShoeSlot.SetLZ(-0.00001f);
  1383. //RightShoeSlot.SetLZ(-0.00001f);
  1384. //LeftLegSlot.SetLZ(0);
  1385. //RightLegSlot.SetLZ(0);
  1386. //NeckSlot.SetLZ(0.00001f);
  1387. //LeftHandSlot.SetLZ(-0.00001f);
  1388. //RightHandSlot.SetLZ(-0.00001f);
  1389. //LeftShortSleeveSlot.SetLZ(-0.000015f);
  1390. //RightShortSleeveSlot.SetLZ(-0.000015f);
  1391. //LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1392. //RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1393. }
  1394. }
  1395. private void SetSlotLocalZ(DragonBones.Slot slot, float z)
  1396. {
  1397. if (slot.UnityTransform == null)
  1398. {
  1399. UAC.transform.FindChild(slot.name).SetLZ(z);
  1400. }
  1401. else
  1402. {
  1403. slot.UnityTransform.SetLZ(z);
  1404. }
  1405. }
  1406. private void SetSlotAsFirstChild(DragonBones.Slot slot)
  1407. {
  1408. if (slot.UnityTransform == null)
  1409. {
  1410. UAC.transform.FindChild(slot.name).SetAsFirstSibling();
  1411. }
  1412. else
  1413. {
  1414. slot.UnityTransform.SetAsFirstSibling();
  1415. }
  1416. }
  1417. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  1418. {
  1419. // Debug.Log (bodyPart + " " + armatureName);
  1420. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  1421. if (bodyPart == BodyPart.Eye)
  1422. {
  1423. Eye = armatureName;
  1424. slotList.Add(EyeSlot);
  1425. }
  1426. else if (bodyPart == BodyPart.Top)
  1427. {
  1428. Top = armatureName;
  1429. slotList.Add(TopSlot);
  1430. }
  1431. else if (bodyPart == BodyPart.Shoe)
  1432. {
  1433. Shoe = armatureName;
  1434. slotList.Add(LeftShoeSlot);
  1435. slotList.Add(RightShoeSlot);
  1436. }
  1437. else if (bodyPart == BodyPart.Head)
  1438. {
  1439. Head = armatureName;
  1440. slotList.Add(HeadSlot);
  1441. }
  1442. else if (bodyPart == BodyPart.Wing)
  1443. {
  1444. if (Wing == armatureName)
  1445. {
  1446. return;
  1447. }
  1448. else
  1449. {
  1450. Wing = armatureName;
  1451. slotList.Add(WingSlot);
  1452. }
  1453. }
  1454. else if (bodyPart == BodyPart.Dress)
  1455. {
  1456. Dress = armatureName;
  1457. slotList.Add(DressSlot);
  1458. }
  1459. else if (bodyPart == BodyPart.Mouse)
  1460. {
  1461. Mouse = armatureName;
  1462. slotList.Add(MouseSlot);
  1463. }
  1464. else if (bodyPart == BodyPart.Headwear)
  1465. {
  1466. HeadWear = armatureName;
  1467. slotList.Add(HeadWearSlot);
  1468. }
  1469. else if (bodyPart == BodyPart.Leg)
  1470. {
  1471. slotList.Add(LeftLegSlot);
  1472. slotList.Add(RightLegSlot);
  1473. }
  1474. else if (bodyPart == BodyPart.LeftHand)
  1475. {
  1476. slotList.Add(LeftHandSlot);
  1477. }
  1478. else if (bodyPart == BodyPart.RightHand)
  1479. {
  1480. slotList.Add(RightHandSlot);
  1481. }
  1482. else if (bodyPart == BodyPart.Neck)
  1483. {
  1484. slotList.Add(NeckSlot);
  1485. }
  1486. else if (bodyPart == BodyPart.LeftLongSleeve)
  1487. {
  1488. LeftLongSleeve = armatureName;
  1489. ChangeClose(LeftLongSleeveUAC, armatureName);
  1490. return;
  1491. }
  1492. else if (bodyPart == BodyPart.LeftShortSleeve)
  1493. {
  1494. LeftShortSleeve = armatureName;
  1495. slotList.Add(LeftShortSleeveSlot);
  1496. }
  1497. else if (bodyPart == BodyPart.RightLongSleeve)
  1498. {
  1499. RightLongSleeve = armatureName;
  1500. ChangeClose(RightLongSleeveUAC, armatureName);
  1501. return;
  1502. }
  1503. else if (bodyPart == BodyPart.RightShortSleeve)
  1504. {
  1505. RightShortSleeve = armatureName;
  1506. slotList.Add(RightShortSleeveSlot);
  1507. }
  1508. else
  1509. {
  1510. throw new Exception();
  1511. }
  1512. ChangeClose(slotList, armatureName, setDepth);
  1513. if (bodyPart == BodyPart.Wing)
  1514. {
  1515. 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);
  1516. tweenRoot.PingPong = true;
  1517. tweenRoot.StartForward();
  1518. }
  1519. }
  1520. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1521. {
  1522. for (int i = 0; i < slotList.Count; i++)
  1523. {
  1524. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1525. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1526. }
  1527. if (setDepth)
  1528. {
  1529. DelayCall.Call
  1530. (
  1531. 1,
  1532. () =>
  1533. {
  1534. ResetDepth();
  1535. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1536. }
  1537. );
  1538. }
  1539. }
  1540. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1541. {
  1542. if (armatureName == "Empty")
  1543. {
  1544. uac.SetActive(false);
  1545. }
  1546. else
  1547. {
  1548. uac.SetActive(true);
  1549. }
  1550. if (setDepth)
  1551. {
  1552. DelayCall.Call
  1553. (
  1554. 1,
  1555. () =>
  1556. {
  1557. ResetDepth();
  1558. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1559. }
  1560. );
  1561. }
  1562. }
  1563. #endregion
  1564. }