Player.cs 47 KB

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