Player.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  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)
  477. {
  478. player.ChangeClose(BodyPart, ArmatureName);
  479. if (Unavailable)
  480. {
  481. return;
  482. }
  483. if (ExtraBodyParts.Length > 0)
  484. {
  485. player.ChangeClose(BodyPart.LeftLongSleeve, "Empty");
  486. player.ChangeClose(BodyPart.LeftShortSleeve, "Empty");
  487. player.ChangeClose(BodyPart.RightLongSleeve, "Empty");
  488. player.ChangeClose(BodyPart.RightShortSleeve, "Empty");
  489. }
  490. for (int i = 0; i < ExtraArmatureNames.Length; i++)
  491. {
  492. player.ChangeClose(ExtraBodyParts[i], ExtraArmatureNames[i]);
  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. CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
  588. if (closeItem.IsBought && excludeBought) continue;
  589. if (closeItem.BuyCurrent == Current.Coin)
  590. {
  591. totalCoin += closeItem.BuyCost;
  592. coinAmount++;
  593. }
  594. if (closeItem.BuyCurrent == Current.Diamond)
  595. {
  596. totalDiamond += closeItem.BuyCost;
  597. diamondAmount++;
  598. }
  599. }
  600. List<KV<Current, KV<int, double>>> results = new List<KV<Current, KV<int, double>>>();
  601. results.Add(new KV<Current, KV<int, double>>(Current.Coin, new KV<int, double>(coinAmount, totalCoin)));
  602. results.Add(new KV<Current, KV<int, double>>(Current.Diamond, new KV<int, double>(diamondAmount, totalDiamond)));
  603. return results;
  604. }
  605. }
  606. public enum PlayerDirection
  607. {
  608. Left = 0,
  609. Right = 1,
  610. }
  611. public class Player : Regist , IPointerClickHandler
  612. {
  613. #region Config
  614. public static string IdleAnimationName = "newAnimation";
  615. public static string JumpAnimationName = "newAnimation1";
  616. public static string WalkAnimationName = "newAnimation2";
  617. public static string RunAnimationName = "newAnimation3";
  618. public static bool InDressRoom;
  619. public static float InDressRoomJumpFrequency;
  620. public float JumpTime;
  621. public float JumpTimer;
  622. public PlayerDirection PlayerDirection
  623. {
  624. get { return playerDirection; }
  625. set
  626. {
  627. playerDirection = value;
  628. Flip(playerDirection);
  629. }
  630. }
  631. public PlayerDirection playerDirection = PlayerDirection.Left;
  632. public bool PlayAnimFlag1;
  633. public bool PlayAnimFlag2;
  634. public string CurrentAnimationName;
  635. public MeshFilter ExpressionMeshFilter;
  636. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  637. private string ExpressionName;
  638. private Coroutine ResetExpressionCoroutine;
  639. public static Dictionary<string, Vector3> LeftExpressionPositionDictionary = new Dictionary<string, Vector3>
  640. {
  641. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  642. {"汗颜", new Vector3(0.35f, 0.91f, -0.00001f)},
  643. {"惊讶", new Vector3(0.09f, -0.07f, -0.00001f)},
  644. {"开心", new Vector3(0.1f, -0.22f, -0.00001f)},
  645. {"哭", new Vector3(0.07f, -0.64f, -0.00001f)},
  646. {"期待", new Vector3(0.04f, -0.20f, -0.00001f)},
  647. {"色咪咪", new Vector3(0.03f, -0.09f, -0.00001f)},
  648. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  649. };
  650. public static Dictionary<string, Vector3> RightExpressionPositionDictionary = new Dictionary<string, Vector3>
  651. {
  652. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  653. {"汗颜", new Vector3(-0.22f, 0.91f, -0.00001f)},
  654. {"惊讶", new Vector3(-0.09f, -0.07f, -0.00001f)},
  655. {"开心", new Vector3(-0.1f, -0.22f, -0.00001f)},
  656. {"哭", new Vector3(-0.07f, -0.64f, -0.00001f)},
  657. {"期待", new Vector3(-0.04f, -0.20f, -0.00001f)},
  658. {"色咪咪", new Vector3(-0.03f, -0.09f, -0.00001f)},
  659. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  660. };
  661. #region 换装
  662. public Transform Shadow;
  663. private Transform Pivot
  664. {
  665. get
  666. {
  667. if (pivot == null)
  668. {
  669. pivot = UAC.transform.FindChild(PlayerLabel.Pivot);
  670. }
  671. return pivot;
  672. }
  673. }
  674. private Transform pivot;
  675. public string Eye;
  676. public string Top;
  677. public string Shoe;
  678. public string Head;
  679. public string Wing;
  680. public string Dress;
  681. public string Mouse;
  682. public string HeadWear;
  683. public string LeftLongSleeve;
  684. public string LeftShortSleeve;
  685. public string RightLongSleeve;
  686. public string RightShortSleeve;
  687. private string TempClose;
  688. public DragonBones.Slot NeckSlot;
  689. public DragonBones.Slot LeftHandSlot;
  690. public DragonBones.Slot RightHandSlot;
  691. public DragonBones.Slot LeftLegSlot;
  692. public DragonBones.Slot RightLegSlot;
  693. public DragonBones.Slot LeftShortSleeveSlot;
  694. public DragonBones.Slot RightShortSleeveSlot;
  695. public DragonBones.Slot EyeSlot;
  696. public DragonBones.Slot TopSlot;
  697. public DragonBones.Slot HeadSlot;
  698. public DragonBones.Slot DressSlot;
  699. public DragonBones.Slot WingSlot;
  700. public DragonBones.Slot MouseSlot;
  701. public DragonBones.Slot LeftShoeSlot;
  702. public DragonBones.Slot RightShoeSlot;
  703. public DragonBones.Slot HeadWearSlot;
  704. public UnityArmatureComponent UAC;
  705. public UnityArmatureComponent LeftLongSleeveUAC;
  706. public UnityArmatureComponent RightLongSleeveUAC;
  707. #endregion
  708. #endregion
  709. public override bool InitAtOnce()
  710. {
  711. if (base.InitAtOnce())
  712. {
  713. return true;
  714. }
  715. enabled = true;
  716. Auxiliary.CompileDic(transform, ChildDic);
  717. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  718. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  719. Shadow = ChildDic[PlayerLabel.Shadow];
  720. Shadow.CreateStreamScale
  721. (
  722. new List<float>() {0, 0, 0},
  723. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  724. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  725. true,
  726. true,
  727. Curve.EaseOutQuad
  728. );
  729. MeshFilter meshFilter = Shadow.GetComponent<MeshFilter>();
  730. meshFilter.mesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(ResourceLabel.FlowerShadow, Folder.Scene));
  731. meshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), meshFilter.mesh.vertices.Length).ToList());
  732. Shadow.GetComponent<MeshRenderer>().sharedMaterial = UnityFactory.Materials[0];
  733. ExpressionMeshFilter = ChildDic[PlayerLabel.ExpressionMeshFilter].GetComponent<MeshFilter>();
  734. ExpressionMeshFilter.GetComponent<MeshRenderer>().sharedMaterial = UnityFactory.Materials[0];
  735. return false;
  736. }
  737. public void Update()
  738. {
  739. if (InDressRoom)
  740. {
  741. JumpTimer += Time.deltaTime;
  742. if (JumpTimer > JumpTime)
  743. {
  744. if (!PlayAnimFlag1 && !PlayAnimFlag2)
  745. {
  746. PlayAnim(JumpAnimationName);
  747. }
  748. PlayAnimFlag2 = true;
  749. }
  750. if (JumpTimer > InDressRoomJumpFrequency)
  751. {
  752. PlayAnimFlag2 = false;
  753. JumpTime = Mathf.Lerp(0, InDressRoomJumpFrequency, Random.Range(0f, 1f));
  754. JumpTimer = 0;
  755. }
  756. }
  757. //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  758. //{
  759. // MoveThread();
  760. //}
  761. }
  762. public void OnAnimStart(string str, EventObject eventObject)
  763. {
  764. if (eventObject.animationState.name == JumpAnimationName)
  765. {
  766. Shadow.StreamReForScale();
  767. PlayAnimFlag1 = true;
  768. TempClose = Eye;
  769. ChangeClose(BodyPart.Eye, "眼睛表情1");
  770. }
  771. else if (eventObject.animationState.name == IdleAnimationName)
  772. {
  773. PlayAnimFlag1 = false;
  774. if (TempClose != null)
  775. {
  776. ChangeClose(BodyPart.Eye, TempClose);
  777. }
  778. }
  779. }
  780. public void PlayAnim(string animName)
  781. {
  782. if (PlayAnimFlag1)
  783. {
  784. return;
  785. }
  786. if (UAC.anim.lastAnimationName == animName)
  787. {
  788. return;
  789. }
  790. if (SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
  791. {
  792. CurrentAnimationName = animName;
  793. }
  794. UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
  795. }
  796. public float GetFadeInTime(string lastAnimation, string targetAnimation)
  797. {
  798. if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
  799. return -1f;
  800. else
  801. return 0.1f;
  802. //throw new Exception();
  803. }
  804. public void SetAllCollider(bool enable)
  805. {
  806. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  807. for (int i = 0; i < colliders.Length; i++)
  808. {
  809. colliders[i].enabled = enable;
  810. }
  811. }
  812. public void OnPointerClick(PointerEventData eventData)
  813. {
  814. AudioManager.PlayClip(AudioLabel.GetCurrent);
  815. PlayAnim(JumpAnimationName);
  816. }
  817. public void ResetExpression()
  818. {
  819. ExpressionMeshFilter.SetActive(false);
  820. EyeSlot.UnityTransform.GetChild(0).SetActive(true);
  821. MouseSlot.UnityTransform.GetChild(0).SetActive(true);
  822. }
  823. public void ChangeExpression(string expressionName, float duration)
  824. {
  825. ExpressionName = expressionName;
  826. ExpressionMeshFilter.sharedMesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(expressionName, Folder.Scene));
  827. ExpressionMeshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), ExpressionMeshFilter.mesh.vertices.Length).ToList());
  828. ExpressionMeshFilter.transform.parent = EyeSlot.UnityTransform;
  829. ExpressionMeshFilter.SetActive(true);
  830. EyeSlot.UnityTransform.GetChild(0).SetActive(false);
  831. MouseSlot.UnityTransform.GetChild(0).SetActive(false);
  832. FlipExpression(expressionName, PlayerDirection);
  833. if (ResetExpressionCoroutine != null)
  834. Auxiliary.Instance.StopCoroutine(ResetExpressionCoroutine);
  835. ResetExpressionCoroutine = Auxiliary.Instance.DelayCall
  836. (
  837. () =>
  838. {
  839. ResetExpression();
  840. },
  841. duration
  842. );
  843. }
  844. public void Flip(PlayerDirection direction)
  845. {
  846. FlipExpression(ExpressionName, direction);
  847. if (direction == PlayerDirection.Left)
  848. {
  849. UAC.armature.flipX = false;
  850. playerDirection = PlayerDirection.Left;
  851. }
  852. else if (direction == PlayerDirection.Right)
  853. {
  854. UAC.armature.flipX = true;
  855. playerDirection = PlayerDirection.Right;
  856. }
  857. else
  858. {
  859. throw new Exception();
  860. }
  861. DelayCall.Call(1, () => Shadow.SetX(Pivot.position.x));
  862. }
  863. public void FlipExpression(string expressionName, PlayerDirection direction)
  864. {
  865. if (string.IsNullOrEmpty(ExpressionName))
  866. {
  867. return;
  868. }
  869. if (direction == PlayerDirection.Left)
  870. {
  871. ExpressionMeshFilter.transform.eulerAngles = new Vector3();
  872. ExpressionMeshFilter.transform.localPosition = LeftExpressionPositionDictionary[ExpressionName];
  873. }
  874. else if (direction == PlayerDirection.Right)
  875. {
  876. UAC.armature.flipX = true;
  877. ExpressionMeshFilter.transform.eulerAngles = new Vector3(0, 180, 0);
  878. ExpressionMeshFilter.transform.localPosition = RightExpressionPositionDictionary[ExpressionName];
  879. playerDirection = PlayerDirection.Right;
  880. }
  881. else
  882. {
  883. throw new Exception();
  884. }
  885. }
  886. public void SaveDressDatas(bool showNavigate)
  887. {
  888. AudioManager.PlayClip(AudioLabel.ClickButton);
  889. List<CloseItem> closeUnitList = new List<CloseItem>();
  890. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Head]]);
  891. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Dress]]);
  892. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Shoe]]);
  893. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[HeadWear]]);
  894. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Top]]);
  895. if (Wing != "Empty")
  896. {
  897. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Wing]]);
  898. }
  899. for (int i = 0; i < closeUnitList.Count; i++)
  900. {
  901. if (!closeUnitList[i].IsBought)
  902. {
  903. if (showNavigate)
  904. {
  905. BuyDressNavigate(closeUnitList);
  906. }
  907. return;
  908. }
  909. }
  910. PlayerManager.DressDatas[0] = Head;
  911. PlayerManager.DressDatas[1] = Dress;
  912. PlayerManager.DressDatas[2] = Shoe;
  913. PlayerManager.DressDatas[3] = HeadWear;
  914. PlayerManager.DressDatas[4] = Top;
  915. PlayerManager.DressDatas[7] = Wing;
  916. PlayerManager.DressDatas[8] = LeftLongSleeve;
  917. PlayerManager.DressDatas[9] = LeftShortSleeve;
  918. PlayerManager.DressDatas[10] = RightLongSleeve;
  919. PlayerManager.DressDatas[11] = RightShortSleeve;
  920. Toast.Show(1.5f, Language.GetStr(LanguageLabel.UI__P_SaveSucceed));
  921. }
  922. public void ResetDressDatas()
  923. {
  924. AudioManager.PlayClip(AudioLabel.ClickButton);
  925. List<string> dressData = new List<string>(PlayerManager.DressDatas);
  926. dressData[5] = Eye;
  927. PlayerManager.BuildPlayer(dressData);
  928. }
  929. public List<int> GetCurrentChangableDressIDs()
  930. {
  931. List<int> ids = new List<int>();
  932. //if (PlayAnimFlag1) ids.Add(PlayerManager.CloseIDDictionary[TempClose]);
  933. //else ids.Add(PlayerManager.CloseIDDictionary[Eye]);
  934. ids.Add(PlayerManager.CloseIDDictionary[Top]);
  935. ids.Add(PlayerManager.CloseIDDictionary[Shoe]);
  936. ids.Add(PlayerManager.CloseIDDictionary[Head]);
  937. if (Wing != "Empty")
  938. {
  939. ids.Add(PlayerManager.CloseIDDictionary[Wing]);
  940. }
  941. ids.Add(PlayerManager.CloseIDDictionary[Dress]);
  942. //ids.Add(PlayerManager.CloseIDDictionary[Mouse]);
  943. ids.Add(PlayerManager.CloseIDDictionary[HeadWear]);
  944. //ids.Add(PlayerManager.CloseIDDictionary[LeftLongSleeve]);
  945. //ids.Add(PlayerManager.CloseIDDictionary[LeftShortSleeve]);
  946. //ids.Add(PlayerManager.CloseIDDictionary[RightLongSleeve]);
  947. //ids.Add(PlayerManager.CloseIDDictionary[RightShortSleeve]);
  948. return ids;
  949. }
  950. public void BuyDressNavigate(List<CloseItem> closeUnitList)
  951. {
  952. for (int i = 0; i < closeUnitList.Count; i++)
  953. {
  954. if (closeUnitList[i].IsBought)
  955. {
  956. closeUnitList.RemoveAt(i--);
  957. }
  958. else
  959. {
  960. closeUnitList[i].BuyBtn.onClick.Invoke();
  961. closeUnitList.RemoveAt(i--);
  962. ResourceManager.Get(CanvasLabel.Pa_Info).GetTweenCG().AddEventOnetime
  963. (
  964. EventType.BackwardFinish,
  965. () =>
  966. {
  967. if (closeUnitList.Count == 0)
  968. {
  969. SaveDressDatas(false);
  970. }
  971. else
  972. {
  973. BuyDressNavigate(closeUnitList);
  974. }
  975. }
  976. );
  977. return;
  978. }
  979. }
  980. }
  981. public void LeaveDressroom()
  982. {
  983. bool allSave = true;
  984. bool allBought = true;
  985. List<string> currentDerssData = new List<string>() { Head, Dress, Shoe, HeadWear, Top, Wing };
  986. for (int i = 0; i < currentDerssData.Count; i++)
  987. {
  988. if (!PlayerManager.CloseIDDictionary.ContainsKey(currentDerssData[i]))
  989. {
  990. continue;
  991. }
  992. int id = PlayerManager.CloseIDDictionary[currentDerssData[i]];
  993. allBought = allBought && PlayerManager.CloseItemDictionary[id].IsBought;
  994. //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
  995. allSave = allSave && currentDerssData[i] == PlayerManager.DressDatas[i];
  996. }
  997. if (allBought)
  998. {
  999. if (allSave)
  1000. {
  1001. ExitDressRoom();
  1002. }
  1003. else
  1004. {
  1005. ResetDressDatas();
  1006. ExitDressRoom();
  1007. }
  1008. }
  1009. else
  1010. {
  1011. Bubble.Show
  1012. (
  1013. null, Language.GetStr(LanguageLabel.UI__P_Return), null, null,
  1014. () =>
  1015. {
  1016. ResetDressDatas();
  1017. ResourceManager.Get(CanvasLabel.K_Bubble).GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  1018. }
  1019. );
  1020. }
  1021. }
  1022. public void ExitDressRoom()
  1023. {
  1024. Manager.SceneSwitchFlag = false;
  1025. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1026. tweenRoot.AddEventOnetime
  1027. (
  1028. EventType.BackwardFinish,
  1029. () =>
  1030. {
  1031. transform.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
  1032. transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  1033. transform.localScale = ResourceManager.Get(GardenLabel.GardenPlayerPos).lossyScale;
  1034. ResourceManager.Get(ResourceLabel.Garden).TweenForSr();
  1035. ResourceManager.Get(DressroomLabel.DressRoom).TweenBacSr();
  1036. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  1037. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenBacCG();
  1038. }
  1039. );
  1040. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1041. tweenRoot.AddEventOnetime
  1042. (
  1043. EventType.BackwardFinish,
  1044. () =>
  1045. {
  1046. SetAllCollider(true);
  1047. InDressRoom = false;
  1048. JumpTimer = 0;
  1049. PlayAnim(IdleAnimationName);
  1050. DeactiveShadow();
  1051. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenForCG();
  1052. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1053. }
  1054. );
  1055. }
  1056. public void EnterDressRoom()
  1057. {
  1058. if (Manager.SceneSwitchFlag)
  1059. {
  1060. return;
  1061. }
  1062. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenBacCG();
  1063. InDressRoom = true;
  1064. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  1065. Manager.SceneSwitchFlag = true;
  1066. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  1067. SetAllCollider(false);
  1068. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1069. tweenRoot.AddEventOnetime
  1070. (
  1071. EventType.BackwardFinish,
  1072. () =>
  1073. {
  1074. GardenManager.RetrieveAllElf();
  1075. IAPManager.RetrieveADChest();
  1076. ActiveShadow();
  1077. transform.SetParent(ResourceManager.Get(DressroomLabel.DressRoom));
  1078. transform.position = ResourceManager.Get(DressroomLabel.DressRoomPos).position;
  1079. transform.localScale = ResourceManager.Get(DressroomLabel.DressRoomPos).lossyScale;
  1080. ResourceManager.Get(ResourceLabel.Garden).TweenBacSr();
  1081. ResourceManager.Get(DressroomLabel.DressRoom).TweenForSr();
  1082. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenForCG();
  1083. }
  1084. );
  1085. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1086. tweenRoot.AddEventOnetime
  1087. (
  1088. EventType.ForwardFinish,
  1089. () =>
  1090. {
  1091. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1092. }
  1093. );
  1094. }
  1095. public void ActiveShadow()
  1096. {
  1097. ChildDic[PlayerLabel.ShadowParent].SetActive(true);
  1098. ChildDic[PlayerLabel.ShadowParent].SetLZ(3);
  1099. }
  1100. public void DeactiveShadow()
  1101. {
  1102. Shadow.GetStreamScale().Pause();
  1103. Shadow.GetStreamScale().InOrigin = true;
  1104. ChildDic[PlayerLabel.ShadowParent].SetActive(false);
  1105. }
  1106. #region 换装
  1107. public void CorrectPivot()
  1108. {
  1109. List<Transform> children = new List<Transform>();
  1110. while (transform.childCount > 0)
  1111. {
  1112. children.Add(transform.GetChild(0));
  1113. children.Back(0).parent = null;
  1114. }
  1115. Vector3 offset = Pivot.position - transform.position;
  1116. children[0].position += offset;
  1117. children[1].position += offset;
  1118. transform.position += offset;
  1119. foreach (var collider in GetComponents<BoxCollider2D>())
  1120. {
  1121. collider.offset -= new Vector2(offset.x, offset.y);
  1122. }
  1123. for (int i = 0; i < children.Count; i++)
  1124. {
  1125. children[i].parent = transform;
  1126. }
  1127. }
  1128. public UnityArmatureComponent Build()
  1129. {
  1130. if (!PlayerManager.Inited)
  1131. {
  1132. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  1133. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex, Folder.Config), ResourceLabel.StandTexture);
  1134. PlayerManager.Inited = true;
  1135. }
  1136. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  1137. UAC.transform.parent = transform;
  1138. UAC.transform.localScale = new Vector3(1, 1, 1);
  1139. UAC.transform.localPosition = new Vector3();
  1140. UAC.anim.Play(IdleAnimationName);
  1141. UAC.AddEventListener(EventObject.START, OnAnimStart);
  1142. Eye = "眼睛1";
  1143. Top = "上衣1";
  1144. Shoe = "鞋子1";
  1145. Head = "脑壳1";
  1146. Wing = "Empty";
  1147. Dress = "裙子1";
  1148. Mouse = "嘴巴1";
  1149. HeadWear = "头饰品1";
  1150. NeckSlot = UAC.armature.GetSlot("脖子");
  1151. LeftHandSlot = UAC.armature.GetSlot("左手");
  1152. RightHandSlot = UAC.armature.GetSlot("右手");
  1153. LeftLegSlot = UAC.armature.GetSlot("左腿");
  1154. RightLegSlot = UAC.armature.GetSlot("右腿");
  1155. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  1156. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  1157. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  1158. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  1159. EyeSlot = UAC.armature.GetSlot("眼睛");
  1160. TopSlot = UAC.armature.GetSlot("上衣");
  1161. HeadSlot = UAC.armature.GetSlot("脑壳");
  1162. WingSlot = UAC.armature.GetSlot("翅膀");
  1163. DressSlot = UAC.armature.GetSlot("裙子");
  1164. MouseSlot = UAC.armature.GetSlot("嘴巴");
  1165. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  1166. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  1167. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  1168. ChangeClose(BodyPart.Eye, "眼睛1", false);
  1169. ChangeClose(BodyPart.Top, "上衣1", false);
  1170. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  1171. ChangeClose(BodyPart.Head, "脑壳1", false);
  1172. ChangeClose(BodyPart.Dress, "裙子1", false);
  1173. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  1174. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  1175. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  1176. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  1177. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  1178. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  1179. CorrectPivot();
  1180. return UAC;
  1181. }
  1182. public UnityArmatureComponent BuildPink()
  1183. {
  1184. Build();
  1185. ChangeClose(BodyPart.Eye, "眼睛3", false);
  1186. ChangeClose(BodyPart.Top, "上衣3", false);
  1187. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  1188. ChangeClose(BodyPart.Head, "脑壳3", false);
  1189. ChangeClose(BodyPart.Wing, "Empty", false);
  1190. ChangeClose(BodyPart.Dress, "裙子3", false);
  1191. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  1192. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  1193. ResetDepth();
  1194. return UAC;
  1195. }
  1196. public UnityArmatureComponent BuildBlond()
  1197. {
  1198. Build();
  1199. ChangeClose(BodyPart.Wing, "Empty", false);
  1200. ResetDepth();
  1201. return UAC;
  1202. }
  1203. public UnityArmatureComponent BuildBrown()
  1204. {
  1205. Build();
  1206. ChangeClose(BodyPart.Eye, "眼睛2", false);
  1207. ChangeClose(BodyPart.Top, "上衣2", false);
  1208. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  1209. ChangeClose(BodyPart.Head, "脑壳2", false);
  1210. ChangeClose(BodyPart.Wing, "Empty", false);
  1211. ChangeClose(BodyPart.Dress, "裙子2", false);
  1212. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  1213. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  1214. ResetDepth();
  1215. return UAC;
  1216. }
  1217. public void ResetDepth()
  1218. {
  1219. UAC.transform.SetLZ(2.5f);
  1220. WingSlot.UnityTransform.SetLZ(0);
  1221. EyeSlot.UnityTransform.SetLZ(0);
  1222. TopSlot.UnityTransform.SetLZ(0);
  1223. MouseSlot.UnityTransform.SetLZ(0);
  1224. HeadWearSlot.UnityTransform.SetLZ(0);
  1225. LeftShoeSlot.UnityTransform.SetLZ(0);
  1226. RightShoeSlot.UnityTransform.SetLZ(0);
  1227. LeftLegSlot.UnityTransform.SetLZ(0);
  1228. RightLegSlot.UnityTransform.SetLZ(0);
  1229. NeckSlot.UnityTransform.SetLZ(0);
  1230. LeftHandSlot.UnityTransform.SetLZ(0);
  1231. RightHandSlot.UnityTransform.SetLZ(0);
  1232. LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  1233. RightShortSleeveSlot.UnityTransform.SetLZ(0);
  1234. WingSlot.SetLZ(0.00003f);
  1235. EyeSlot.SetLZ(-0.00001f);
  1236. TopSlot.SetLZ(-0.00003f);
  1237. MouseSlot.SetLZ(-0.00001f);
  1238. HeadWearSlot.SetLZ(-0.00001f);
  1239. HeadSlot.UnityTransform.SetLZ(0);
  1240. if (HeadSlot.UnityTransform.childCount > 1)
  1241. {
  1242. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1243. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1244. }
  1245. DressSlot.UnityTransform.SetLZ(-0.00002f);
  1246. if (DressSlot.UnityTransform.childCount > 1)
  1247. {
  1248. DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1249. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1250. }
  1251. LeftShoeSlot.SetLZ(-0.00001f);
  1252. RightShoeSlot.SetLZ(-0.00001f);
  1253. LeftLegSlot.SetLZ(0);
  1254. RightLegSlot.SetLZ(0);
  1255. NeckSlot.SetLZ(0.00001f);
  1256. LeftHandSlot.SetLZ(-0.00001f);
  1257. RightHandSlot.SetLZ(-0.00001f);
  1258. LeftShortSleeveSlot.SetLZ(-0.000015f);
  1259. RightShortSleeveSlot.SetLZ(-0.000015f);
  1260. LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1261. RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1262. }
  1263. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  1264. {
  1265. // Debug.Log (bodyPart + " " + armatureName);
  1266. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  1267. if (bodyPart == BodyPart.Eye)
  1268. {
  1269. Eye = armatureName;
  1270. slotList.Add(EyeSlot);
  1271. }
  1272. else if (bodyPart == BodyPart.Top)
  1273. {
  1274. Top = armatureName;
  1275. slotList.Add(TopSlot);
  1276. }
  1277. else if (bodyPart == BodyPart.Shoe)
  1278. {
  1279. Shoe = armatureName;
  1280. slotList.Add(LeftShoeSlot);
  1281. slotList.Add(RightShoeSlot);
  1282. }
  1283. else if (bodyPart == BodyPart.Head)
  1284. {
  1285. Head = armatureName;
  1286. slotList.Add(HeadSlot);
  1287. }
  1288. else if (bodyPart == BodyPart.Wing)
  1289. {
  1290. if (Wing == armatureName)
  1291. {
  1292. return;
  1293. }
  1294. else
  1295. {
  1296. Wing = armatureName;
  1297. slotList.Add(WingSlot);
  1298. }
  1299. }
  1300. else if (bodyPart == BodyPart.Dress)
  1301. {
  1302. Dress = armatureName;
  1303. slotList.Add(DressSlot);
  1304. }
  1305. else if (bodyPart == BodyPart.Mouse)
  1306. {
  1307. Mouse = armatureName;
  1308. slotList.Add(MouseSlot);
  1309. }
  1310. else if (bodyPart == BodyPart.Headwear)
  1311. {
  1312. HeadWear = armatureName;
  1313. slotList.Add(HeadWearSlot);
  1314. }
  1315. else if (bodyPart == BodyPart.Leg)
  1316. {
  1317. slotList.Add(LeftLegSlot);
  1318. slotList.Add(RightLegSlot);
  1319. }
  1320. else if (bodyPart == BodyPart.LeftHand)
  1321. {
  1322. slotList.Add(LeftHandSlot);
  1323. }
  1324. else if (bodyPart == BodyPart.RightHand)
  1325. {
  1326. slotList.Add(RightHandSlot);
  1327. }
  1328. else if (bodyPart == BodyPart.Neck)
  1329. {
  1330. slotList.Add(NeckSlot);
  1331. }
  1332. else if (bodyPart == BodyPart.LeftLongSleeve)
  1333. {
  1334. LeftLongSleeve = armatureName;
  1335. ChangeClose(LeftLongSleeveUAC, armatureName);
  1336. return;
  1337. }
  1338. else if (bodyPart == BodyPart.LeftShortSleeve)
  1339. {
  1340. LeftShortSleeve = armatureName;
  1341. slotList.Add(LeftShortSleeveSlot);
  1342. }
  1343. else if (bodyPart == BodyPart.RightLongSleeve)
  1344. {
  1345. RightLongSleeve = armatureName;
  1346. ChangeClose(RightLongSleeveUAC, armatureName);
  1347. return;
  1348. }
  1349. else if (bodyPart == BodyPart.RightShortSleeve)
  1350. {
  1351. RightShortSleeve = armatureName;
  1352. slotList.Add(RightShortSleeveSlot);
  1353. }
  1354. else
  1355. {
  1356. throw new Exception();
  1357. }
  1358. ChangeClose(slotList, armatureName, setDepth);
  1359. if (bodyPart == BodyPart.Wing)
  1360. {
  1361. 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);
  1362. tweenRoot.PingPong = true;
  1363. tweenRoot.StartForward();
  1364. }
  1365. }
  1366. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1367. {
  1368. for (int i = 0; i < slotList.Count; i++)
  1369. {
  1370. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1371. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1372. }
  1373. if (setDepth)
  1374. {
  1375. ResetDepth();
  1376. }
  1377. }
  1378. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1379. {
  1380. if (armatureName == "Empty")
  1381. {
  1382. uac.SetActive(false);
  1383. }
  1384. else
  1385. {
  1386. uac.SetActive(true);
  1387. }
  1388. if (setDepth)
  1389. {
  1390. ResetDepth();
  1391. }
  1392. }
  1393. #endregion
  1394. }