Player.cs 37 KB

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