Player.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  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 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. ManaServer.Save();
  339. },
  340. StaticsManager.ItemID.解锁服装,
  341. StaticsManager.ConsumeModule.Shop,
  342. true,
  343. false,
  344. () =>
  345. {
  346. ManaPlayer.Player.Reset();
  347. TweenRoot tweenRoot = ManaReso.Get("Pa_Info").TweenBacCG();
  348. tweenRoot.AddEventOnetime
  349. (
  350. EventType.BackwardFinish,
  351. () =>
  352. {
  353. ManaPlayer.Player.Return();
  354. }
  355. );
  356. ManaReso.Get("B_SignIn0").GetTweenCG().AddEventOnetime
  357. (
  358. EventType.ForwardFinish,
  359. () =>
  360. {
  361. ManaReso.Get("F_Manage0").TweenForVec();
  362. }
  363. );
  364. }
  365. );
  366. }
  367. public void OnLevelChange()
  368. {
  369. }
  370. }
  371. public enum PlayerDirection
  372. {
  373. Left = 0,
  374. Right = 1,
  375. }
  376. public class Player : Regist , IPointerClickHandler
  377. {
  378. #region 变量
  379. public static string IdleAnimationName = "newAnimation";
  380. public static string JumpAnimationName = "newAnimation1";
  381. public static string WalkAnimationName = "newAnimation2";
  382. public static string RunAnimationName = "newAnimation3";
  383. public static bool InDressRoom;
  384. public static float JumpFrequency;
  385. public PlayerDirection PlayerDirection
  386. {
  387. get { return playerDirection; }
  388. set
  389. {
  390. playerDirection = value;
  391. Flip(playerDirection);
  392. }
  393. }
  394. private PlayerDirection playerDirection = PlayerDirection.Left;
  395. public bool AnimLock1;
  396. public bool AnimLock2;
  397. public float JumpTime;
  398. public float JumpTimer;
  399. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  400. #region 换装
  401. public string Eye;
  402. public string Top;
  403. public string Shoe;
  404. public string Head;
  405. public string Wing;
  406. public string Dress;
  407. public string Mouse;
  408. public string HeadWear;
  409. public string LeftLongSleeve;
  410. public string LeftShortSleeve;
  411. public string RightLongSleeve;
  412. public string RightShortSleeve;
  413. private string TempClose;
  414. public DragonBones.Slot NeckSlot;
  415. public DragonBones.Slot LeftHandSlot;
  416. public DragonBones.Slot RightHandSlot;
  417. public DragonBones.Slot LeftLegSlot;
  418. public DragonBones.Slot RightLegSlot;
  419. public DragonBones.Slot LeftShortSleeveSlot;
  420. public DragonBones.Slot RightShortSleeveSlot;
  421. public DragonBones.Slot EyeSlot;
  422. public DragonBones.Slot TopSlot;
  423. public DragonBones.Slot HeadSlot;
  424. public DragonBones.Slot DressSlot;
  425. public DragonBones.Slot WingSlot;
  426. public DragonBones.Slot MouseSlot;
  427. public DragonBones.Slot LeftShoeSlot;
  428. public DragonBones.Slot RightShoeSlot;
  429. public DragonBones.Slot HeadWearSlot;
  430. public UnityArmatureComponent UAC;
  431. public UnityArmatureComponent LeftLongSleeveUAC;
  432. public UnityArmatureComponent RightLongSleeveUAC;
  433. #endregion
  434. #endregion
  435. public override bool RegistImmed()
  436. {
  437. if (base.RegistImmed())
  438. {
  439. return true;
  440. }
  441. enabled = true;
  442. Auxiliary.CompileDic(transform, ChildDic);
  443. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  444. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  445. ChildDic["Shadow"].CreateStreamScale
  446. (
  447. new List<float>() {0, 0, 0},
  448. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  449. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  450. true,
  451. true,
  452. Curve.EaseOutQuad
  453. );
  454. return false;
  455. }
  456. public void Update()
  457. {
  458. if (InDressRoom)
  459. {
  460. JumpTimer += Time.deltaTime;
  461. if (JumpTimer > JumpTime)
  462. {
  463. if (!AnimLock1 && !AnimLock2)
  464. {
  465. PlayAnim(JumpAnimationName);
  466. }
  467. AnimLock2 = true;
  468. }
  469. if (JumpTimer > JumpFrequency)
  470. {
  471. AnimLock2 = false;
  472. JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0f, 1f));
  473. JumpTimer = 0;
  474. }
  475. }
  476. //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  477. //{
  478. // MoveThread();
  479. //}
  480. }
  481. public void OnStart(string str, EventObject eventObject)
  482. {
  483. if (eventObject.animationState.name == JumpAnimationName)
  484. {
  485. ChildDic["Shadow"].StreamReForScale();
  486. AnimLock1 = true;
  487. TempClose = Eye;
  488. ChangeClose(BodyPart.Eye, "眼睛表情1");
  489. }
  490. else if (eventObject.animationState.name == IdleAnimationName)
  491. {
  492. AnimLock1 = false;
  493. if (TempClose != null)
  494. {
  495. ChangeClose(BodyPart.Eye, TempClose);
  496. }
  497. }
  498. }
  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. CurrentAnimationName = animName;
  513. }
  514. UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
  515. }
  516. public float GetFadeInTime(string lastAnimation, string targetAnimation)
  517. {
  518. if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
  519. return -1f;
  520. else
  521. return 0.1f;
  522. //throw new Exception();
  523. }
  524. public void SetAllCollider(bool enable)
  525. {
  526. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  527. for (int i = 0; i < colliders.Length; i++)
  528. {
  529. colliders[i].enabled = enable;
  530. }
  531. }
  532. public void OnPointerClick(PointerEventData eventData)
  533. {
  534. ManaAudio.PlayClip(Clip.CurrentClip);
  535. ManaNickName.ShowNickNameSettingPanel();
  536. PlayAnim(JumpAnimationName);
  537. }
  538. public void Flip(PlayerDirection direction)
  539. {
  540. if (direction == PlayerDirection.Left)
  541. {
  542. UAC.armature.flipX = false;
  543. playerDirection = PlayerDirection.Left;
  544. }
  545. else
  546. {
  547. UAC.armature.flipX = true;
  548. playerDirection = PlayerDirection.Right;
  549. }
  550. }
  551. public void Save(bool showNavigate)
  552. {
  553. ManaAudio.PlayClip(Clip.BtnClip);
  554. List<CloseUnit> closeUnitList = new List<CloseUnit>();
  555. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Head]]);
  556. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Dress]]);
  557. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Shoe]]);
  558. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[HeadWear]]);
  559. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Top]]);
  560. if (Wing != "Empty")
  561. {
  562. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Wing]]);
  563. }
  564. for (int i = 0; i < closeUnitList.Count; i++)
  565. {
  566. if (!closeUnitList[i].Bought)
  567. {
  568. if (showNavigate)
  569. {
  570. BuyNavigate(closeUnitList);
  571. }
  572. return;
  573. }
  574. }
  575. ManaPlayer.DressData[0] = Head;
  576. ManaPlayer.DressData[1] = Dress;
  577. ManaPlayer.DressData[2] = Shoe;
  578. ManaPlayer.DressData[3] = HeadWear;
  579. ManaPlayer.DressData[4] = Top;
  580. ManaPlayer.DressData[7] = Wing;
  581. ManaPlayer.DressData[8] = LeftLongSleeve;
  582. ManaPlayer.DressData[9] = LeftShortSleeve;
  583. ManaPlayer.DressData[10] = RightLongSleeve;
  584. ManaPlayer.DressData[11] = RightShortSleeve;
  585. //GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.SyncClose();
  586. }
  587. public void Reset()
  588. {
  589. ManaAudio.PlayClip(Clip.BtnClip);
  590. List<string> dressData = new List<string>(ManaPlayer.DressData);
  591. dressData[5] = Eye;
  592. ManaPlayer.BuildPlayer(dressData);
  593. }
  594. public void Return()
  595. {
  596. bool allSave = true;
  597. bool allBought = true;
  598. List<string> currentDerssData = new List<string>() {Head, Dress, Shoe, HeadWear, Top, Eye, Mouse, Wing};
  599. for (int i = 0; i < currentDerssData.Count; i++)
  600. {
  601. if (!ManaPlayer.CloseIDDic.ContainsKey(currentDerssData[i]))
  602. {
  603. continue;
  604. }
  605. int id = ManaPlayer.CloseIDDic[currentDerssData[i]];
  606. allBought = allBought && ManaPlayer.CloseUnitDic[id].Bought;
  607. allSave = allSave && currentDerssData[i] == ManaPlayer.DressData[i];
  608. }
  609. if (allBought)
  610. {
  611. if (allSave)
  612. {
  613. ExitDressRoom();
  614. }
  615. else
  616. {
  617. Reset();
  618. ExitDressRoom();
  619. }
  620. }
  621. else
  622. {
  623. Bubble.Show
  624. (
  625. null, Language.GetStr("UI", "P_Return"), null, null,
  626. () =>
  627. {
  628. Reset();
  629. ManaReso.Get("K_Bubble").GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  630. }
  631. );
  632. }
  633. }
  634. public void BuyNavigate(List<CloseUnit> closeUnitList)
  635. {
  636. for (int i = 0; i < closeUnitList.Count; i++)
  637. {
  638. if (closeUnitList[i].Bought)
  639. {
  640. closeUnitList.RemoveAt(i--);
  641. }
  642. else
  643. {
  644. closeUnitList[i].BuyBtn.onClick.Invoke();
  645. closeUnitList.RemoveAt(i--);
  646. ManaReso.Get("Pa_Info").GetTweenCG().AddEventOnetime
  647. (
  648. EventType.BackwardFinish,
  649. () =>
  650. {
  651. if (closeUnitList.Count == 0)
  652. {
  653. Save(false);
  654. }
  655. else
  656. {
  657. BuyNavigate(closeUnitList);
  658. }
  659. }
  660. );
  661. return;
  662. }
  663. }
  664. }
  665. public void ExitDressRoom()
  666. {
  667. ManaCenter.SceneSwitchLock = false;
  668. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  669. tweenRoot.AddEventOnetime
  670. (
  671. EventType.BackwardFinish,
  672. () =>
  673. {
  674. transform.SetParent(ManaReso.Get("GardenNormal"));
  675. transform.position = ManaReso.Get("PlayerPosTra").position;
  676. transform.localScale = ManaReso.Get("PlayerPosTra").lossyScale;
  677. ManaReso.Get("Garden").TweenForSr();
  678. ManaReso.Get("DressRoom").TweenBacSr();
  679. ManaReso.Get("C_Main").TweenForCG();
  680. ManaReso.Get("P_DressRoom").TweenBacCG();
  681. }
  682. );
  683. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  684. tweenRoot.AddEventOnetime
  685. (
  686. EventType.BackwardFinish,
  687. () =>
  688. {
  689. SetAllCollider(true);
  690. InDressRoom = false;
  691. JumpTimer = 0;
  692. PlayAnim(IdleAnimationName);
  693. ChildDic["Shadow"].GetStreamScale().Pause();
  694. ChildDic["Shadow"].GetStreamScale().InOrigin = true;
  695. ChildDic["ShadowParent"].SetActive(false);
  696. ManaReso.Get("B_SignIn0").TweenForCG();
  697. ManaReso.Get("I_BlackMask").TweenForCG();
  698. }
  699. );
  700. }
  701. public void EnterDressRoom()
  702. {
  703. if (ManaCenter.SceneSwitchLock)
  704. {
  705. return;
  706. }
  707. ChildDic["ShadowParent"].SetActive(true);
  708. ManaReso.Get("B_SignIn0").TweenBacCG();
  709. InDressRoom = true;
  710. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  711. ManaCenter.SceneSwitchLock = true;
  712. ManaReso.Get("C_Main").TweenBacCG();
  713. SetAllCollider(false);
  714. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  715. tweenRoot.AddEventOnetime
  716. (
  717. EventType.BackwardFinish,
  718. () =>
  719. {
  720. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  721. {
  722. ManaGarden.PlantList[i].Flower.RetrieveElf();
  723. }
  724. //ChildDic["ShadowParent"].SetActive(true);
  725. transform.SetParent(ManaReso.Get("DressRoom"));
  726. transform.position = ManaReso.Get("DressRoomPos").position;
  727. transform.localScale = ManaReso.Get("DressRoomPos").lossyScale;
  728. ManaReso.Get("Garden").TweenBacSr();
  729. ManaReso.Get("DressRoom").TweenForSr();
  730. ManaReso.Get("P_DressRoom").TweenForCG();
  731. }
  732. );
  733. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  734. tweenRoot.AddEventOnetime
  735. (
  736. EventType.ForwardFinish,
  737. () =>
  738. {
  739. ManaReso.Get("I_BlackMask").TweenForCG();
  740. }
  741. );
  742. }
  743. #region 换装
  744. public void CorrectPivot()
  745. {
  746. List<Transform> children = new List<Transform>();
  747. while (transform.childCount > 0)
  748. {
  749. children.Add(transform.GetChild(0));
  750. children.Back(0).parent = null;
  751. }
  752. Vector3 offset = UAC.transform.FindChild("Pivot").position - transform.position;
  753. children[0].position += offset;
  754. children[1].position += offset;
  755. transform.position += offset;
  756. for (int i = 0; i < children.Count; i++)
  757. {
  758. children[i].parent = transform;
  759. }
  760. }
  761. public UnityArmatureComponent Build()
  762. {
  763. if (!ManaPlayer.Complete)
  764. {
  765. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  766. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  767. ManaPlayer.Complete = true;
  768. }
  769. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  770. UAC.transform.parent = transform;
  771. UAC.transform.localScale = new Vector3(1, 1, 1);
  772. UAC.transform.localPosition = new Vector3();
  773. UAC.anim.Play(IdleAnimationName);
  774. UAC.AddEventListener(EventObject.START, OnStart);
  775. Eye = "眼睛1";
  776. Top = "上衣1";
  777. Shoe = "鞋子1";
  778. Head = "脑壳1";
  779. Wing = "Empty";
  780. Dress = "裙子1";
  781. Mouse = "嘴巴1";
  782. HeadWear = "头饰品1";
  783. NeckSlot = UAC.armature.GetSlot("脖子");
  784. LeftHandSlot = UAC.armature.GetSlot("左手");
  785. RightHandSlot = UAC.armature.GetSlot("右手");
  786. LeftLegSlot = UAC.armature.GetSlot("左腿");
  787. RightLegSlot = UAC.armature.GetSlot("右腿");
  788. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  789. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  790. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  791. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  792. EyeSlot = UAC.armature.GetSlot("眼睛");
  793. TopSlot = UAC.armature.GetSlot("上衣");
  794. HeadSlot = UAC.armature.GetSlot("脑壳");
  795. WingSlot = UAC.armature.GetSlot("翅膀");
  796. DressSlot = UAC.armature.GetSlot("裙子");
  797. MouseSlot = UAC.armature.GetSlot("嘴巴");
  798. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  799. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  800. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  801. ChangeClose(BodyPart.Eye, "眼睛1", false);
  802. ChangeClose(BodyPart.Top, "上衣1", false);
  803. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  804. ChangeClose(BodyPart.Head, "脑壳1", false);
  805. ChangeClose(BodyPart.Dress, "裙子1", false);
  806. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  807. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  808. CorrectPivot();
  809. return UAC;
  810. }
  811. public UnityArmatureComponent BuildPink()
  812. {
  813. Build();
  814. ChangeClose(BodyPart.Eye, "眼睛3", false);
  815. ChangeClose(BodyPart.Top, "上衣3", false);
  816. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  817. ChangeClose(BodyPart.Head, "脑壳3", false);
  818. ChangeClose(BodyPart.Wing, "Empty", false);
  819. ChangeClose(BodyPart.Dress, "裙子3", false);
  820. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  821. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  822. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  823. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  824. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  825. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  826. ResetDepth();
  827. return UAC;
  828. }
  829. public UnityArmatureComponent BuildBlond()
  830. {
  831. Build();
  832. ChangeClose(BodyPart.Wing, "Empty", false);
  833. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  834. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  835. ChangeClose(BodyPart.LeftShortSleeve, "短袖1左", false);
  836. ChangeClose(BodyPart.RightShortSleeve, "短袖1右", false);
  837. ResetDepth();
  838. return UAC;
  839. }
  840. public UnityArmatureComponent BuildBrown()
  841. {
  842. Build();
  843. ChangeClose(BodyPart.Eye, "眼睛2", false);
  844. ChangeClose(BodyPart.Top, "上衣2", false);
  845. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  846. ChangeClose(BodyPart.Head, "脑壳2", false);
  847. ChangeClose(BodyPart.Wing, "Empty", false);
  848. ChangeClose(BodyPart.Dress, "裙子2", false);
  849. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  850. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  851. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  852. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  853. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  854. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  855. ResetDepth();
  856. return UAC;
  857. }
  858. public void ResetDepth()
  859. {
  860. UAC.transform.SetLZ(2.5f);
  861. WingSlot.UnityTransform.SetLZ(0);
  862. EyeSlot.UnityTransform.SetLZ(0);
  863. TopSlot.UnityTransform.SetLZ(0);
  864. MouseSlot.UnityTransform.SetLZ(0);
  865. HeadWearSlot.UnityTransform.SetLZ(0);
  866. LeftShoeSlot.UnityTransform.SetLZ(0);
  867. RightShoeSlot.UnityTransform.SetLZ(0);
  868. LeftLegSlot.UnityTransform.SetLZ(0);
  869. RightLegSlot.UnityTransform.SetLZ(0);
  870. NeckSlot.UnityTransform.SetLZ(0);
  871. LeftHandSlot.UnityTransform.SetLZ(0);
  872. RightHandSlot.UnityTransform.SetLZ(0);
  873. LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  874. RightShortSleeveSlot.UnityTransform.SetLZ(0);
  875. WingSlot.SetLZ(0.003f);
  876. EyeSlot.SetLZ(-0.001f);
  877. TopSlot.SetLZ(-0.003f);
  878. MouseSlot.SetLZ(-0.001f);
  879. HeadWearSlot.SetLZ(-0.001f);
  880. HeadSlot.UnityTransform.SetLZ(0);
  881. if (HeadSlot.UnityTransform.childCount > 1)
  882. {
  883. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.002f);
  884. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  885. }
  886. DressSlot.UnityTransform.SetLZ(-0.002f);
  887. //Debug.Log(DressSlot.UnityTransform.name);
  888. if (DressSlot.UnityTransform.childCount > 1)
  889. {
  890. DressSlot.UnityTransform.GetChild(0).SetLZ(0.002f);
  891. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  892. }
  893. LeftShoeSlot.SetLZ(-0.001f);
  894. RightShoeSlot.SetLZ(-0.001f);
  895. LeftLegSlot.SetLZ(0);
  896. RightLegSlot.SetLZ(0);
  897. NeckSlot.SetLZ(0.001f);
  898. LeftHandSlot.SetLZ(-0.001f);
  899. RightHandSlot.SetLZ(-0.001f);
  900. //Debug.Log(LeftLongSleeveSlot.UnityTransform.name);
  901. //Debug.Log(LeftShortSleeveSlot.UnityTransform.name);
  902. //Debug.Log(RightShortSleeveSlot.UnityTransform.name);
  903. LeftShortSleeveSlot.SetLZ(-0.0015f);
  904. RightShortSleeveSlot.SetLZ(-0.0015f);
  905. LeftLongSleeveUAC.transform.SetLZ(-0.0015f);
  906. RightLongSleeveUAC.transform.SetLZ(-0.0015f);
  907. // Debug.Log (LeftLongSleeveSlot.armature.UnityTransform.name);
  908. // Debug.Log (LeftShortSleeveSlot.armature.UnityTransform.name);
  909. // Debug.Log (RightLongSleeveSlot.armature.UnityTransform.name);
  910. // Debug.Log (RightShortSleeveSlot.armature.UnityTransform.name);
  911. //
  912. // UAC.transform.SetLZ(2.5f);
  913. //
  914. // if (Wing != "Empty")
  915. // {
  916. // transform.FindChild("Armature/" + Wing).SetLZ(0.003f);
  917. // }
  918. //
  919. // transform.FindChild("Armature/" + Eye).SetLZ(-0.001f);
  920. // transform.FindChild("Armature/" + Top).SetLZ(-0.003f);
  921. // transform.FindChild("Armature/" + Mouse).SetLZ(-0.001f);
  922. // transform.FindChild("Armature/" + HeadWear).SetLZ(-0.001f);
  923. //
  924. // Transform tempTra = transform.FindChild("Armature/" + Head);
  925. //
  926. // tempTra.SetLZ(0);
  927. // if (tempTra.childCount > 1)
  928. // {
  929. // tempTra.GetChild(0).SetLZ(0.002f);
  930. // tempTra.GetChild(1).SetLZ(0f);
  931. // }
  932. //
  933. //
  934. // tempTra = transform.FindChild("Armature/" + Dress);
  935. //
  936. // tempTra.SetLZ(-0.002f);
  937. // if (tempTra.childCount > 1)
  938. // {
  939. // tempTra.GetChild(0).SetLZ(0.002f);
  940. // tempTra.GetChild(1).SetLZ(0f);
  941. // }
  942. //
  943. //
  944. // tempTra = transform.FindChild("Armature/" + Shoe);
  945. // tempTra.SetLZ(-0.001f);
  946. //
  947. // transform.FindChild("Armature").GetChild(tempTra.GetSiblingIndex() + 1).SetLZ(-0.001f);
  948. //
  949. //
  950. // transform.FindChild("Armature/左腿").SetLZ(0);
  951. // transform.FindChild("Armature/右腿").SetLZ(0);
  952. // transform.FindChild("Armature/脖子").SetLZ(0.001f);
  953. // transform.FindChild("Armature/左手").SetLZ(-0.001f);
  954. // transform.FindChild("Armature/右手").SetLZ(-0.001f);
  955. }
  956. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  957. {
  958. // Debug.Log (bodyPart + " " + armatureName);
  959. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  960. if (bodyPart == BodyPart.Eye)
  961. {
  962. Eye = armatureName;
  963. slotList.Add(EyeSlot);
  964. }
  965. else if (bodyPart == BodyPart.Top)
  966. {
  967. Top = armatureName;
  968. slotList.Add(TopSlot);
  969. }
  970. else if (bodyPart == BodyPart.Shoe)
  971. {
  972. Shoe = armatureName;
  973. slotList.Add(LeftShoeSlot);
  974. slotList.Add(RightShoeSlot);
  975. }
  976. else if (bodyPart == BodyPart.Head)
  977. {
  978. Head = armatureName;
  979. slotList.Add(HeadSlot);
  980. }
  981. else if (bodyPart == BodyPart.Wing)
  982. {
  983. if (Wing == armatureName)
  984. {
  985. return;
  986. }
  987. else
  988. {
  989. Wing = armatureName;
  990. slotList.Add(WingSlot);
  991. }
  992. }
  993. else if (bodyPart == BodyPart.Dress)
  994. {
  995. Dress = armatureName;
  996. slotList.Add(DressSlot);
  997. }
  998. else if (bodyPart == BodyPart.Mouse)
  999. {
  1000. Mouse = armatureName;
  1001. slotList.Add(MouseSlot);
  1002. }
  1003. else if (bodyPart == BodyPart.Headwear)
  1004. {
  1005. HeadWear = armatureName;
  1006. slotList.Add(HeadWearSlot);
  1007. }
  1008. else if (bodyPart == BodyPart.Leg)
  1009. {
  1010. slotList.Add(LeftLegSlot);
  1011. slotList.Add(RightLegSlot);
  1012. }
  1013. else if (bodyPart == BodyPart.LeftHand)
  1014. {
  1015. slotList.Add(LeftHandSlot);
  1016. }
  1017. else if (bodyPart == BodyPart.RightHand)
  1018. {
  1019. slotList.Add(RightHandSlot);
  1020. }
  1021. else if (bodyPart == BodyPart.Neck)
  1022. {
  1023. slotList.Add(NeckSlot);
  1024. }
  1025. else if (bodyPart == BodyPart.LeftLongSleeve)
  1026. {
  1027. LeftLongSleeve = armatureName;
  1028. ChangeClose(LeftLongSleeveUAC, armatureName);
  1029. return;
  1030. }
  1031. else if (bodyPart == BodyPart.LeftShortSleeve)
  1032. {
  1033. LeftShortSleeve = armatureName;
  1034. slotList.Add(LeftShortSleeveSlot);
  1035. }
  1036. else if (bodyPart == BodyPart.RightLongSleeve)
  1037. {
  1038. RightLongSleeve = armatureName;
  1039. ChangeClose(RightLongSleeveUAC, armatureName);
  1040. return;
  1041. }
  1042. else if (bodyPart == BodyPart.RightShortSleeve)
  1043. {
  1044. RightShortSleeve = armatureName;
  1045. slotList.Add(RightShortSleeveSlot);
  1046. }
  1047. else
  1048. {
  1049. throw new Exception();
  1050. }
  1051. ChangeClose(slotList, armatureName, setDepth);
  1052. if (bodyPart == BodyPart.Wing)
  1053. {
  1054. 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);
  1055. tweenRoot.PingPong = true;
  1056. tweenRoot.StartForward();
  1057. }
  1058. }
  1059. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1060. {
  1061. for (int i = 0; i < slotList.Count; i++)
  1062. {
  1063. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1064. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1065. }
  1066. if (setDepth)
  1067. {
  1068. ResetDepth();
  1069. }
  1070. }
  1071. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1072. {
  1073. if (armatureName == "Empty")
  1074. {
  1075. uac.SetActive(false);
  1076. }
  1077. else
  1078. {
  1079. uac.SetActive(true);
  1080. }
  1081. if (setDepth)
  1082. {
  1083. ResetDepth();
  1084. }
  1085. }
  1086. #endregion
  1087. }