Player.cs 37 KB

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