Player.cs 49 KB

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