Player.cs 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  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 class PlayerLabel
  15. {
  16. public static string MessageBox = "MessageBox";
  17. public static string NickName = "NickName";
  18. public static string Pivot = "Pivot";
  19. public static string Shadow = "Shadow";
  20. public static string ExpressionMeshFilter = "ExpressionMeshFilter";
  21. public static string ShadowParent = "ShadowParent";
  22. public static string Player = "Player";
  23. public static string RightPos = "RightPos";
  24. public static string LeftPos = "LeftPos";
  25. public static string EnterGameTra = "EnterGameTra";
  26. }
  27. public enum BodyPart
  28. {
  29. Leg = 0,
  30. LeftHand = 1,
  31. RightHand = 2,
  32. LeftLongSleeve = 3,
  33. LeftShortSleeve = 4,
  34. RightLongSleeve = 5,
  35. RightShortSleeve = 6,
  36. Neck = 7,
  37. Eye = 8,
  38. Top = 9,
  39. Shoe = 10,
  40. Head = 11,
  41. Wing = 12,
  42. Dress = 13,
  43. Mouse = 14,
  44. Headwear = 15,
  45. }
  46. public class ExchangeInfo
  47. {
  48. public float Rate;
  49. public double Value;
  50. public Current Current;
  51. public static void GetExchangeValue(ExchangeInfo info, StaticsManager.ConsumeModule consumeModule)
  52. {
  53. if (info.Current == Current.Coin)
  54. {
  55. Manager.AddCoin(info.Value, StaticsManager.ItemID.获得金币, consumeModule);
  56. }
  57. else if (info.Current == Current.Diamond)
  58. {
  59. Manager.AddDiamond(info.Value, StaticsManager.ItemID.获得钻石, consumeModule);
  60. }
  61. }
  62. public static ExchangeInfo GetExchangeInfo(Current current, double amt, float rate)
  63. {
  64. ExchangeInfo info = new ExchangeInfo();
  65. info.Rate = rate;
  66. info.Value = amt * rate;
  67. info.Current = current;
  68. return info;
  69. }
  70. }
  71. public class CloseItemLabel
  72. {
  73. public static string Icon1 = "Icon1";
  74. public static string Icon2 = "Icon2";
  75. public static string Icon3 = "Icon3";
  76. public static string CloseItem = "CloseItem";
  77. public static string BuyBtn = "BuyBtn";
  78. public static string BuyBtnLab = "BuyBtnLab";
  79. }
  80. public class CloseItem
  81. {
  82. public enum CloseType
  83. {
  84. Top,
  85. Hair,
  86. Wing,
  87. Dress,
  88. Decarator,
  89. Shoe,
  90. }
  91. #region Var
  92. public string Name
  93. {
  94. get { return LabelUtility.CombineLanguageLabel(LanguageLabel.DressRoom, FullID); }
  95. }
  96. public static string IDPrefix = "Armature";
  97. public string FullID
  98. {
  99. get { return IDPrefix + id; }
  100. }
  101. public int id;
  102. public int Index;
  103. public int BuyLevel;
  104. public int PixelSize;
  105. public bool Possess;
  106. public string ArmatureName;
  107. public string[] ExtraArmatureNames;
  108. public BodyPart[] ExtraBodyParts;
  109. public float SpriteAlpha;
  110. public float IconOffset;
  111. public Text BuyBtnLab;
  112. public Sprite[] Sprites;
  113. public Image Icon1;
  114. public Image Icon2;
  115. public Image Icon3;
  116. public Button BuyBtn;
  117. public Button DressBtn;
  118. public Vector2 IconOffset1;
  119. public Vector2 IconOffset2;
  120. public BodyPart BodyPart;
  121. public Transform Transform;
  122. public CloseType Type;
  123. public bool Ignore;
  124. public double BuyAmt;
  125. public double BuyAdvanceAmt;
  126. public Current BuyCurrent;
  127. public Current BuyAdvanceCurrent;
  128. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  129. #endregion
  130. public CloseItem(XmlAttributeCollection attribute)
  131. {
  132. Ignore = Auxiliary.StringToBool(attribute[19].Value, false);
  133. id = Auxiliary.StringToInt(attribute[0].Value, -1);
  134. BodyPart = BodyPartParse(attribute[4].Value);
  135. ArmatureName = attribute[16].Value;
  136. PlayerManager.CloseIDDic.Add(ArmatureName, id);
  137. PlayerManager.CloseItemDic.Add(id, this);
  138. if (Ignore)
  139. {
  140. return;
  141. }
  142. Type = TypeParse(attribute[2].Value);
  143. Index = Auxiliary.StringToInt(attribute[3].Value, -1);
  144. BuyLevel = Auxiliary.StringToInt(attribute[5].Value, 0);
  145. BuyCurrent = Auxiliary.CurrentParse(attribute[6].Value);
  146. BuyAmt = Auxiliary.StringToDouble(attribute[7].Value, 0);
  147. BuyAdvanceCurrent = Auxiliary.CurrentParse(attribute[8].Value);
  148. BuyAdvanceAmt = Auxiliary.StringToDouble(attribute[9].Value, 0);
  149. PixelSize = Auxiliary.StringToInt(attribute[10].Value, 100);
  150. IconOffset = Auxiliary.StringToFloat(attribute[11].Value, 0);
  151. IconOffset1 = Auxiliary.StringToVector(',', attribute[12].Value, new Vector3());
  152. IconOffset2 = Auxiliary.StringToVector(',', attribute[13].Value, new Vector3());
  153. Sprites = SpriteParse(attribute[14].Value);
  154. SpriteAlpha = Auxiliary.StringToFloat(attribute[15].Value, 1);
  155. ExtraBodyParts = BodyPartParses(attribute[17].Value);
  156. ExtraArmatureNames = Auxiliary.StringToStrings(',', attribute[18].Value, new List<string>()).ToArray();
  157. CreateItem();
  158. }
  159. protected void CreateItem()
  160. {
  161. Transform = ResourceManager.Get(ResourceLabel.CloseItem, Folder.UI, false, ResourceManager.Get(ObjectLabel.Canvas), false);
  162. if (Type == CloseType.Top)
  163. {
  164. Transform.SetParent(ResourceManager.Get(ObjectLabel.Pb_TopGrid));
  165. }
  166. else if (Type == CloseType.Hair)
  167. {
  168. Transform.SetParent(ResourceManager.Get(ObjectLabel.Pa_HairGrid));
  169. }
  170. else if (Type == CloseType.Dress)
  171. {
  172. Transform.SetParent(ResourceManager.Get(ObjectLabel.Pc_DressGrid));
  173. }
  174. else if (Type == CloseType.Wing)
  175. {
  176. Transform.SetParent(ResourceManager.Get(ObjectLabel.Pe_WingGrid));
  177. }
  178. else if (Type == CloseType.Decarator)
  179. {
  180. Transform.SetParent(ResourceManager.Get(ObjectLabel.Pd_DecaratorGrid));
  181. }
  182. else if (Type == CloseType.Shoe)
  183. {
  184. Transform.SetParent(ResourceManager.Get(ObjectLabel.Pf_ShoeGrid));
  185. }
  186. else
  187. {
  188. throw new Exception();
  189. }
  190. Transform.SetSiblingIndex(Index);
  191. Auxiliary.CompileDic(Transform, ChildDic);
  192. Icon1 = ChildDic[CloseItemLabel.Icon1].GetComponent<Image>();
  193. Icon2 = ChildDic[CloseItemLabel.Icon2].GetComponent<Image>();
  194. Icon3 = ChildDic[CloseItemLabel.Icon3].GetComponent<Image>();
  195. DressBtn = ChildDic[CloseItemLabel.CloseItem].GetComponent<Button>();
  196. BuyBtn = ChildDic[CloseItemLabel.BuyBtn].GetComponent<Button>();
  197. BuyBtnLab = ChildDic[CloseItemLabel.BuyBtnLab].GetComponent<Text>();
  198. BuyBtnLab.GetComponent<TextPlus>().SetY = true;
  199. float newSize = PixelSize / Sprites[0].rect.width;
  200. SetUpUI(newSize, new Vector2(), Icon1, Icon2, Icon3);
  201. if (BuyCurrent != Current.Free)
  202. {
  203. BuyBtnLab.text = Auxiliary.ImageParse(BuyCurrent) + Auxiliary.ShrinkNumberStr(BuyAmt);
  204. }
  205. if (BuyLevel > Manager.Level)
  206. {
  207. BuyBtn.interactable = false;
  208. BuyBtn.image.material = Lib.GrayMat;
  209. }
  210. BuyBtn.onClick.AddListener
  211. (
  212. () =>
  213. {
  214. AudioManager.PlayClip(AudioLabel.ClickButton);
  215. ResourceManager.Get(ObjectLabel.Pa_Info).TweenForCG();
  216. SetUpUI(newSize, new Vector2(0, 22), ResourceManager.Get<Image>(ObjectLabel.Pa_Icon1), ResourceManager.Get<Image>(ObjectLabel.Pa_Icon3), ResourceManager.Get<Image>(ObjectLabel.Pa_Icon2));
  217. ResourceManager.SetText(ObjectLabel.Pa_Lab, Name);
  218. ResourceManager.SetText(ObjectLabel.Pa_BtnLab, Language.GetStr(LanguageLabel.UI__Pa_BtnLab) + Auxiliary.ImageParse(BuyCurrent) + BuyAmt);
  219. ResourceManager.SetButtonEvent
  220. (
  221. ObjectLabel.Pa_Btn,
  222. OnBuy
  223. );
  224. }
  225. );
  226. DressBtn.onClick.AddListener
  227. (
  228. () =>
  229. {
  230. AudioManager.PlayClip(AudioLabel.ClickButton);
  231. if (BuyLevel > Manager.Level)
  232. {
  233. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__P_Unlock));
  234. return;
  235. }
  236. ChangeDress(PlayerManager.Player);
  237. }
  238. );
  239. }
  240. protected Sprite[] SpriteParse(string str)
  241. {
  242. string[] spriteNames = str.Split(',');
  243. Sprite[] sprites = new Sprite[spriteNames.Length];
  244. for (int i = 0; i < spriteNames.Length; i++)
  245. {
  246. if (!PlayerManager.CloseSpriteDic.ContainsKey(spriteNames[i]))
  247. {
  248. Debug.Log(spriteNames[i]);
  249. }
  250. sprites[i] = PlayerManager.CloseSpriteDic[spriteNames[i]];
  251. }
  252. return sprites;
  253. }
  254. protected BodyPart BodyPartParse(string str)
  255. {
  256. int type = Auxiliary.StringToInt(str, -1);
  257. if (type == 1)
  258. {
  259. return BodyPart.Head;
  260. }
  261. else if (type == 2)
  262. {
  263. return BodyPart.Dress;
  264. }
  265. else if (type == 3)
  266. {
  267. return BodyPart.Shoe;
  268. }
  269. else if (type == 4)
  270. {
  271. return BodyPart.Headwear;
  272. }
  273. else if (type == 5)
  274. {
  275. return BodyPart.Top;
  276. }
  277. else if (type == 6)
  278. {
  279. return BodyPart.Wing;
  280. }
  281. else if (type == 7)
  282. {
  283. return BodyPart.LeftLongSleeve;
  284. }
  285. else if (type == 8)
  286. {
  287. return BodyPart.RightLongSleeve;
  288. }
  289. else if (type == 9)
  290. {
  291. return BodyPart.LeftShortSleeve;
  292. }
  293. else if (type == 10)
  294. {
  295. return BodyPart.RightShortSleeve;
  296. }
  297. else if (type == 11)
  298. {
  299. return BodyPart.Eye;
  300. }
  301. else if (type == 12)
  302. {
  303. return BodyPart.Mouse;
  304. }
  305. else
  306. {
  307. throw new Exception();
  308. }
  309. }
  310. protected BodyPart[] BodyPartParses(string str)
  311. {
  312. List<string> typeIDs = Auxiliary.StringToStrings(',', str, new List<string>());
  313. BodyPart[] bodyParts = new BodyPart[typeIDs.Count];
  314. for (int i = 0; i < typeIDs.Count; i++)
  315. {
  316. bodyParts[i] = BodyPartParse(typeIDs[i]);
  317. }
  318. return bodyParts;
  319. }
  320. protected CloseType TypeParse(string str)
  321. {
  322. int type = Auxiliary.StringToInt(str, -1);
  323. if (type == 1)
  324. {
  325. return CloseType.Hair;
  326. }
  327. else if (type == 2)
  328. {
  329. return CloseType.Top;
  330. }
  331. else if (type == 3)
  332. {
  333. return CloseType.Dress;
  334. }
  335. else if (type == 4)
  336. {
  337. return CloseType.Decarator;
  338. }
  339. else if (type == 5)
  340. {
  341. return CloseType.Wing;
  342. }
  343. else if (type == 6)
  344. {
  345. return CloseType.Shoe;
  346. }
  347. else
  348. {
  349. throw new Exception();
  350. }
  351. }
  352. public void SetUpUI(float newSize, Vector2 offset, Image icon1, Image icon2, Image icon3)
  353. {
  354. icon1.SetActive(false);
  355. icon3.SetActive(false);
  356. icon2.SetActive(true);
  357. icon2.sprite = Sprites[0];
  358. icon2.Resize(true, new Vector2(newSize, newSize));
  359. icon2.SetAlpha(SpriteAlpha);
  360. icon2.transform.localPosition = offset + new Vector2(0, IconOffset);
  361. if (Sprites.Length >= 2)
  362. {
  363. icon1.SetActive(true);
  364. icon1.sprite = Sprites[1];
  365. icon1.Resize(true, new Vector2(newSize, newSize));
  366. icon1.SetAlpha(SpriteAlpha);
  367. icon1.transform.localPosition = IconOffset1 * newSize + offset + new Vector2(0, IconOffset);
  368. }
  369. if (Sprites.Length >= 3)
  370. {
  371. icon3.SetActive(true);
  372. icon3.sprite = Sprites[2];
  373. icon3.Resize(true, new Vector2(newSize, newSize));
  374. icon3.SetAlpha(SpriteAlpha);
  375. icon3.transform.localPosition = IconOffset2 * newSize + offset + new Vector2(0, IconOffset);
  376. }
  377. }
  378. public void Unlock()
  379. {
  380. if (Ignore)
  381. {
  382. return;
  383. }
  384. Possess = true;
  385. BuyBtn.interactable = false;
  386. BuyBtn.image.material = Lib.GrayMat;
  387. BuyBtnLab.text = Language.GetStr(LanguageLabel.UI__P_BtnLab2);
  388. Manager.CloseAmt++;
  389. }
  390. public void OnBuy()
  391. {
  392. Manager.Pay
  393. (
  394. "",
  395. BuyAmt,
  396. BuyCurrent,
  397. () =>
  398. {
  399. OnBuySucceed();
  400. ResourceManager.Get(ObjectLabel.Pa_Info).TweenBacCG();
  401. ChangeDress(PlayerManager.Player);
  402. SaveDressData();
  403. },
  404. StaticsManager.ItemID.解锁服装,
  405. StaticsManager.ConsumeModule.Shop,
  406. true,
  407. false,
  408. () =>
  409. {
  410. PlayerManager.Player.Reset();
  411. TweenRoot tweenRoot = ResourceManager.Get(ObjectLabel.Pa_Info).TweenBacCG();
  412. tweenRoot.AddEventOnetime
  413. (
  414. EventType.BackwardFinish,
  415. () =>
  416. {
  417. PlayerManager.Player.Return();
  418. }
  419. );
  420. ResourceManager.Get(ObjectLabel.B_SignIn0).GetTweenCG().AddEventOnetime
  421. (
  422. EventType.ForwardFinish,
  423. () =>
  424. {
  425. ResourceManager.Get(ObjectLabel.F_Manage0).TweenForVec();
  426. }
  427. );
  428. }
  429. );
  430. }
  431. public void OnBuySucceed()
  432. {
  433. Unlock();
  434. AudioManager.PlayClip(AudioLabel.GetCurrent);
  435. PlayerManager.BoughtCloseList.UniqueAdd(id);
  436. HttpManager.Save();
  437. }
  438. public void ChangeDress(Player player)
  439. {
  440. player.ChangeClose(BodyPart, ArmatureName);
  441. if (Ignore)
  442. {
  443. return;
  444. }
  445. if (ExtraBodyParts.Length > 0)
  446. {
  447. player.ChangeClose(BodyPart.LeftLongSleeve, "Empty");
  448. player.ChangeClose(BodyPart.LeftShortSleeve, "Empty");
  449. player.ChangeClose(BodyPart.RightLongSleeve, "Empty");
  450. player.ChangeClose(BodyPart.RightShortSleeve, "Empty");
  451. }
  452. for (int i = 0; i < ExtraArmatureNames.Length; i++)
  453. {
  454. player.ChangeClose(ExtraBodyParts[i], ExtraArmatureNames[i]);
  455. }
  456. }
  457. public void SaveDressData() //仅在购买完成时调用
  458. {
  459. SaveDressData(BodyPart);
  460. if (BodyPart == BodyPart.Top)
  461. {
  462. PlayerManager.DressData[8] = "Empty";
  463. PlayerManager.DressData[9] = "Empty";
  464. PlayerManager.DressData[10] = "Empty";
  465. PlayerManager.DressData[11] = "Empty";
  466. foreach (var bodyPart in ExtraBodyParts)
  467. {
  468. SaveDressData(bodyPart);
  469. }
  470. }
  471. }
  472. public void SaveDressData(BodyPart bodyPart) //仅在购买完成时调用
  473. {
  474. if (bodyPart == BodyPart.LeftLongSleeve)
  475. {
  476. PlayerManager.DressData[8] = PlayerManager.Player.LeftLongSleeve;
  477. }
  478. else if (bodyPart == BodyPart.LeftShortSleeve)
  479. {
  480. PlayerManager.DressData[9] = PlayerManager.Player.LeftShortSleeve;
  481. }
  482. else if (bodyPart == BodyPart.RightLongSleeve)
  483. {
  484. PlayerManager.DressData[10] = PlayerManager.Player.RightLongSleeve;
  485. }
  486. else if (bodyPart == BodyPart.RightShortSleeve)
  487. {
  488. PlayerManager.DressData[11] = PlayerManager.Player.RightShortSleeve;
  489. }
  490. else if (bodyPart == BodyPart.Top)
  491. {
  492. PlayerManager.DressData[4] = PlayerManager.Player.Top;
  493. }
  494. else if (bodyPart == BodyPart.Shoe)
  495. {
  496. PlayerManager.DressData[2] = PlayerManager.Player.Shoe;
  497. }
  498. else if (bodyPart == BodyPart.Head)
  499. {
  500. PlayerManager.DressData[0] = PlayerManager.Player.Head;
  501. }
  502. else if (bodyPart == BodyPart.Wing)
  503. {
  504. PlayerManager.DressData[7] = PlayerManager.Player.Wing;
  505. }
  506. else if (bodyPart == BodyPart.Dress)
  507. {
  508. PlayerManager.DressData[1] = PlayerManager.Player.Dress;
  509. }
  510. else if (bodyPart == BodyPart.Headwear)
  511. {
  512. PlayerManager.DressData[3] = PlayerManager.Player.HeadWear;
  513. }
  514. else
  515. {
  516. throw new Exception();
  517. }
  518. }
  519. public void OnLevelChange()
  520. {
  521. if (Ignore)
  522. {
  523. return;
  524. }
  525. if (Possess)
  526. {
  527. return;
  528. }
  529. if (BuyLevel < Manager.Level)
  530. {
  531. BuyBtn.interactable = true;
  532. BuyBtn.image.material = null;
  533. }
  534. }
  535. public ExchangeInfo GetExchangeValue(float rate, StaticsManager.ConsumeModule consumeModule)
  536. {
  537. ExchangeInfo info = ExchangeInfo.GetExchangeInfo(BuyCurrent, BuyAmt, rate);
  538. ExchangeInfo.GetExchangeValue(info, consumeModule);
  539. return info;
  540. }
  541. }
  542. public enum PlayerDirection
  543. {
  544. Left = 0,
  545. Right = 1,
  546. }
  547. public class Player : Regist , IPointerClickHandler
  548. {
  549. #region 变量
  550. public static string IdleAnimationName = "newAnimation";
  551. public static string JumpAnimationName = "newAnimation1";
  552. public static string WalkAnimationName = "newAnimation2";
  553. public static string RunAnimationName = "newAnimation3";
  554. public static bool InDressRoom;
  555. public static float JumpFrequency;
  556. public PlayerDirection PlayerDirection
  557. {
  558. get { return playerDirection; }
  559. set
  560. {
  561. playerDirection = value;
  562. Flip(playerDirection);
  563. }
  564. }
  565. private PlayerDirection playerDirection = PlayerDirection.Left;
  566. public bool AnimLock1;
  567. public bool AnimLock2;
  568. public float JumpTime;
  569. public float JumpTimer;
  570. public MeshFilter ExpressionMeshFilter;
  571. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  572. public static Dictionary<string, Vector3> LeftExpressionPositionDictionary = new Dictionary<string, Vector3>
  573. {
  574. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  575. {"汗颜", new Vector3(0.35f, 0.91f, -0.00001f)},
  576. {"惊讶", new Vector3(0.09f, -0.07f, -0.00001f)},
  577. {"开心", new Vector3(0.1f, -0.22f, -0.00001f)},
  578. {"哭", new Vector3(0.07f, -0.64f, -0.00001f)},
  579. {"期待", new Vector3(0.04f, -0.20f, -0.00001f)},
  580. {"色咪咪", new Vector3(0.03f, -0.09f, -0.00001f)},
  581. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  582. };
  583. public static Dictionary<string, Vector3> RightExpressionPositionDictionary = new Dictionary<string, Vector3>
  584. {
  585. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  586. {"汗颜", new Vector3(-0.22f, 0.91f, -0.00001f)},
  587. {"惊讶", new Vector3(-0.09f, -0.07f, -0.00001f)},
  588. {"开心", new Vector3(-0.1f, -0.22f, -0.00001f)},
  589. {"哭", new Vector3(-0.07f, -0.64f, -0.00001f)},
  590. {"期待", new Vector3(-0.04f, -0.20f, -0.00001f)},
  591. {"色咪咪", new Vector3(-0.03f, -0.09f, -0.00001f)},
  592. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  593. };
  594. #region 换装
  595. public Transform Shadow;
  596. private Transform Pivot
  597. {
  598. get
  599. {
  600. if (pivot == null)
  601. {
  602. pivot = UAC.transform.FindChild(PlayerLabel.Pivot);
  603. }
  604. return pivot;
  605. }
  606. }
  607. private Transform pivot;
  608. public string Eye;
  609. public string Top;
  610. public string Shoe;
  611. public string Head;
  612. public string Wing;
  613. public string Dress;
  614. public string Mouse;
  615. public string HeadWear;
  616. public string LeftLongSleeve;
  617. public string LeftShortSleeve;
  618. public string RightLongSleeve;
  619. public string RightShortSleeve;
  620. private string TempClose;
  621. public DragonBones.Slot NeckSlot;
  622. public DragonBones.Slot LeftHandSlot;
  623. public DragonBones.Slot RightHandSlot;
  624. public DragonBones.Slot LeftLegSlot;
  625. public DragonBones.Slot RightLegSlot;
  626. public DragonBones.Slot LeftShortSleeveSlot;
  627. public DragonBones.Slot RightShortSleeveSlot;
  628. public DragonBones.Slot EyeSlot;
  629. public DragonBones.Slot TopSlot;
  630. public DragonBones.Slot HeadSlot;
  631. public DragonBones.Slot DressSlot;
  632. public DragonBones.Slot WingSlot;
  633. public DragonBones.Slot MouseSlot;
  634. public DragonBones.Slot LeftShoeSlot;
  635. public DragonBones.Slot RightShoeSlot;
  636. public DragonBones.Slot HeadWearSlot;
  637. public UnityArmatureComponent UAC;
  638. public UnityArmatureComponent LeftLongSleeveUAC;
  639. public UnityArmatureComponent RightLongSleeveUAC;
  640. #endregion
  641. #endregion
  642. public override bool InitAtOnce()
  643. {
  644. if (base.InitAtOnce())
  645. {
  646. return true;
  647. }
  648. enabled = true;
  649. Auxiliary.CompileDic(transform, ChildDic);
  650. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  651. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  652. Shadow = ChildDic[PlayerLabel.Shadow];
  653. Shadow.CreateStreamScale
  654. (
  655. new List<float>() {0, 0, 0},
  656. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  657. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  658. true,
  659. true,
  660. Curve.EaseOutQuad
  661. );
  662. MeshFilter meshFilter = Shadow.GetComponent<MeshFilter>();
  663. meshFilter.mesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(ResourceLabel.FlowerShadow, Folder.Scene));
  664. meshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), meshFilter.mesh.vertices.Length).ToList());
  665. Shadow.GetComponent<MeshRenderer>().sharedMaterial = UnityFactory.Materials[0];
  666. ExpressionMeshFilter = ChildDic[PlayerLabel.ExpressionMeshFilter].GetComponent<MeshFilter>();
  667. ExpressionMeshFilter.GetComponent<MeshRenderer>().sharedMaterial = UnityFactory.Materials[0];
  668. return false;
  669. }
  670. public void Update()
  671. {
  672. if (InDressRoom)
  673. {
  674. JumpTimer += Time.deltaTime;
  675. if (JumpTimer > JumpTime)
  676. {
  677. if (!AnimLock1 && !AnimLock2)
  678. {
  679. PlayAnim(JumpAnimationName);
  680. }
  681. AnimLock2 = true;
  682. }
  683. if (JumpTimer > JumpFrequency)
  684. {
  685. AnimLock2 = false;
  686. JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0f, 1f));
  687. JumpTimer = 0;
  688. }
  689. }
  690. //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  691. //{
  692. // MoveThread();
  693. //}
  694. }
  695. public void OnStart(string str, EventObject eventObject)
  696. {
  697. if (eventObject.animationState.name == JumpAnimationName)
  698. {
  699. Shadow.StreamReForScale();
  700. AnimLock1 = true;
  701. TempClose = Eye;
  702. ChangeClose(BodyPart.Eye, "眼睛表情1");
  703. }
  704. else if (eventObject.animationState.name == IdleAnimationName)
  705. {
  706. AnimLock1 = false;
  707. if (TempClose != null)
  708. {
  709. ChangeClose(BodyPart.Eye, TempClose);
  710. }
  711. }
  712. }
  713. public string CurrentAnimationName;
  714. public void PlayAnim(string animName)
  715. {
  716. if (AnimLock1)
  717. {
  718. return;
  719. }
  720. if (UAC.anim.lastAnimationName == animName)
  721. {
  722. return;
  723. }
  724. if (SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
  725. {
  726. CurrentAnimationName = animName;
  727. }
  728. UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
  729. }
  730. public float GetFadeInTime(string lastAnimation, string targetAnimation)
  731. {
  732. if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
  733. return -1f;
  734. else
  735. return 0.1f;
  736. //throw new Exception();
  737. }
  738. public void SetAllCollider(bool enable)
  739. {
  740. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  741. for (int i = 0; i < colliders.Length; i++)
  742. {
  743. colliders[i].enabled = enable;
  744. }
  745. }
  746. public void OnPointerClick(PointerEventData eventData)
  747. {
  748. AudioManager.PlayClip(AudioLabel.GetCurrent);
  749. PlayAnim(JumpAnimationName);
  750. }
  751. public void ResetExpression()
  752. {
  753. ExpressionMeshFilter.SetActive(false);
  754. EyeSlot.UnityTransform.GetChild(0).SetActive(true);
  755. MouseSlot.UnityTransform.GetChild(0).SetActive(true);
  756. }
  757. private string ExpressionName;
  758. private Coroutine ResetExpressionCoroutine;
  759. public void ChangeExpression(string expressionName, float duration)
  760. {
  761. ExpressionName = expressionName;
  762. ExpressionMeshFilter.sharedMesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(expressionName, Folder.Scene));
  763. ExpressionMeshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), ExpressionMeshFilter.mesh.vertices.Length).ToList());
  764. ExpressionMeshFilter.transform.parent = EyeSlot.UnityTransform;
  765. ExpressionMeshFilter.SetActive(true);
  766. EyeSlot.UnityTransform.GetChild(0).SetActive(false);
  767. MouseSlot.UnityTransform.GetChild(0).SetActive(false);
  768. FlipExpression(expressionName, PlayerDirection);
  769. if (ResetExpressionCoroutine != null)
  770. Auxiliary.Instance.StopCoroutine(ResetExpressionCoroutine);
  771. ResetExpressionCoroutine = Auxiliary.Instance.DelayCall
  772. (
  773. () =>
  774. {
  775. ResetExpression();
  776. },
  777. duration
  778. );
  779. }
  780. public void Flip(PlayerDirection direction)
  781. {
  782. FlipExpression(ExpressionName, direction);
  783. if (direction == PlayerDirection.Left)
  784. {
  785. UAC.armature.flipX = false;
  786. playerDirection = PlayerDirection.Left;
  787. }
  788. else if (direction == PlayerDirection.Right)
  789. {
  790. UAC.armature.flipX = true;
  791. playerDirection = PlayerDirection.Right;
  792. }
  793. else
  794. {
  795. throw new Exception();
  796. }
  797. DelayCall.Call(1, () => Shadow.SetX(Pivot.position.x));
  798. }
  799. public void FlipExpression(string expressionName, PlayerDirection direction)
  800. {
  801. if (string.IsNullOrEmpty(ExpressionName))
  802. {
  803. return;
  804. }
  805. if (direction == PlayerDirection.Left)
  806. {
  807. ExpressionMeshFilter.transform.eulerAngles = new Vector3();
  808. ExpressionMeshFilter.transform.localPosition = LeftExpressionPositionDictionary[ExpressionName];
  809. }
  810. else if (direction == PlayerDirection.Right)
  811. {
  812. UAC.armature.flipX = true;
  813. ExpressionMeshFilter.transform.eulerAngles = new Vector3(0, 180, 0);
  814. ExpressionMeshFilter.transform.localPosition = RightExpressionPositionDictionary[ExpressionName];
  815. playerDirection = PlayerDirection.Right;
  816. }
  817. else
  818. {
  819. throw new Exception();
  820. }
  821. }
  822. public void Save(bool showNavigate)
  823. {
  824. AudioManager.PlayClip(AudioLabel.ClickButton);
  825. List<CloseItem> closeUnitList = new List<CloseItem>();
  826. closeUnitList.Add(PlayerManager.CloseItemDic[PlayerManager.CloseIDDic[Head]]);
  827. closeUnitList.Add(PlayerManager.CloseItemDic[PlayerManager.CloseIDDic[Dress]]);
  828. closeUnitList.Add(PlayerManager.CloseItemDic[PlayerManager.CloseIDDic[Shoe]]);
  829. closeUnitList.Add(PlayerManager.CloseItemDic[PlayerManager.CloseIDDic[HeadWear]]);
  830. closeUnitList.Add(PlayerManager.CloseItemDic[PlayerManager.CloseIDDic[Top]]);
  831. if (Wing != "Empty")
  832. {
  833. closeUnitList.Add(PlayerManager.CloseItemDic[PlayerManager.CloseIDDic[Wing]]);
  834. }
  835. for (int i = 0; i < closeUnitList.Count; i++)
  836. {
  837. if (!closeUnitList[i].Possess)
  838. {
  839. if (showNavigate)
  840. {
  841. BuyNavigate(closeUnitList);
  842. }
  843. return;
  844. }
  845. }
  846. PlayerManager.DressData[0] = Head;
  847. PlayerManager.DressData[1] = Dress;
  848. PlayerManager.DressData[2] = Shoe;
  849. PlayerManager.DressData[3] = HeadWear;
  850. PlayerManager.DressData[4] = Top;
  851. PlayerManager.DressData[7] = Wing;
  852. PlayerManager.DressData[8] = LeftLongSleeve;
  853. PlayerManager.DressData[9] = LeftShortSleeve;
  854. PlayerManager.DressData[10] = RightLongSleeve;
  855. PlayerManager.DressData[11] = RightShortSleeve;
  856. }
  857. public void Reset()
  858. {
  859. AudioManager.PlayClip(AudioLabel.ClickButton);
  860. List<string> dressData = new List<string>(PlayerManager.DressData);
  861. dressData[5] = Eye;
  862. PlayerManager.BuildPlayer(dressData);
  863. }
  864. public void Return()
  865. {
  866. bool allSave = true;
  867. bool allBought = true;
  868. List<string> currentDerssData = new List<string>() {Head, Dress, Shoe, HeadWear, Top, Wing};
  869. for (int i = 0; i < currentDerssData.Count; i++)
  870. {
  871. if (!PlayerManager.CloseIDDic.ContainsKey(currentDerssData[i]))
  872. {
  873. continue;
  874. }
  875. int id = PlayerManager.CloseIDDic[currentDerssData[i]];
  876. allBought = allBought && PlayerManager.CloseItemDic[id].Possess;
  877. //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
  878. allSave = allSave && currentDerssData[i] == PlayerManager.DressData[i];
  879. }
  880. if (allBought)
  881. {
  882. if (allSave)
  883. {
  884. ExitDressRoom();
  885. }
  886. else
  887. {
  888. Reset();
  889. ExitDressRoom();
  890. }
  891. }
  892. else
  893. {
  894. Bubble.Show
  895. (
  896. null, Language.GetStr(LanguageLabel.UI__P_Return), null, null,
  897. () =>
  898. {
  899. Reset();
  900. ResourceManager.Get(ObjectLabel.K_Bubble).GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  901. }
  902. );
  903. }
  904. }
  905. public void BuyNavigate(List<CloseItem> closeUnitList)
  906. {
  907. for (int i = 0; i < closeUnitList.Count; i++)
  908. {
  909. if (closeUnitList[i].Possess)
  910. {
  911. closeUnitList.RemoveAt(i--);
  912. }
  913. else
  914. {
  915. closeUnitList[i].BuyBtn.onClick.Invoke();
  916. closeUnitList.RemoveAt(i--);
  917. ResourceManager.Get(ObjectLabel.Pa_Info).GetTweenCG().AddEventOnetime
  918. (
  919. EventType.BackwardFinish,
  920. () =>
  921. {
  922. if (closeUnitList.Count == 0)
  923. {
  924. Save(false);
  925. }
  926. else
  927. {
  928. BuyNavigate(closeUnitList);
  929. }
  930. }
  931. );
  932. return;
  933. }
  934. }
  935. }
  936. public void ExitDressRoom()
  937. {
  938. Manager.SceneSwitchLock = false;
  939. TweenRoot tweenRoot = ResourceManager.Get(ObjectLabel.I_BlackMask).TweenBacCG();
  940. tweenRoot.AddEventOnetime
  941. (
  942. EventType.BackwardFinish,
  943. () =>
  944. {
  945. transform.SetParent(ResourceManager.Get(GardenLabel.GardenNormal));
  946. transform.position = ResourceManager.Get(GardenLabel.PlayerPosTra).position;
  947. transform.localScale = ResourceManager.Get(GardenLabel.PlayerPosTra).lossyScale;
  948. ResourceManager.Get(ResourceLabel.Garden).TweenForSr();
  949. ResourceManager.Get(DressroomLabel.DressRoom).TweenBacSr();
  950. ResourceManager.Get(ObjectLabel.C_Main).TweenForCG();
  951. ResourceManager.Get(ObjectLabel.P_DressRoom).TweenBacCG();
  952. }
  953. );
  954. tweenRoot = ResourceManager.Get(ObjectLabel.P_DressRoom).GetTweenCG();
  955. tweenRoot.AddEventOnetime
  956. (
  957. EventType.BackwardFinish,
  958. () =>
  959. {
  960. SetAllCollider(true);
  961. InDressRoom = false;
  962. JumpTimer = 0;
  963. PlayAnim(IdleAnimationName);
  964. DeactiveShadow();
  965. ResourceManager.Get(ObjectLabel.B_SignIn0).TweenForCG();
  966. ResourceManager.Get(ObjectLabel.I_BlackMask).TweenForCG();
  967. }
  968. );
  969. }
  970. public void EnterDressRoom()
  971. {
  972. if (Manager.SceneSwitchLock)
  973. {
  974. return;
  975. }
  976. ResourceManager.Get(ObjectLabel.B_SignIn0).TweenBacCG();
  977. InDressRoom = true;
  978. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  979. Manager.SceneSwitchLock = true;
  980. ResourceManager.Get(ObjectLabel.C_Main).TweenBacCG();
  981. SetAllCollider(false);
  982. TweenRoot tweenRoot = ResourceManager.Get(ObjectLabel.I_BlackMask).TweenBacCG();
  983. tweenRoot.AddEventOnetime
  984. (
  985. EventType.BackwardFinish,
  986. () =>
  987. {
  988. GardenManager.RetrieveAllElf();
  989. IAPManager.RetrieveADChest();
  990. ActiveShadow();
  991. transform.SetParent(ResourceManager.Get(DressroomLabel.DressRoom));
  992. transform.position = ResourceManager.Get(DressroomLabel.DressRoomPos).position;
  993. transform.localScale = ResourceManager.Get(DressroomLabel.DressRoomPos).lossyScale;
  994. ResourceManager.Get(ResourceLabel.Garden).TweenBacSr();
  995. ResourceManager.Get(DressroomLabel.DressRoom).TweenForSr();
  996. ResourceManager.Get(ObjectLabel.P_DressRoom).TweenForCG();
  997. }
  998. );
  999. tweenRoot = ResourceManager.Get(ObjectLabel.P_DressRoom).GetTweenCG();
  1000. tweenRoot.AddEventOnetime
  1001. (
  1002. EventType.ForwardFinish,
  1003. () =>
  1004. {
  1005. ResourceManager.Get(ObjectLabel.I_BlackMask).TweenForCG();
  1006. }
  1007. );
  1008. }
  1009. public void ActiveShadow()
  1010. {
  1011. ChildDic[PlayerLabel.ShadowParent].SetActive(true);
  1012. ChildDic[PlayerLabel.ShadowParent].SetLZ(3);
  1013. }
  1014. public void DeactiveShadow()
  1015. {
  1016. Shadow.GetStreamScale().Pause();
  1017. Shadow.GetStreamScale().InOrigin = true;
  1018. ChildDic[PlayerLabel.ShadowParent].SetActive(false);
  1019. }
  1020. #region 换装
  1021. public void CorrectPivot()
  1022. {
  1023. List<Transform> children = new List<Transform>();
  1024. while (transform.childCount > 0)
  1025. {
  1026. children.Add(transform.GetChild(0));
  1027. children.Back(0).parent = null;
  1028. }
  1029. Vector3 offset = Pivot.position - transform.position;
  1030. children[0].position += offset;
  1031. children[1].position += offset;
  1032. transform.position += offset;
  1033. foreach (var collider in GetComponents<BoxCollider2D>())
  1034. {
  1035. collider.offset -= new Vector2(offset.x, offset.y);
  1036. }
  1037. for (int i = 0; i < children.Count; i++)
  1038. {
  1039. children[i].parent = transform;
  1040. }
  1041. }
  1042. public UnityArmatureComponent Build()
  1043. {
  1044. if (!PlayerManager.Complete)
  1045. {
  1046. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  1047. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex, Folder.Config), ResourceLabel.StandTexture);
  1048. PlayerManager.Complete = true;
  1049. }
  1050. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  1051. UAC.transform.parent = transform;
  1052. UAC.transform.localScale = new Vector3(1, 1, 1);
  1053. UAC.transform.localPosition = new Vector3();
  1054. UAC.anim.Play(IdleAnimationName);
  1055. UAC.AddEventListener(EventObject.START, OnStart);
  1056. Eye = "眼睛1";
  1057. Top = "上衣1";
  1058. Shoe = "鞋子1";
  1059. Head = "脑壳1";
  1060. Wing = "Empty";
  1061. Dress = "裙子1";
  1062. Mouse = "嘴巴1";
  1063. HeadWear = "头饰品1";
  1064. NeckSlot = UAC.armature.GetSlot("脖子");
  1065. LeftHandSlot = UAC.armature.GetSlot("左手");
  1066. RightHandSlot = UAC.armature.GetSlot("右手");
  1067. LeftLegSlot = UAC.armature.GetSlot("左腿");
  1068. RightLegSlot = UAC.armature.GetSlot("右腿");
  1069. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  1070. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  1071. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  1072. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  1073. EyeSlot = UAC.armature.GetSlot("眼睛");
  1074. TopSlot = UAC.armature.GetSlot("上衣");
  1075. HeadSlot = UAC.armature.GetSlot("脑壳");
  1076. WingSlot = UAC.armature.GetSlot("翅膀");
  1077. DressSlot = UAC.armature.GetSlot("裙子");
  1078. MouseSlot = UAC.armature.GetSlot("嘴巴");
  1079. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  1080. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  1081. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  1082. ChangeClose(BodyPart.Eye, "眼睛1", false);
  1083. ChangeClose(BodyPart.Top, "上衣1", false);
  1084. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  1085. ChangeClose(BodyPart.Head, "脑壳1", false);
  1086. ChangeClose(BodyPart.Dress, "裙子1", false);
  1087. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  1088. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  1089. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  1090. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  1091. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  1092. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  1093. CorrectPivot();
  1094. return UAC;
  1095. }
  1096. public UnityArmatureComponent BuildPink()
  1097. {
  1098. Build();
  1099. ChangeClose(BodyPart.Eye, "眼睛3", false);
  1100. ChangeClose(BodyPart.Top, "上衣3", false);
  1101. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  1102. ChangeClose(BodyPart.Head, "脑壳3", false);
  1103. ChangeClose(BodyPart.Wing, "Empty", false);
  1104. ChangeClose(BodyPart.Dress, "裙子3", false);
  1105. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  1106. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  1107. ResetDepth();
  1108. return UAC;
  1109. }
  1110. public UnityArmatureComponent BuildBlond()
  1111. {
  1112. Build();
  1113. ChangeClose(BodyPart.Wing, "Empty", false);
  1114. ResetDepth();
  1115. return UAC;
  1116. }
  1117. public UnityArmatureComponent BuildBrown()
  1118. {
  1119. Build();
  1120. ChangeClose(BodyPart.Eye, "眼睛2", false);
  1121. ChangeClose(BodyPart.Top, "上衣2", false);
  1122. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  1123. ChangeClose(BodyPart.Head, "脑壳2", false);
  1124. ChangeClose(BodyPart.Wing, "Empty", false);
  1125. ChangeClose(BodyPart.Dress, "裙子2", false);
  1126. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  1127. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  1128. ResetDepth();
  1129. return UAC;
  1130. }
  1131. public void ResetDepth()
  1132. {
  1133. UAC.transform.SetLZ(2.5f);
  1134. WingSlot.UnityTransform.SetLZ(0);
  1135. EyeSlot.UnityTransform.SetLZ(0);
  1136. TopSlot.UnityTransform.SetLZ(0);
  1137. MouseSlot.UnityTransform.SetLZ(0);
  1138. HeadWearSlot.UnityTransform.SetLZ(0);
  1139. LeftShoeSlot.UnityTransform.SetLZ(0);
  1140. RightShoeSlot.UnityTransform.SetLZ(0);
  1141. LeftLegSlot.UnityTransform.SetLZ(0);
  1142. RightLegSlot.UnityTransform.SetLZ(0);
  1143. NeckSlot.UnityTransform.SetLZ(0);
  1144. LeftHandSlot.UnityTransform.SetLZ(0);
  1145. RightHandSlot.UnityTransform.SetLZ(0);
  1146. LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  1147. RightShortSleeveSlot.UnityTransform.SetLZ(0);
  1148. WingSlot.SetLZ(0.00003f);
  1149. EyeSlot.SetLZ(-0.00001f);
  1150. TopSlot.SetLZ(-0.00003f);
  1151. MouseSlot.SetLZ(-0.00001f);
  1152. HeadWearSlot.SetLZ(-0.00001f);
  1153. HeadSlot.UnityTransform.SetLZ(0);
  1154. if (HeadSlot.UnityTransform.childCount > 1)
  1155. {
  1156. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1157. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1158. }
  1159. DressSlot.UnityTransform.SetLZ(-0.00002f);
  1160. if (DressSlot.UnityTransform.childCount > 1)
  1161. {
  1162. DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1163. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1164. }
  1165. LeftShoeSlot.SetLZ(-0.00001f);
  1166. RightShoeSlot.SetLZ(-0.00001f);
  1167. LeftLegSlot.SetLZ(0);
  1168. RightLegSlot.SetLZ(0);
  1169. NeckSlot.SetLZ(0.00001f);
  1170. LeftHandSlot.SetLZ(-0.00001f);
  1171. RightHandSlot.SetLZ(-0.00001f);
  1172. LeftShortSleeveSlot.SetLZ(-0.000015f);
  1173. RightShortSleeveSlot.SetLZ(-0.000015f);
  1174. LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1175. RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1176. }
  1177. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  1178. {
  1179. // Debug.Log (bodyPart + " " + armatureName);
  1180. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  1181. if (bodyPart == BodyPart.Eye)
  1182. {
  1183. Eye = armatureName;
  1184. slotList.Add(EyeSlot);
  1185. }
  1186. else if (bodyPart == BodyPart.Top)
  1187. {
  1188. Top = armatureName;
  1189. slotList.Add(TopSlot);
  1190. }
  1191. else if (bodyPart == BodyPart.Shoe)
  1192. {
  1193. Shoe = armatureName;
  1194. slotList.Add(LeftShoeSlot);
  1195. slotList.Add(RightShoeSlot);
  1196. }
  1197. else if (bodyPart == BodyPart.Head)
  1198. {
  1199. Head = armatureName;
  1200. slotList.Add(HeadSlot);
  1201. }
  1202. else if (bodyPart == BodyPart.Wing)
  1203. {
  1204. if (Wing == armatureName)
  1205. {
  1206. return;
  1207. }
  1208. else
  1209. {
  1210. Wing = armatureName;
  1211. slotList.Add(WingSlot);
  1212. }
  1213. }
  1214. else if (bodyPart == BodyPart.Dress)
  1215. {
  1216. Dress = armatureName;
  1217. slotList.Add(DressSlot);
  1218. }
  1219. else if (bodyPart == BodyPart.Mouse)
  1220. {
  1221. Mouse = armatureName;
  1222. slotList.Add(MouseSlot);
  1223. }
  1224. else if (bodyPart == BodyPart.Headwear)
  1225. {
  1226. HeadWear = armatureName;
  1227. slotList.Add(HeadWearSlot);
  1228. }
  1229. else if (bodyPart == BodyPart.Leg)
  1230. {
  1231. slotList.Add(LeftLegSlot);
  1232. slotList.Add(RightLegSlot);
  1233. }
  1234. else if (bodyPart == BodyPart.LeftHand)
  1235. {
  1236. slotList.Add(LeftHandSlot);
  1237. }
  1238. else if (bodyPart == BodyPart.RightHand)
  1239. {
  1240. slotList.Add(RightHandSlot);
  1241. }
  1242. else if (bodyPart == BodyPart.Neck)
  1243. {
  1244. slotList.Add(NeckSlot);
  1245. }
  1246. else if (bodyPart == BodyPart.LeftLongSleeve)
  1247. {
  1248. LeftLongSleeve = armatureName;
  1249. ChangeClose(LeftLongSleeveUAC, armatureName);
  1250. return;
  1251. }
  1252. else if (bodyPart == BodyPart.LeftShortSleeve)
  1253. {
  1254. LeftShortSleeve = armatureName;
  1255. slotList.Add(LeftShortSleeveSlot);
  1256. }
  1257. else if (bodyPart == BodyPart.RightLongSleeve)
  1258. {
  1259. RightLongSleeve = armatureName;
  1260. ChangeClose(RightLongSleeveUAC, armatureName);
  1261. return;
  1262. }
  1263. else if (bodyPart == BodyPart.RightShortSleeve)
  1264. {
  1265. RightShortSleeve = armatureName;
  1266. slotList.Add(RightShortSleeveSlot);
  1267. }
  1268. else
  1269. {
  1270. throw new Exception();
  1271. }
  1272. ChangeClose(slotList, armatureName, setDepth);
  1273. if (bodyPart == BodyPart.Wing)
  1274. {
  1275. 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);
  1276. tweenRoot.PingPong = true;
  1277. tweenRoot.StartForward();
  1278. }
  1279. }
  1280. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1281. {
  1282. for (int i = 0; i < slotList.Count; i++)
  1283. {
  1284. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1285. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1286. }
  1287. if (setDepth)
  1288. {
  1289. ResetDepth();
  1290. }
  1291. }
  1292. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1293. {
  1294. if (armatureName == "Empty")
  1295. {
  1296. uac.SetActive(false);
  1297. }
  1298. else
  1299. {
  1300. uac.SetActive(true);
  1301. }
  1302. if (setDepth)
  1303. {
  1304. ResetDepth();
  1305. }
  1306. }
  1307. #endregion
  1308. }