Player.cs 35 KB

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