Player.cs 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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 enum BodyPart
  15. {
  16. Leg = 0,
  17. LeftHand = 1,
  18. RightHand = 2,
  19. LeftLongSleeve = 3,
  20. LeftShortSleeve = 4,
  21. RightLongSleeve = 5,
  22. RightShortSleeve = 6,
  23. Neck = 7,
  24. Eye = 8,
  25. Top = 9,
  26. Shoe = 10,
  27. Head = 11,
  28. Wing = 12,
  29. Dress = 13,
  30. Mouse = 14,
  31. Headwear = 15,
  32. }
  33. public class CloseUnit
  34. {
  35. public enum CloseType
  36. {
  37. Top,
  38. Hair,
  39. Wing,
  40. Dress,
  41. Decarator,
  42. Shoe,
  43. }
  44. #region Var
  45. public string Name
  46. {
  47. get { return Language.GetStr("DressRoom", "Armature" + ID); }
  48. }
  49. public int ID;
  50. public int Index;
  51. public int BuyLevel;
  52. public int PixelSize;
  53. public bool Bought;
  54. public string ArmatureName;
  55. public string[] ExtraArmatureNames;
  56. public BodyPart[] ExtraBodyParts;
  57. public float SpriteAlpha;
  58. public float IconOffset;
  59. public Text BuyBtnLab;
  60. public Sprite[] Sprites;
  61. public Image Icon1;
  62. public Image Icon2;
  63. public Image Icon3;
  64. public Button BuyBtn;
  65. public Button DressBtn;
  66. public Vector2 IconOffset1;
  67. public Vector2 IconOffset2;
  68. public BodyPart BodyPart;
  69. public Transform Transform;
  70. public CloseType Type;
  71. public bool Ignore;
  72. public double BuyAmt;
  73. public double BuyAdvanceAmt;
  74. public Current BuyCurrent;
  75. public Current BuyAdvanceCurrent;
  76. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  77. #endregion
  78. public CloseUnit(XmlAttributeCollection attribute)
  79. {
  80. Ignore = Auxiliary.BoolParse(attribute[19].Value, false);
  81. ID = Auxiliary.IntParse(attribute[0].Value, -1);
  82. BodyPart = BodyPartParse(attribute[4].Value);
  83. ArmatureName = attribute[16].Value;
  84. ManaPlayer.CloseIDDic.Add(ArmatureName, ID);
  85. ManaPlayer.CloseUnitDic.Add(ID, this);
  86. if (Ignore)
  87. {
  88. return;
  89. }
  90. Type = TypeParse(attribute[2].Value);
  91. Index = Auxiliary.IntParse(attribute[3].Value, -1);
  92. BuyLevel = Auxiliary.IntParse(attribute[5].Value, 0);
  93. BuyCurrent = Auxiliary.CurrentParse(attribute[6].Value);
  94. BuyAmt = Auxiliary.DoubleParse(attribute[7].Value, 0);
  95. BuyAdvanceCurrent = Auxiliary.CurrentParse(attribute[8].Value);
  96. BuyAdvanceAmt = Auxiliary.DoubleParse(attribute[9].Value, 0);
  97. PixelSize = Auxiliary.IntParse(attribute[10].Value, 100);
  98. IconOffset = Auxiliary.FloatParse(attribute[11].Value, 0);
  99. IconOffset1 = Auxiliary.VectorParse(',', attribute[12].Value, new Vector3());
  100. IconOffset2 = Auxiliary.VectorParse(',', attribute[13].Value, new Vector3());
  101. Sprites = SpriteParse(attribute[14].Value);
  102. SpriteAlpha = Auxiliary.FloatParse(attribute[15].Value, 1);
  103. ExtraBodyParts = BodyPartParses(attribute[17].Value);
  104. ExtraArmatureNames = Auxiliary.StringListParse(',', attribute[18].Value, new List<string>()).ToArray();
  105. CreateItem();
  106. }
  107. protected void CreateItem()
  108. {
  109. Transform = ManaReso.Get("CloseItem", Folder.UI, false, ManaReso.Get("Canvas"), false);
  110. if (Type == CloseType.Top)
  111. {
  112. Transform.SetParent(ManaReso.Get("Pb_TopGrid"));
  113. }
  114. else if (Type == CloseType.Hair)
  115. {
  116. Transform.SetParent(ManaReso.Get("Pa_HairGrid"));
  117. }
  118. else if (Type == CloseType.Dress)
  119. {
  120. Transform.SetParent(ManaReso.Get("Pc_DressGrid"));
  121. }
  122. else if (Type == CloseType.Wing)
  123. {
  124. Transform.SetParent(ManaReso.Get("Pe_WingGrid"));
  125. }
  126. else if (Type == CloseType.Decarator)
  127. {
  128. Transform.SetParent(ManaReso.Get("Pd_DecaratorGrid"));
  129. }
  130. else if (Type == CloseType.Shoe)
  131. {
  132. Transform.SetParent(ManaReso.Get("Pf_ShoeGrid"));
  133. }
  134. else
  135. {
  136. throw new Exception();
  137. }
  138. Transform.SetSiblingIndex(Index);
  139. Auxiliary.CompileDic(Transform, ChildDic);
  140. Icon1 = ChildDic["Icon1"].GetComponent<Image>();
  141. Icon2 = ChildDic["Icon2"].GetComponent<Image>();
  142. Icon3 = ChildDic["Icon3"].GetComponent<Image>();
  143. DressBtn = ChildDic["CloseItem"].GetComponent<Button>();
  144. BuyBtn = ChildDic["BuyBtn"].GetComponent<Button>();
  145. BuyBtnLab = ChildDic["BuyBtnLab"].GetComponent<Text>();
  146. BuyBtnLab.GetComponent<TextPlus>().SetY = true;
  147. float newSize = PixelSize / Sprites[0].rect.width;
  148. SetUpUI(newSize, new Vector2(), Icon1, Icon2, Icon3);
  149. if (BuyCurrent != Current.Free)
  150. {
  151. BuyBtnLab.text = Auxiliary.ImageParse(BuyCurrent) + Auxiliary.ShrinkNumberStr(BuyAmt);
  152. }
  153. if (BuyLevel > ManaCenter.Level)
  154. {
  155. BuyBtn.interactable = false;
  156. BuyBtn.image.material = Lib.GrayMat;
  157. }
  158. BuyBtn.onClick.AddListener
  159. (
  160. () =>
  161. {
  162. ManaAudio.PlayClip(Clip.BtnClip);
  163. ManaReso.Get("Pa_Info").TweenForCG();
  164. SetUpUI(newSize, new Vector2(0, 22), ManaReso.Get<Image>("Pa_Icon1"), ManaReso.Get<Image>("Pa_Icon3"), ManaReso.Get<Image>("Pa_Icon2"));
  165. ManaReso.SetText("Pa_Lab", Name);
  166. ManaReso.SetText("Pa_BtnLab", Language.GetStr("UI", "Pa_BtnLab") + Auxiliary.ImageParse(BuyCurrent) + BuyAmt);
  167. ManaReso.SetButtonEvent
  168. (
  169. "Pa_Btn",
  170. OnBuy
  171. );
  172. }
  173. );
  174. DressBtn.onClick.AddListener
  175. (
  176. () =>
  177. {
  178. ManaAudio.PlayClip(Clip.BtnClip);
  179. if (BuyLevel > ManaCenter.Level)
  180. {
  181. Bubble.Show(null, Language.GetStr("UI", "P_Unlock"));
  182. return;
  183. }
  184. ChangeDress(ManaPlayer.Player);
  185. }
  186. );
  187. }
  188. protected Sprite[] SpriteParse(string str)
  189. {
  190. string[] spriteNames = str.Split(',');
  191. Sprite[] sprites = new Sprite[spriteNames.Length];
  192. for (int i = 0; i < spriteNames.Length; i++)
  193. {
  194. if (!ManaPlayer.CloseSpriteDic.ContainsKey(spriteNames[i]))
  195. {
  196. Debug.Log(spriteNames[i]);
  197. }
  198. sprites[i] = ManaPlayer.CloseSpriteDic[spriteNames[i]];
  199. }
  200. return sprites;
  201. }
  202. protected BodyPart BodyPartParse(string str)
  203. {
  204. int type = Auxiliary.IntParse(str, -1);
  205. if (type == 1)
  206. {
  207. return BodyPart.Head;
  208. }
  209. else if (type == 2)
  210. {
  211. return BodyPart.Dress;
  212. }
  213. else if (type == 3)
  214. {
  215. return BodyPart.Shoe;
  216. }
  217. else if (type == 4)
  218. {
  219. return BodyPart.Headwear;
  220. }
  221. else if (type == 5)
  222. {
  223. return BodyPart.Top;
  224. }
  225. else if (type == 6)
  226. {
  227. return BodyPart.Wing;
  228. }
  229. else if (type == 7)
  230. {
  231. return BodyPart.LeftLongSleeve;
  232. }
  233. else if (type == 8)
  234. {
  235. return BodyPart.RightLongSleeve;
  236. }
  237. else if (type == 9)
  238. {
  239. return BodyPart.LeftShortSleeve;
  240. }
  241. else if (type == 10)
  242. {
  243. return BodyPart.RightShortSleeve;
  244. }
  245. else if (type == 11)
  246. {
  247. return BodyPart.Eye;
  248. }
  249. else if (type == 12)
  250. {
  251. return BodyPart.Mouse;
  252. }
  253. else
  254. {
  255. throw new Exception();
  256. }
  257. }
  258. protected BodyPart[] BodyPartParses(string str)
  259. {
  260. List<string> typeIDs = Auxiliary.StringListParse(',', str, new List<string>());
  261. BodyPart[] bodyParts = new BodyPart[typeIDs.Count];
  262. for (int i = 0; i < typeIDs.Count; i++)
  263. {
  264. bodyParts[i] = BodyPartParse(typeIDs[i]);
  265. }
  266. return bodyParts;
  267. }
  268. protected CloseType TypeParse(string str)
  269. {
  270. int type = Auxiliary.IntParse(str, -1);
  271. if (type == 1)
  272. {
  273. return CloseType.Hair;
  274. }
  275. else if (type == 2)
  276. {
  277. return CloseType.Top;
  278. }
  279. else if (type == 3)
  280. {
  281. return CloseType.Dress;
  282. }
  283. else if (type == 4)
  284. {
  285. return CloseType.Decarator;
  286. }
  287. else if (type == 5)
  288. {
  289. return CloseType.Wing;
  290. }
  291. else if (type == 6)
  292. {
  293. return CloseType.Shoe;
  294. }
  295. else
  296. {
  297. throw new Exception();
  298. }
  299. }
  300. public void SetUpUI(float newSize, Vector2 offset, Image icon1, Image icon2, Image icon3)
  301. {
  302. icon1.SetActive(false);
  303. icon3.SetActive(false);
  304. icon2.SetActive(true);
  305. icon2.sprite = Sprites[0];
  306. icon2.Resize(true, new Vector2(newSize, newSize));
  307. icon2.SetAlpha(SpriteAlpha);
  308. icon2.transform.localPosition = offset + new Vector2(0, IconOffset);
  309. if (Sprites.Length >= 2)
  310. {
  311. icon1.SetActive(true);
  312. icon1.sprite = Sprites[1];
  313. icon1.Resize(true, new Vector2(newSize, newSize));
  314. icon1.SetAlpha(SpriteAlpha);
  315. icon1.transform.localPosition = IconOffset1 * newSize + offset + new Vector2(0, IconOffset);
  316. }
  317. if (Sprites.Length >= 3)
  318. {
  319. icon3.SetActive(true);
  320. icon3.sprite = Sprites[2];
  321. icon3.Resize(true, new Vector2(newSize, newSize));
  322. icon3.SetAlpha(SpriteAlpha);
  323. icon3.transform.localPosition = IconOffset2 * newSize + offset + new Vector2(0, IconOffset);
  324. }
  325. }
  326. public void Unlock()
  327. {
  328. if (Ignore)
  329. {
  330. return;
  331. }
  332. Bought = true;
  333. BuyBtn.interactable = false;
  334. BuyBtn.image.material = Lib.GrayMat;
  335. BuyBtnLab.text = Language.GetStr("UI", "P_BtnLab2");
  336. ManaCenter.CloseAmt++;
  337. }
  338. public void OnBuy()
  339. {
  340. ManaCenter.Pay
  341. (
  342. "",
  343. BuyAmt,
  344. BuyCurrent,
  345. () =>
  346. {
  347. Unlock();
  348. ManaAudio.PlayClip(Clip.CurrentClip);
  349. ManaPlayer.BoughtCloseList.UniqueAdd(ID);
  350. ManaReso.Get("Pa_Info").TweenBacCG();
  351. ManaServer.Save();
  352. },
  353. StaticsManager.ItemID.解锁服装,
  354. StaticsManager.ConsumeModule.Shop,
  355. true,
  356. false,
  357. () =>
  358. {
  359. ManaPlayer.Player.Reset();
  360. TweenRoot tweenRoot = ManaReso.Get("Pa_Info").TweenBacCG();
  361. tweenRoot.AddEventOnetime
  362. (
  363. EventType.BackwardFinish,
  364. () =>
  365. {
  366. ManaPlayer.Player.Return();
  367. }
  368. );
  369. ManaReso.Get("B_SignIn0").GetTweenCG().AddEventOnetime
  370. (
  371. EventType.ForwardFinish,
  372. () =>
  373. {
  374. ManaReso.Get("F_Manage0").TweenForVec();
  375. }
  376. );
  377. }
  378. );
  379. }
  380. public void ChangeDress(Player player)
  381. {
  382. player.ChangeClose(BodyPart, ArmatureName);
  383. if (Ignore)
  384. {
  385. return;
  386. }
  387. if (ExtraBodyParts.Length > 0)
  388. {
  389. player.ChangeClose(BodyPart.LeftLongSleeve, "Empty");
  390. player.ChangeClose(BodyPart.LeftShortSleeve, "Empty");
  391. player.ChangeClose(BodyPart.RightLongSleeve, "Empty");
  392. player.ChangeClose(BodyPart.RightShortSleeve, "Empty");
  393. }
  394. for (int i = 0; i < ExtraArmatureNames.Length; i++)
  395. {
  396. player.ChangeClose(ExtraBodyParts[i], ExtraArmatureNames[i]);
  397. }
  398. }
  399. public void OnLevelChange()
  400. {
  401. if (Ignore)
  402. {
  403. return;
  404. }
  405. if (Bought)
  406. {
  407. return;
  408. }
  409. if (BuyLevel < ManaCenter.Level)
  410. {
  411. BuyBtn.interactable = true;
  412. BuyBtn.image.material = null;
  413. }
  414. }
  415. }
  416. public enum PlayerDirection
  417. {
  418. Left = 0,
  419. Right = 1,
  420. }
  421. public class Player : Regist , IPointerClickHandler
  422. {
  423. #region 变量
  424. public static string IdleAnimationName = "newAnimation";
  425. public static string JumpAnimationName = "newAnimation1";
  426. public static string WalkAnimationName = "newAnimation2";
  427. public static string RunAnimationName = "newAnimation3";
  428. public static bool InDressRoom;
  429. public static float JumpFrequency;
  430. public PlayerDirection PlayerDirection
  431. {
  432. get { return playerDirection; }
  433. set
  434. {
  435. playerDirection = value;
  436. Flip(playerDirection);
  437. }
  438. }
  439. private PlayerDirection playerDirection = PlayerDirection.Left;
  440. public bool AnimLock1;
  441. public bool AnimLock2;
  442. public float JumpTime;
  443. public float JumpTimer;
  444. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  445. #region 换装
  446. public string Eye;
  447. public string Top;
  448. public string Shoe;
  449. public string Head;
  450. public string Wing;
  451. public string Dress;
  452. public string Mouse;
  453. public string HeadWear;
  454. public string LeftLongSleeve;
  455. public string LeftShortSleeve;
  456. public string RightLongSleeve;
  457. public string RightShortSleeve;
  458. private string TempClose;
  459. public DragonBones.Slot NeckSlot;
  460. public DragonBones.Slot LeftHandSlot;
  461. public DragonBones.Slot RightHandSlot;
  462. public DragonBones.Slot LeftLegSlot;
  463. public DragonBones.Slot RightLegSlot;
  464. public DragonBones.Slot LeftShortSleeveSlot;
  465. public DragonBones.Slot RightShortSleeveSlot;
  466. public DragonBones.Slot EyeSlot;
  467. public DragonBones.Slot TopSlot;
  468. public DragonBones.Slot HeadSlot;
  469. public DragonBones.Slot DressSlot;
  470. public DragonBones.Slot WingSlot;
  471. public DragonBones.Slot MouseSlot;
  472. public DragonBones.Slot LeftShoeSlot;
  473. public DragonBones.Slot RightShoeSlot;
  474. public DragonBones.Slot HeadWearSlot;
  475. public UnityArmatureComponent UAC;
  476. public UnityArmatureComponent LeftLongSleeveUAC;
  477. public UnityArmatureComponent RightLongSleeveUAC;
  478. #endregion
  479. #endregion
  480. public override bool RegistImmed()
  481. {
  482. if (base.RegistImmed())
  483. {
  484. return true;
  485. }
  486. enabled = true;
  487. Auxiliary.CompileDic(transform, ChildDic);
  488. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  489. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  490. ChildDic["Shadow"].CreateStreamScale
  491. (
  492. new List<float>() {0, 0, 0},
  493. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  494. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  495. true,
  496. true,
  497. Curve.EaseOutQuad
  498. );
  499. return false;
  500. }
  501. public void Update()
  502. {
  503. if (InDressRoom)
  504. {
  505. JumpTimer += Time.deltaTime;
  506. if (JumpTimer > JumpTime)
  507. {
  508. if (!AnimLock1 && !AnimLock2)
  509. {
  510. PlayAnim(JumpAnimationName);
  511. }
  512. AnimLock2 = true;
  513. }
  514. if (JumpTimer > JumpFrequency)
  515. {
  516. AnimLock2 = false;
  517. JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0f, 1f));
  518. JumpTimer = 0;
  519. }
  520. }
  521. //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  522. //{
  523. // MoveThread();
  524. //}
  525. }
  526. public void OnStart(string str, EventObject eventObject)
  527. {
  528. if (eventObject.animationState.name == JumpAnimationName)
  529. {
  530. ChildDic["Shadow"].StreamReForScale();
  531. AnimLock1 = true;
  532. TempClose = Eye;
  533. ChangeClose(BodyPart.Eye, "眼睛表情1");
  534. }
  535. else if (eventObject.animationState.name == IdleAnimationName)
  536. {
  537. AnimLock1 = false;
  538. if (TempClose != null)
  539. {
  540. ChangeClose(BodyPart.Eye, TempClose);
  541. }
  542. }
  543. }
  544. public string CurrentAnimationName;
  545. public void PlayAnim(string animName)
  546. {
  547. if (AnimLock1)
  548. {
  549. return;
  550. }
  551. if (UAC.anim.lastAnimationName == animName)
  552. {
  553. return;
  554. }
  555. if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  556. {
  557. CurrentAnimationName = animName;
  558. }
  559. UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
  560. }
  561. public float GetFadeInTime(string lastAnimation, string targetAnimation)
  562. {
  563. if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
  564. return -1f;
  565. else
  566. return 0.1f;
  567. //throw new Exception();
  568. }
  569. public void SetAllCollider(bool enable)
  570. {
  571. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  572. for (int i = 0; i < colliders.Length; i++)
  573. {
  574. colliders[i].enabled = enable;
  575. }
  576. }
  577. public void OnPointerClick(PointerEventData eventData)
  578. {
  579. ManaAudio.PlayClip(Clip.CurrentClip);
  580. ManaNickName.ShowNickNameSettingPanel();
  581. PlayAnim(JumpAnimationName);
  582. }
  583. public void Flip(PlayerDirection direction)
  584. {
  585. if (direction == PlayerDirection.Left)
  586. {
  587. UAC.armature.flipX = false;
  588. playerDirection = PlayerDirection.Left;
  589. }
  590. else
  591. {
  592. UAC.armature.flipX = true;
  593. playerDirection = PlayerDirection.Right;
  594. }
  595. }
  596. public void Save(bool showNavigate)
  597. {
  598. ManaAudio.PlayClip(Clip.BtnClip);
  599. List<CloseUnit> closeUnitList = new List<CloseUnit>();
  600. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Head]]);
  601. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Dress]]);
  602. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Shoe]]);
  603. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[HeadWear]]);
  604. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Top]]);
  605. if (Wing != "Empty")
  606. {
  607. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Wing]]);
  608. }
  609. for (int i = 0; i < closeUnitList.Count; i++)
  610. {
  611. if (!closeUnitList[i].Bought)
  612. {
  613. if (showNavigate)
  614. {
  615. BuyNavigate(closeUnitList);
  616. }
  617. return;
  618. }
  619. }
  620. ManaPlayer.DressData[0] = Head;
  621. ManaPlayer.DressData[1] = Dress;
  622. ManaPlayer.DressData[2] = Shoe;
  623. ManaPlayer.DressData[3] = HeadWear;
  624. ManaPlayer.DressData[4] = Top;
  625. ManaPlayer.DressData[7] = Wing;
  626. ManaPlayer.DressData[8] = LeftLongSleeve;
  627. ManaPlayer.DressData[9] = LeftShortSleeve;
  628. ManaPlayer.DressData[10] = RightLongSleeve;
  629. ManaPlayer.DressData[11] = RightShortSleeve;
  630. //GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.SyncClose();
  631. }
  632. public void Reset()
  633. {
  634. ManaAudio.PlayClip(Clip.BtnClip);
  635. List<string> dressData = new List<string>(ManaPlayer.DressData);
  636. dressData[5] = Eye;
  637. ManaPlayer.BuildPlayer(dressData);
  638. }
  639. public void Return()
  640. {
  641. bool allSave = true;
  642. bool allBought = true;
  643. List<string> currentDerssData = new List<string>() {Head, Dress, Shoe, HeadWear, Top, Wing};
  644. for (int i = 0; i < currentDerssData.Count; i++)
  645. {
  646. if (!ManaPlayer.CloseIDDic.ContainsKey(currentDerssData[i]))
  647. {
  648. continue;
  649. }
  650. int id = ManaPlayer.CloseIDDic[currentDerssData[i]];
  651. allBought = allBought && ManaPlayer.CloseUnitDic[id].Bought;
  652. //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
  653. allSave = allSave && currentDerssData[i] == ManaPlayer.DressData[i];
  654. }
  655. if (allBought)
  656. {
  657. if (allSave)
  658. {
  659. ExitDressRoom();
  660. }
  661. else
  662. {
  663. Reset();
  664. ExitDressRoom();
  665. }
  666. }
  667. else
  668. {
  669. Bubble.Show
  670. (
  671. null, Language.GetStr("UI", "P_Return"), null, null,
  672. () =>
  673. {
  674. Reset();
  675. ManaReso.Get("K_Bubble").GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  676. }
  677. );
  678. }
  679. }
  680. public void BuyNavigate(List<CloseUnit> closeUnitList)
  681. {
  682. for (int i = 0; i < closeUnitList.Count; i++)
  683. {
  684. if (closeUnitList[i].Bought)
  685. {
  686. closeUnitList.RemoveAt(i--);
  687. }
  688. else
  689. {
  690. closeUnitList[i].BuyBtn.onClick.Invoke();
  691. closeUnitList.RemoveAt(i--);
  692. ManaReso.Get("Pa_Info").GetTweenCG().AddEventOnetime
  693. (
  694. EventType.BackwardFinish,
  695. () =>
  696. {
  697. if (closeUnitList.Count == 0)
  698. {
  699. Save(false);
  700. }
  701. else
  702. {
  703. BuyNavigate(closeUnitList);
  704. }
  705. }
  706. );
  707. return;
  708. }
  709. }
  710. }
  711. public void ExitDressRoom()
  712. {
  713. ManaCenter.SceneSwitchLock = false;
  714. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  715. tweenRoot.AddEventOnetime
  716. (
  717. EventType.BackwardFinish,
  718. () =>
  719. {
  720. transform.SetParent(ManaReso.Get("GardenNormal"));
  721. transform.position = ManaReso.Get("PlayerPosTra").position;
  722. transform.localScale = ManaReso.Get("PlayerPosTra").lossyScale;
  723. ManaReso.Get("Garden").TweenForSr();
  724. ManaReso.Get("DressRoom").TweenBacSr();
  725. ManaReso.Get("C_Main").TweenForCG();
  726. ManaReso.Get("P_DressRoom").TweenBacCG();
  727. }
  728. );
  729. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  730. tweenRoot.AddEventOnetime
  731. (
  732. EventType.BackwardFinish,
  733. () =>
  734. {
  735. SetAllCollider(true);
  736. InDressRoom = false;
  737. JumpTimer = 0;
  738. PlayAnim(IdleAnimationName);
  739. ChildDic["Shadow"].GetStreamScale().Pause();
  740. ChildDic["Shadow"].GetStreamScale().InOrigin = true;
  741. ChildDic["ShadowParent"].SetActive(false);
  742. ManaReso.Get("B_SignIn0").TweenForCG();
  743. ManaReso.Get("I_BlackMask").TweenForCG();
  744. }
  745. );
  746. }
  747. public void EnterDressRoom()
  748. {
  749. if (ManaCenter.SceneSwitchLock)
  750. {
  751. return;
  752. }
  753. ManaReso.Get("B_SignIn0").TweenBacCG();
  754. InDressRoom = true;
  755. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  756. ManaCenter.SceneSwitchLock = true;
  757. ManaReso.Get("C_Main").TweenBacCG();
  758. SetAllCollider(false);
  759. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  760. tweenRoot.AddEventOnetime
  761. (
  762. EventType.BackwardFinish,
  763. () =>
  764. {
  765. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  766. {
  767. ManaGarden.PlantList[i].Flower.RetrieveElf();
  768. }
  769. ChildDic["ShadowParent"].SetActive(true);
  770. ChildDic["ShadowParent"].SetLZ(3);
  771. transform.SetParent(ManaReso.Get("DressRoom"));
  772. transform.position = ManaReso.Get("DressRoomPos").position;
  773. transform.localScale = ManaReso.Get("DressRoomPos").lossyScale;
  774. ManaReso.Get("Garden").TweenBacSr();
  775. ManaReso.Get("DressRoom").TweenForSr();
  776. ManaReso.Get("P_DressRoom").TweenForCG();
  777. }
  778. );
  779. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  780. tweenRoot.AddEventOnetime
  781. (
  782. EventType.ForwardFinish,
  783. () =>
  784. {
  785. ManaReso.Get("I_BlackMask").TweenForCG();
  786. }
  787. );
  788. }
  789. #region 换装
  790. public void CorrectPivot()
  791. {
  792. List<Transform> children = new List<Transform>();
  793. while (transform.childCount > 0)
  794. {
  795. children.Add(transform.GetChild(0));
  796. children.Back(0).parent = null;
  797. }
  798. Vector3 offset = UAC.transform.FindChild("Pivot").position - transform.position;
  799. children[0].position += offset;
  800. children[1].position += offset;
  801. transform.position += offset;
  802. for (int i = 0; i < children.Count; i++)
  803. {
  804. children[i].parent = transform;
  805. }
  806. }
  807. public UnityArmatureComponent Build()
  808. {
  809. if (!ManaPlayer.Complete)
  810. {
  811. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  812. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  813. ManaPlayer.Complete = true;
  814. }
  815. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  816. UAC.transform.parent = transform;
  817. UAC.transform.localScale = new Vector3(1, 1, 1);
  818. UAC.transform.localPosition = new Vector3();
  819. UAC.anim.Play(IdleAnimationName);
  820. UAC.AddEventListener(EventObject.START, OnStart);
  821. Eye = "眼睛1";
  822. Top = "上衣1";
  823. Shoe = "鞋子1";
  824. Head = "脑壳1";
  825. Wing = "Empty";
  826. Dress = "裙子1";
  827. Mouse = "嘴巴1";
  828. HeadWear = "头饰品1";
  829. NeckSlot = UAC.armature.GetSlot("脖子");
  830. LeftHandSlot = UAC.armature.GetSlot("左手");
  831. RightHandSlot = UAC.armature.GetSlot("右手");
  832. LeftLegSlot = UAC.armature.GetSlot("左腿");
  833. RightLegSlot = UAC.armature.GetSlot("右腿");
  834. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  835. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  836. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  837. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  838. EyeSlot = UAC.armature.GetSlot("眼睛");
  839. TopSlot = UAC.armature.GetSlot("上衣");
  840. HeadSlot = UAC.armature.GetSlot("脑壳");
  841. WingSlot = UAC.armature.GetSlot("翅膀");
  842. DressSlot = UAC.armature.GetSlot("裙子");
  843. MouseSlot = UAC.armature.GetSlot("嘴巴");
  844. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  845. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  846. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  847. ChangeClose(BodyPart.Eye, "眼睛1", false);
  848. ChangeClose(BodyPart.Top, "上衣1", false);
  849. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  850. ChangeClose(BodyPart.Head, "脑壳1", false);
  851. ChangeClose(BodyPart.Dress, "裙子1", false);
  852. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  853. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  854. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  855. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  856. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  857. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  858. CorrectPivot();
  859. return UAC;
  860. }
  861. public UnityArmatureComponent BuildPink()
  862. {
  863. Build();
  864. ChangeClose(BodyPart.Eye, "眼睛3", false);
  865. ChangeClose(BodyPart.Top, "上衣3", false);
  866. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  867. ChangeClose(BodyPart.Head, "脑壳3", false);
  868. ChangeClose(BodyPart.Wing, "Empty", false);
  869. ChangeClose(BodyPart.Dress, "裙子3", false);
  870. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  871. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  872. ResetDepth();
  873. return UAC;
  874. }
  875. public UnityArmatureComponent BuildBlond()
  876. {
  877. Build();
  878. ChangeClose(BodyPart.Wing, "Empty", false);
  879. ResetDepth();
  880. return UAC;
  881. }
  882. public UnityArmatureComponent BuildBrown()
  883. {
  884. Build();
  885. ChangeClose(BodyPart.Eye, "眼睛2", false);
  886. ChangeClose(BodyPart.Top, "上衣2", false);
  887. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  888. ChangeClose(BodyPart.Head, "脑壳2", false);
  889. ChangeClose(BodyPart.Wing, "Empty", false);
  890. ChangeClose(BodyPart.Dress, "裙子2", false);
  891. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  892. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  893. ResetDepth();
  894. return UAC;
  895. }
  896. public void ResetDepth()
  897. {
  898. UAC.transform.SetLZ(2.5f);
  899. WingSlot.UnityTransform.SetLZ(0);
  900. EyeSlot.UnityTransform.SetLZ(0);
  901. TopSlot.UnityTransform.SetLZ(0);
  902. MouseSlot.UnityTransform.SetLZ(0);
  903. HeadWearSlot.UnityTransform.SetLZ(0);
  904. LeftShoeSlot.UnityTransform.SetLZ(0);
  905. RightShoeSlot.UnityTransform.SetLZ(0);
  906. LeftLegSlot.UnityTransform.SetLZ(0);
  907. RightLegSlot.UnityTransform.SetLZ(0);
  908. NeckSlot.UnityTransform.SetLZ(0);
  909. LeftHandSlot.UnityTransform.SetLZ(0);
  910. RightHandSlot.UnityTransform.SetLZ(0);
  911. LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  912. RightShortSleeveSlot.UnityTransform.SetLZ(0);
  913. WingSlot.SetLZ(0.003f);
  914. EyeSlot.SetLZ(-0.001f);
  915. TopSlot.SetLZ(-0.003f);
  916. MouseSlot.SetLZ(-0.001f);
  917. HeadWearSlot.SetLZ(-0.001f);
  918. HeadSlot.UnityTransform.SetLZ(0);
  919. if (HeadSlot.UnityTransform.childCount > 1)
  920. {
  921. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.002f);
  922. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  923. }
  924. DressSlot.UnityTransform.SetLZ(-0.002f);
  925. if (DressSlot.UnityTransform.childCount > 1)
  926. {
  927. DressSlot.UnityTransform.GetChild(0).SetLZ(0.002f);
  928. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  929. }
  930. LeftShoeSlot.SetLZ(-0.001f);
  931. RightShoeSlot.SetLZ(-0.001f);
  932. LeftLegSlot.SetLZ(0);
  933. RightLegSlot.SetLZ(0);
  934. NeckSlot.SetLZ(0.001f);
  935. LeftHandSlot.SetLZ(-0.001f);
  936. RightHandSlot.SetLZ(-0.001f);
  937. LeftShortSleeveSlot.SetLZ(-0.0015f);
  938. RightShortSleeveSlot.SetLZ(-0.0015f);
  939. LeftLongSleeveUAC.transform.SetLZ(-0.0015f);
  940. RightLongSleeveUAC.transform.SetLZ(-0.0015f);
  941. }
  942. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  943. {
  944. // Debug.Log (bodyPart + " " + armatureName);
  945. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  946. if (bodyPart == BodyPart.Eye)
  947. {
  948. Eye = armatureName;
  949. slotList.Add(EyeSlot);
  950. }
  951. else if (bodyPart == BodyPart.Top)
  952. {
  953. Top = armatureName;
  954. slotList.Add(TopSlot);
  955. }
  956. else if (bodyPart == BodyPart.Shoe)
  957. {
  958. Shoe = armatureName;
  959. slotList.Add(LeftShoeSlot);
  960. slotList.Add(RightShoeSlot);
  961. }
  962. else if (bodyPart == BodyPart.Head)
  963. {
  964. Head = armatureName;
  965. slotList.Add(HeadSlot);
  966. }
  967. else if (bodyPart == BodyPart.Wing)
  968. {
  969. if (Wing == armatureName)
  970. {
  971. return;
  972. }
  973. else
  974. {
  975. Wing = armatureName;
  976. slotList.Add(WingSlot);
  977. }
  978. }
  979. else if (bodyPart == BodyPart.Dress)
  980. {
  981. Dress = armatureName;
  982. slotList.Add(DressSlot);
  983. }
  984. else if (bodyPart == BodyPart.Mouse)
  985. {
  986. Mouse = armatureName;
  987. slotList.Add(MouseSlot);
  988. }
  989. else if (bodyPart == BodyPart.Headwear)
  990. {
  991. HeadWear = armatureName;
  992. slotList.Add(HeadWearSlot);
  993. }
  994. else if (bodyPart == BodyPart.Leg)
  995. {
  996. slotList.Add(LeftLegSlot);
  997. slotList.Add(RightLegSlot);
  998. }
  999. else if (bodyPart == BodyPart.LeftHand)
  1000. {
  1001. slotList.Add(LeftHandSlot);
  1002. }
  1003. else if (bodyPart == BodyPart.RightHand)
  1004. {
  1005. slotList.Add(RightHandSlot);
  1006. }
  1007. else if (bodyPart == BodyPart.Neck)
  1008. {
  1009. slotList.Add(NeckSlot);
  1010. }
  1011. else if (bodyPart == BodyPart.LeftLongSleeve)
  1012. {
  1013. LeftLongSleeve = armatureName;
  1014. ChangeClose(LeftLongSleeveUAC, armatureName);
  1015. return;
  1016. }
  1017. else if (bodyPart == BodyPart.LeftShortSleeve)
  1018. {
  1019. LeftShortSleeve = armatureName;
  1020. slotList.Add(LeftShortSleeveSlot);
  1021. }
  1022. else if (bodyPart == BodyPart.RightLongSleeve)
  1023. {
  1024. RightLongSleeve = armatureName;
  1025. ChangeClose(RightLongSleeveUAC, armatureName);
  1026. return;
  1027. }
  1028. else if (bodyPart == BodyPart.RightShortSleeve)
  1029. {
  1030. RightShortSleeve = armatureName;
  1031. slotList.Add(RightShortSleeveSlot);
  1032. }
  1033. else
  1034. {
  1035. throw new Exception();
  1036. }
  1037. ChangeClose(slotList, armatureName, setDepth);
  1038. if (bodyPart == BodyPart.Wing)
  1039. {
  1040. 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);
  1041. tweenRoot.PingPong = true;
  1042. tweenRoot.StartForward();
  1043. }
  1044. }
  1045. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1046. {
  1047. for (int i = 0; i < slotList.Count; i++)
  1048. {
  1049. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1050. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1051. }
  1052. if (setDepth)
  1053. {
  1054. ResetDepth();
  1055. }
  1056. }
  1057. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1058. {
  1059. if (armatureName == "Empty")
  1060. {
  1061. uac.SetActive(false);
  1062. }
  1063. else
  1064. {
  1065. uac.SetActive(true);
  1066. }
  1067. if (setDepth)
  1068. {
  1069. ResetDepth();
  1070. }
  1071. }
  1072. #endregion
  1073. }