Player.cs 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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. Eye,
  16. Top,
  17. Shoe,
  18. Head,
  19. Wing,
  20. Dress,
  21. Mouse,
  22. Headwear,
  23. }
  24. public class CloseUnit
  25. {
  26. public enum CloseType
  27. {
  28. Top,
  29. Hair,
  30. Wing,
  31. Dress,
  32. Decarator,
  33. }
  34. #region Var
  35. public string Description
  36. {
  37. get { return Language.GetStr("DressRoom", "Armature" + ID); }
  38. }
  39. public int ID;
  40. public int Index;
  41. public int BuyLevel;
  42. public int PixelSize;
  43. public bool Bought;
  44. public string ArmatureName;
  45. public float SpriteAlpha;
  46. public float IconOffset;
  47. public Text BuyBtnLab;
  48. public Sprite[] Sprites;
  49. public Image Icon1;
  50. public Image Icon2;
  51. public Button BuyBtn;
  52. public Button DressBtn;
  53. public Vector2 IconOffset1;
  54. public BodyPart BodyPart;
  55. public Transform Transform;
  56. public CloseType Type;
  57. public double BuyAmt;
  58. public double BuyAdvanceAmt;
  59. public Current BuyCurrent;
  60. public Current BuyAdvanceCurrent;
  61. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  62. #endregion
  63. public CloseUnit(XmlAttributeCollection attribute)
  64. {
  65. ID = Auxiliary.IntParse(attribute[0].Value, -1);
  66. Type = TypeParse(attribute[2].Value);
  67. Index = Auxiliary.IntParse(attribute[3].Value, -1);
  68. BodyPart = BodyPartParse(attribute[4].Value);
  69. BuyLevel = Auxiliary.IntParse(attribute[5].Value, 0);
  70. BuyCurrent = Auxiliary.CurrentParse(attribute[6].Value);
  71. BuyAmt = Auxiliary.DoubleParse(attribute[7].Value, 0);
  72. BuyAdvanceCurrent = Auxiliary.CurrentParse(attribute[8].Value);
  73. BuyAdvanceAmt = Auxiliary.DoubleParse(attribute[9].Value, 0);
  74. PixelSize = Auxiliary.IntParse(attribute[10].Value, 100);
  75. IconOffset = Auxiliary.FloatParse(attribute[11].Value, 0);
  76. IconOffset1 = Auxiliary.VectorParse(',', attribute[12].Value, new Vector3());
  77. Sprites = SpriteParse(attribute[13].Value);
  78. SpriteAlpha = Auxiliary.FloatParse(attribute[14].Value, 1);
  79. ArmatureName = attribute[15].Value;
  80. ManaPlayer.CloseIDDic.Add(ArmatureName, ID);
  81. ManaPlayer.CloseUnitDic.Add(ID, this);
  82. CreateItem();
  83. }
  84. protected void CreateItem()
  85. {
  86. Transform = ManaReso.Get("CloseItem", Folder.UI, false, ManaReso.Get("Canvas"), false);
  87. if (Type == CloseType.Top)
  88. {
  89. Transform.SetParent(ManaReso.Get("Pb_TopGrid"));
  90. }
  91. else if (Type == CloseType.Hair)
  92. {
  93. Transform.SetParent(ManaReso.Get("Pa_HairGrid"));
  94. }
  95. else if (Type == CloseType.Dress)
  96. {
  97. Transform.SetParent(ManaReso.Get("Pc_DressGrid"));
  98. }
  99. else if (Type == CloseType.Wing)
  100. {
  101. Transform.SetParent(ManaReso.Get("Pe_WingGrid"));
  102. }
  103. else if (Type == CloseType.Decarator)
  104. {
  105. Transform.SetParent(ManaReso.Get("Pd_DecaratorGrid"));
  106. }
  107. else
  108. {
  109. throw new Exception();
  110. }
  111. Transform.SetSiblingIndex(Index);
  112. Auxiliary.CompileDic(Transform, ChildDic);
  113. Icon1 = ChildDic["Icon1"].GetComponent<Image>();
  114. Icon2 = ChildDic["Icon2"].GetComponent<Image>();
  115. DressBtn = ChildDic["CloseItem"].GetComponent<Button>();
  116. BuyBtn = ChildDic["BuyBtn"].GetComponent<Button>();
  117. BuyBtnLab = ChildDic["BuyBtnLab"].GetComponent<Text>();
  118. Icon2.sprite = Sprites[0];
  119. float newSize = PixelSize / Icon2.sprite.rect.width;
  120. Icon2.Resize(true, new Vector2(newSize, newSize));
  121. Icon2.SetAlpha(SpriteAlpha);
  122. Icon2.transform.localPosition = new Vector2(0, IconOffset);
  123. if (Sprites.Length > 1)
  124. {
  125. Icon1.SetActive(true);
  126. Icon1.sprite = Sprites[1];
  127. Icon1.Resize(true, new Vector2(newSize, newSize));
  128. Icon1.SetAlpha(SpriteAlpha);
  129. Icon1.transform.localPosition = IconOffset1*newSize + new Vector2(0, IconOffset);
  130. }
  131. if (BuyCurrent != Current.Free)
  132. {
  133. BuyBtnLab.text = Language.GetStr("UI", "P_BtnLab1") + Auxiliary.ImageParse(BuyCurrent) + Auxiliary.ShrinkNumberStr(BuyAmt);
  134. }
  135. BuyBtn.onClick.AddListener
  136. (
  137. () =>
  138. {
  139. ManaAudio.PlayClip(Clip.BtnClip);
  140. ManaReso.Get("Pa_Info").TweenForCG();
  141. Image image = ManaReso.Get<Image>("Pa_Icon2");
  142. image.sprite = Sprites[0];
  143. image.Resize(true, new Vector2(newSize, newSize));
  144. image.transform.localPosition = new Vector3(0, 22) + new Vector3(0, IconOffset);
  145. if (Sprites.Length > 1)
  146. {
  147. ManaReso.SetActive("Pa_Icon1", true);
  148. Image image1 = ManaReso.Get<Image>("Pa_Icon1");
  149. image1.sprite = Sprites[1];
  150. image1.Resize(true, new Vector2(newSize, newSize));
  151. image1.transform.localPosition = new Vector3(0, 22) + new Vector3(0, IconOffset) + (Vector3) IconOffset1*newSize;
  152. }
  153. else
  154. {
  155. ManaReso.SetActive("Pa_Icon1", false);
  156. }
  157. ManaReso.SetText("Pa_Lab", Description);
  158. ManaReso.SetText("Pa_BtnLab", Language.GetStr("UI", "Pa_BtnLab") + Auxiliary.ImageParse(BuyCurrent) + BuyAmt);
  159. ManaReso.SetButtonEvent
  160. (
  161. "Pa_Btn",
  162. OnBuy
  163. );
  164. }
  165. );
  166. DressBtn.onClick.AddListener
  167. (
  168. () =>
  169. {
  170. ManaAudio.PlayClip(Clip.BtnClip);
  171. ManaPlayer.Player.ChangeClose(BodyPart, ArmatureName);
  172. }
  173. );
  174. }
  175. protected Sprite[] SpriteParse(string str)
  176. {
  177. string[] spriteNames = str.Split(',');
  178. Sprite[] sprites = new Sprite[spriteNames.Length];
  179. for (int i = 0; i < spriteNames.Length; i++)
  180. {
  181. sprites[i] = ManaPlayer.CloseSpriteDic[spriteNames[i]];
  182. }
  183. return sprites;
  184. }
  185. protected BodyPart BodyPartParse(string str)
  186. {
  187. int type = Auxiliary.IntParse(str, -1);
  188. if (type == 1)
  189. {
  190. return BodyPart.Head;
  191. }
  192. else if (type == 2)
  193. {
  194. return BodyPart.Dress;
  195. }
  196. else if (type == 3)
  197. {
  198. return BodyPart.Shoe;
  199. }
  200. else if (type == 4)
  201. {
  202. return BodyPart.Headwear;
  203. }
  204. else if (type == 5)
  205. {
  206. return BodyPart.Top;
  207. }
  208. else if (type == 6)
  209. {
  210. return BodyPart.Wing;
  211. }
  212. else
  213. {
  214. throw new Exception();
  215. }
  216. }
  217. protected CloseType TypeParse(string str)
  218. {
  219. int type = Auxiliary.IntParse(str, -1);
  220. if (type == 1)
  221. {
  222. return CloseType.Hair;
  223. }
  224. else if (type == 2)
  225. {
  226. return CloseType.Top;
  227. }
  228. else if (type == 3)
  229. {
  230. return CloseType.Dress;
  231. }
  232. else if (type == 4)
  233. {
  234. return CloseType.Decarator;
  235. }
  236. else if (type == 5)
  237. {
  238. return CloseType.Wing;
  239. }
  240. else
  241. {
  242. throw new Exception();
  243. }
  244. }
  245. public void Unlock()
  246. {
  247. Bought = true;
  248. BuyBtn.interactable = false;
  249. BuyBtn.image.material = Lib.GrayMat;
  250. BuyBtnLab.text = Language.GetStr("UI", "P_BtnLab2");
  251. ManaCenter.CloseAmt++;
  252. }
  253. public void OnBuy()
  254. {
  255. ManaCenter.Pay
  256. (
  257. "",
  258. BuyAmt,
  259. BuyCurrent,
  260. () =>
  261. {
  262. Unlock();
  263. ManaAudio.PlayClip(Clip.CurrentClip);
  264. ManaPlayer.BoughtCloseList.UniqueAdd(ID);
  265. ManaReso.Get("Pa_Info").TweenBacCG();
  266. },
  267. StaticsManager.ItemID.解锁服装,
  268. StaticsManager.ConsumeModule.Shop,
  269. false
  270. );
  271. }
  272. public void OnLevelChange()
  273. {
  274. }
  275. }
  276. public class Player : Regist , IPointerClickHandler
  277. {
  278. #region 变量
  279. public static bool InDressRoom;
  280. public static float JumpFrequency;
  281. public bool AnimLock1;
  282. public bool AnimLock2;
  283. public float JumpTime;
  284. public float JumpTimer;
  285. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  286. #region 换装
  287. private string Eye;
  288. private string Top;
  289. private string Shoe;
  290. private string Head;
  291. private string Wing;
  292. private string Dress;
  293. private string Mouse;
  294. private string HeadWear;
  295. private string TempClose;
  296. public DragonBones.Slot EyeSlot;
  297. public DragonBones.Slot TopSlot;
  298. public DragonBones.Slot HeadSlot;
  299. public DragonBones.Slot DressSlot;
  300. public DragonBones.Slot WingSlot;
  301. public DragonBones.Slot MouseSlot;
  302. public DragonBones.Slot LeftShoeSlot;
  303. public DragonBones.Slot RightShoeSlot;
  304. public DragonBones.Slot HeadWearSlot;
  305. public UnityArmatureComponent UAC;
  306. #endregion
  307. #endregion
  308. public override bool RegistImmed()
  309. {
  310. if (base.RegistImmed())
  311. {
  312. return true;
  313. }
  314. enabled = true;
  315. Auxiliary.CompileDic(transform, ChildDic);
  316. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  317. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  318. ChildDic["Shadow"].CreateStreamScale
  319. (
  320. new List<float>() {0, 0, 0},
  321. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  322. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  323. true,
  324. true,
  325. Curve.EaseOutQuad
  326. );
  327. return false;
  328. }
  329. public void Update()
  330. {
  331. if (Input.GetKeyDown(KeyCode.Space))
  332. {
  333. UnityFactory.factory.BuildArmature("脑壳1");
  334. }
  335. }
  336. public void FixedUpdate()
  337. {
  338. if (InDressRoom)
  339. {
  340. JumpTimer += Time.fixedDeltaTime;
  341. if (JumpTimer > JumpTime)
  342. {
  343. if (!AnimLock1 && !AnimLock2)
  344. {
  345. PlayAnim("newAnimation1");
  346. }
  347. AnimLock2 = true;
  348. }
  349. if (JumpTimer > JumpFrequency)
  350. {
  351. AnimLock2 = false;
  352. JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0f, 1f));
  353. JumpTimer = 0;
  354. }
  355. }
  356. }
  357. public void OnStart(string str, EventObject eventObject)
  358. {
  359. if (eventObject.animationState.name == "newAnimation1")
  360. {
  361. ChildDic["Shadow"].StreamReForScale();
  362. AnimLock1 = true;
  363. TempClose = Eye;
  364. ChangeClose(BodyPart.Eye, "眼睛表情1");
  365. }
  366. else if (eventObject.animationState.name == "newAnimation")
  367. {
  368. AnimLock1 = false;
  369. if (TempClose != null)
  370. {
  371. ChangeClose(BodyPart.Eye, TempClose);
  372. }
  373. }
  374. }
  375. public void PlayAnim(string animName)
  376. {
  377. if (AnimLock1)
  378. {
  379. return;
  380. }
  381. UAC.anim.Play(animName);
  382. }
  383. public void SetAllCollider(bool enable)
  384. {
  385. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  386. for (int i = 0; i < colliders.Length; i++)
  387. {
  388. colliders[i].enabled = enable;
  389. }
  390. }
  391. public void OnPointerClick(PointerEventData eventData)
  392. {
  393. if (ManaCenter.Level < 13)
  394. {
  395. return;
  396. }
  397. ManaReso.Get("I_BlackMask").GetTweenCG().Duration = 0.5f;
  398. ManaAudio.PlayClip(Clip.CurrentClip);
  399. EnterDressRoom();
  400. }
  401. public void Save(bool showNavigate)
  402. {
  403. ManaAudio.PlayClip(Clip.BtnClip);
  404. List<CloseUnit> closeUnitList = new List<CloseUnit>();
  405. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Head]]);
  406. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Dress]]);
  407. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Shoe]]);
  408. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[HeadWear]]);
  409. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Top]]);
  410. if (Wing != "Empty")
  411. {
  412. closeUnitList.Add(ManaPlayer.CloseUnitDic[ManaPlayer.CloseIDDic[Wing]]);
  413. }
  414. for (int i = 0; i < closeUnitList.Count; i++)
  415. {
  416. if (!closeUnitList[i].Bought)
  417. {
  418. if (showNavigate)
  419. {
  420. BuyNavigate(closeUnitList);
  421. }
  422. return;
  423. }
  424. }
  425. ManaPlayer.DressData[0] = Head;
  426. ManaPlayer.DressData[1] = Dress;
  427. ManaPlayer.DressData[2] = Shoe;
  428. ManaPlayer.DressData[3] = HeadWear;
  429. ManaPlayer.DressData[4] = Top;
  430. ManaPlayer.DressData[7] = Wing;
  431. }
  432. public void Reset()
  433. {
  434. ManaAudio.PlayClip(Clip.BtnClip);
  435. List<string> dressData = new List<string>(ManaPlayer.DressData);
  436. dressData[5] = Eye;
  437. ManaPlayer.BuildPlayer(dressData);
  438. }
  439. public void Return()
  440. {
  441. bool allSave = true;
  442. bool allBought = true;
  443. List<string> currentDerssData = new List<string>() {Head, Dress, Shoe, HeadWear, Top, Eye, Mouse, Wing};
  444. for (int i = 0; i < currentDerssData.Count; i++)
  445. {
  446. if (!ManaPlayer.CloseIDDic.ContainsKey(currentDerssData[i]))
  447. {
  448. continue;
  449. }
  450. int id = ManaPlayer.CloseIDDic[currentDerssData[i]];
  451. allBought = allBought && ManaPlayer.CloseUnitDic[id].Bought;
  452. allSave = allSave && currentDerssData[i] == ManaPlayer.DressData[i];
  453. }
  454. if (allBought)
  455. {
  456. if (allSave)
  457. {
  458. ExitDressRoom();
  459. }
  460. else
  461. {
  462. Reset();
  463. ExitDressRoom();
  464. }
  465. }
  466. else
  467. {
  468. Bubble.Show
  469. (
  470. null, Language.GetStr("UI", "P_Return"), null,
  471. () =>
  472. {
  473. Reset();
  474. ManaReso.Get("K_Bubble").GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  475. }
  476. );
  477. }
  478. }
  479. public void BuyNavigate(List<CloseUnit> closeUnitList)
  480. {
  481. for (int i = 0; i < closeUnitList.Count; i++)
  482. {
  483. if (closeUnitList[i].Bought)
  484. {
  485. closeUnitList.RemoveAt(i--);
  486. }
  487. else
  488. {
  489. closeUnitList[i].BuyBtn.onClick.Invoke();
  490. closeUnitList.RemoveAt(i--);
  491. ManaReso.Get("Pa_Info").GetTweenCG().AddEventOnetime
  492. (
  493. EventType.BackwardFinish,
  494. () =>
  495. {
  496. if (closeUnitList.Count == 0)
  497. {
  498. Save(false);
  499. }
  500. else
  501. {
  502. BuyNavigate(closeUnitList);
  503. }
  504. }
  505. );
  506. return;
  507. }
  508. }
  509. }
  510. public void ExitDressRoom()
  511. {
  512. ManaCenter.SceneSwitchLock = false;
  513. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  514. tweenRoot.AddEventOnetime
  515. (
  516. EventType.BackwardFinish,
  517. () =>
  518. {
  519. transform.position = ManaReso.Get("PlayerPosTra").position;
  520. transform.localScale = ManaReso.Get("PlayerPosTra").lossyScale;
  521. ManaReso.Get("Garden").TweenForSr();
  522. ManaReso.Get("DressRoom").TweenBacSr();
  523. ManaReso.Get("C_Main").TweenForCG();
  524. ManaReso.Get("P_DressRoom").TweenBacCG();
  525. }
  526. );
  527. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  528. tweenRoot.AddEventOnetime
  529. (
  530. EventType.BackwardFinish,
  531. () =>
  532. {
  533. SetAllCollider(true);
  534. InDressRoom = false;
  535. JumpTimer = 0;
  536. PlayAnim("newAnimation");
  537. ChildDic["Shadow"].GetStreamScale().Pause();
  538. ChildDic["Shadow"].GetStreamScale().InOrigin = true;
  539. ChildDic["Shadow"].SetActive(false);
  540. ManaReso.Get("B_SignIn0").TweenForCG();
  541. ManaReso.Get("I_BlackMask").TweenForCG();
  542. }
  543. );
  544. }
  545. public void EnterDressRoom()
  546. {
  547. if (ManaCenter.SceneSwitchLock)
  548. {
  549. return;
  550. }
  551. ManaReso.Get("B_SignIn0").TweenBacCG();
  552. InDressRoom = true;
  553. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  554. ManaCenter.SceneSwitchLock = true;
  555. ManaReso.Get("C_Main").TweenBacCG();
  556. SetAllCollider(false);
  557. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  558. tweenRoot.AddEventOnetime
  559. (
  560. EventType.BackwardFinish,
  561. () =>
  562. {
  563. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  564. {
  565. ManaGarden.PlantList[i].Flower.RetrieveElf();
  566. }
  567. ChildDic["Shadow"].SetActive(true);
  568. transform.position = ManaReso.Get("DressRoomPos").position;
  569. transform.localScale = ManaReso.Get("DressRoomPos").lossyScale;
  570. ManaReso.Get("Garden").TweenBacSr();
  571. ManaReso.Get("DressRoom").TweenForSr();
  572. ManaReso.Get("P_DressRoom").TweenForCG();
  573. }
  574. );
  575. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  576. tweenRoot.AddEventOnetime
  577. (
  578. EventType.ForwardFinish,
  579. () =>
  580. {
  581. if (!ManaPlayer.DressRoomInitialized)
  582. {
  583. ManaReso.SetText("I_Lab", Language.GetStr("UI", "I_Lab"));
  584. ManaReso.SetActive("I_Lab", true);
  585. Auxiliary.Instance.DelayCall
  586. (
  587. () =>
  588. {
  589. ManaPlayer.InitializeDressRoom();
  590. ManaReso.Get("I_BlackMask").TweenForCG();
  591. },
  592. 1
  593. );
  594. }
  595. else
  596. {
  597. ManaReso.Get("I_BlackMask").TweenForCG();
  598. }
  599. }
  600. );
  601. }
  602. #region 换装
  603. public UnityArmatureComponent Build()
  604. {
  605. if (!ManaPlayer.Complete)
  606. {
  607. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  608. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("Closet_ske", Folder.Config));
  609. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  610. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("Closet_tex", Folder.Config), "Closet_texture");
  611. ManaPlayer.Complete = true;
  612. }
  613. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  614. UAC.transform.parent = transform;
  615. UAC.transform.localScale = new Vector3(1, 1, 1);
  616. UAC.transform.localPosition = new Vector3();
  617. UAC.anim.Play("newAnimation");
  618. UAC.AddEventListener(EventObject.START, OnStart);
  619. Eye = "眼睛1";
  620. Top = "上衣1";
  621. Shoe = "鞋子1";
  622. Head = "脑壳1";
  623. Wing = "Empty";
  624. Dress = "裙子1";
  625. Mouse = "嘴巴1";
  626. HeadWear = "头饰品1";
  627. EyeSlot = UAC.armature.GetSlot("眼睛");
  628. TopSlot = UAC.armature.GetSlot("上衣");
  629. HeadSlot = UAC.armature.GetSlot("脑壳");
  630. WingSlot = UAC.armature.GetSlot("翅膀");
  631. DressSlot = UAC.armature.GetSlot("裙子");
  632. MouseSlot = UAC.armature.GetSlot("嘴巴");
  633. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  634. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  635. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  636. ChangeClose(BodyPart.Eye, "眼睛1", false);
  637. ChangeClose(BodyPart.Top, "上衣1", false);
  638. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  639. ChangeClose(BodyPart.Head, "脑壳1", false);
  640. ChangeClose(BodyPart.Dress, "裙子1", false);
  641. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  642. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  643. return UAC;
  644. }
  645. public UnityArmatureComponent BuildPink()
  646. {
  647. Build();
  648. ChangeClose(BodyPart.Eye, "眼睛3", false);
  649. ChangeClose(BodyPart.Top, "上衣3", false);
  650. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  651. ChangeClose(BodyPart.Head, "脑壳3", false);
  652. ChangeClose(BodyPart.Wing, "Empty", false);
  653. ChangeClose(BodyPart.Dress, "裙子3", false);
  654. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  655. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  656. ResetDepth();
  657. return UAC;
  658. }
  659. public UnityArmatureComponent BuildBlond()
  660. {
  661. Build();
  662. ChangeClose(BodyPart.Wing, "Empty", false);
  663. ResetDepth();
  664. return UAC;
  665. }
  666. public UnityArmatureComponent BuildBrown()
  667. {
  668. Build();
  669. ChangeClose(BodyPart.Eye, "眼睛2", false);
  670. ChangeClose(BodyPart.Top, "上衣2", false);
  671. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  672. ChangeClose(BodyPart.Head, "脑壳2", false);
  673. ChangeClose(BodyPart.Wing, "Empty", false);
  674. ChangeClose(BodyPart.Dress, "裙子2", false);
  675. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  676. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  677. ResetDepth();
  678. return UAC;
  679. }
  680. public void ResetDepth()
  681. {
  682. UAC.transform.SetLZ(2);
  683. if (Wing != "Empty")
  684. {
  685. transform.FindChild("Armature/" + Wing).SetLZ(0.003f);
  686. }
  687. transform.FindChild("Armature/" + Eye).SetLZ(-0.001f);
  688. transform.FindChild("Armature/" + Top).SetLZ(-0.003f);
  689. transform.FindChild("Armature/" + Mouse).SetLZ(-0.001f);
  690. transform.FindChild("Armature/" + HeadWear).SetLZ(-0.001f);
  691. Transform tempTra = transform.FindChild("Armature/" + Head);
  692. tempTra.SetLZ(0);
  693. if (tempTra.childCount > 1)
  694. {
  695. tempTra.GetChild(0).SetLZ(0.002f);
  696. tempTra.GetChild(1).SetLZ(0f);
  697. }
  698. tempTra = transform.FindChild("Armature/" + Dress);
  699. tempTra.SetLZ(-0.002f);
  700. if (tempTra.childCount > 1)
  701. {
  702. tempTra.GetChild(0).SetLZ(0.001f);
  703. }
  704. tempTra = transform.FindChild("Armature/" + Shoe);
  705. tempTra.SetLZ(-0.001f);
  706. transform.FindChild("Armature").GetChild(tempTra.GetSiblingIndex() + 1).SetLZ(-0.001f);
  707. transform.FindChild("Armature/左腿").SetLZ(0);
  708. transform.FindChild("Armature/右腿").SetLZ(0);
  709. transform.FindChild("Armature/脖子").SetLZ(0.001f);
  710. transform.FindChild("Armature/左手").SetLZ(-0.001f);
  711. transform.FindChild("Armature/右手").SetLZ(-0.001f);
  712. }
  713. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  714. {
  715. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  716. if (bodyPart == BodyPart.Eye)
  717. {
  718. Eye = armatureName;
  719. slotList.Add(EyeSlot);
  720. }
  721. else if (bodyPart == BodyPart.Top)
  722. {
  723. Top = armatureName;
  724. slotList.Add(TopSlot);
  725. }
  726. else if (bodyPart == BodyPart.Shoe)
  727. {
  728. Shoe = armatureName;
  729. slotList.Add(LeftShoeSlot);
  730. slotList.Add(RightShoeSlot);
  731. }
  732. else if (bodyPart == BodyPart.Head)
  733. {
  734. Head = armatureName;
  735. slotList.Add(HeadSlot);
  736. }
  737. else if (bodyPart == BodyPart.Wing)
  738. {
  739. if (Wing == armatureName)
  740. {
  741. return;
  742. }
  743. else
  744. {
  745. Wing = armatureName;
  746. slotList.Add(WingSlot);
  747. }
  748. }
  749. else if (bodyPart == BodyPart.Dress)
  750. {
  751. Dress = armatureName;
  752. slotList.Add(DressSlot);
  753. }
  754. else if (bodyPart == BodyPart.Mouse)
  755. {
  756. Mouse = armatureName;
  757. slotList.Add(MouseSlot);
  758. }
  759. else if (bodyPart == BodyPart.Headwear)
  760. {
  761. HeadWear = armatureName;
  762. slotList.Add(HeadWearSlot);
  763. }
  764. else
  765. {
  766. throw new Exception();
  767. }
  768. ChangeClose(slotList, armatureName, setDepth);
  769. if (bodyPart == BodyPart.Wing)
  770. {
  771. 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);
  772. tweenRoot.PingPong = true;
  773. tweenRoot.StartForward();
  774. }
  775. }
  776. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  777. {
  778. for (int i = 0; i < slotList.Count; i++)
  779. {
  780. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName);
  781. }
  782. if (setDepth)
  783. {
  784. ResetDepth();
  785. }
  786. }
  787. #endregion
  788. }