Player.cs 56 KB

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