Player.cs 37 KB

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