Player.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  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(null, NavigateToChargeFromDressroom);
  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.ShrinkBigNumberStr(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(Action buySucceedCallback, Action navigateAction)
  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. ResourceManager.SetButtonEvent
  405. (
  406. CanvasLabel.Pa_Btn,
  407. () => OnBuy(buySucceedCallback, navigateAction)
  408. );
  409. }
  410. public void Unlock()
  411. {
  412. if (Unavailable)
  413. {
  414. return;
  415. }
  416. IsBought = true;
  417. BuyBtn.interactable = false;
  418. BuyBtn.image.material = Lib.GrayMat;
  419. BuyBtnLab.text = Language.GetStr(LanguageLabel.UI__P_BtnLab2);
  420. Manager.CloseAmt++;
  421. }
  422. public void OnBuy(Action buySucceedCallback, Action navigateAction)
  423. {
  424. bool navigate = navigateAction != null;
  425. Manager.Pay
  426. (
  427. "",
  428. BuyCost,
  429. BuyCurrent,
  430. () =>
  431. {
  432. OnBuySucceed();
  433. ResourceManager.Get(CanvasLabel.Pa_Info).TweenBacCG();
  434. ChangeDress(PlayerManager.Player);
  435. SaveDressData();
  436. buySucceedCallback.SafeInvoke();
  437. ConfigManager.SaveConfigDocument();
  438. ConfigManager.SaveConfigDocumentToDisk();
  439. },
  440. StaticsManager.ItemID.解锁服装,
  441. StaticsManager.ConsumeModule.Shop,
  442. navigate,
  443. false,
  444. () =>
  445. {
  446. PlayerManager.Player.ResetDressDatas();
  447. navigateAction.SafeInvoke();
  448. }
  449. );
  450. }
  451. public void OnBuySucceed()
  452. {
  453. Unlock();
  454. AudioManager.PlayClip(AudioLabel.GetCurrent);
  455. PlayerManager.BoughtCloseIDs.UniqueAdd(ID);
  456. }
  457. public void NavigateToChargeFromDressroom()
  458. {
  459. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.Pa_Info).TweenBacCG();
  460. tweenRoot.AddEventOnetime
  461. (
  462. EventType.BackwardFinish,
  463. () =>
  464. {
  465. PlayerManager.Player.LeaveDressroom();
  466. }
  467. );
  468. ResourceManager.Get(CanvasLabel.B_SignIn0).GetTweenCG().AddEventOnetime
  469. (
  470. EventType.ForwardFinish,
  471. () =>
  472. {
  473. ResourceManager.Get(CanvasLabel.F_Manage0).TweenForVec();
  474. }
  475. );
  476. }
  477. public void ChangeDress(Player player, bool resetDepth = true)
  478. {
  479. player.ChangeClose(BodyPart, ArmatureName, resetDepth);
  480. if (Unavailable)
  481. {
  482. return;
  483. }
  484. if (ExtraBodyParts.Length > 0)
  485. {
  486. player.ChangeClose(BodyPart.LeftLongSleeve, "Empty", resetDepth);
  487. player.ChangeClose(BodyPart.LeftShortSleeve, "Empty", resetDepth);
  488. player.ChangeClose(BodyPart.RightLongSleeve, "Empty", resetDepth);
  489. player.ChangeClose(BodyPart.RightShortSleeve, "Empty", resetDepth);
  490. }
  491. for (int i = 0; i < ExtraArmatureNames.Length; i++)
  492. {
  493. player.ChangeClose(ExtraBodyParts[i], ExtraArmatureNames[i], resetDepth);
  494. }
  495. }
  496. public void SaveDressData() //仅在购买完成时调用
  497. {
  498. SaveDressData(BodyPart);
  499. if (BodyPart == BodyPart.Top)
  500. {
  501. PlayerManager.DressDatas[8] = "Empty";
  502. PlayerManager.DressDatas[9] = "Empty";
  503. PlayerManager.DressDatas[10] = "Empty";
  504. PlayerManager.DressDatas[11] = "Empty";
  505. foreach (var bodyPart in ExtraBodyParts)
  506. {
  507. SaveDressData(bodyPart);
  508. }
  509. }
  510. }
  511. public void SaveDressData(BodyPart bodyPart) //仅在购买完成时调用
  512. {
  513. if (bodyPart == BodyPart.LeftLongSleeve)
  514. {
  515. PlayerManager.DressDatas[8] = PlayerManager.Player.LeftLongSleeve;
  516. }
  517. else if (bodyPart == BodyPart.LeftShortSleeve)
  518. {
  519. PlayerManager.DressDatas[9] = PlayerManager.Player.LeftShortSleeve;
  520. }
  521. else if (bodyPart == BodyPart.RightLongSleeve)
  522. {
  523. PlayerManager.DressDatas[10] = PlayerManager.Player.RightLongSleeve;
  524. }
  525. else if (bodyPart == BodyPart.RightShortSleeve)
  526. {
  527. PlayerManager.DressDatas[11] = PlayerManager.Player.RightShortSleeve;
  528. }
  529. else if (bodyPart == BodyPart.Top)
  530. {
  531. PlayerManager.DressDatas[4] = PlayerManager.Player.Top;
  532. }
  533. else if (bodyPart == BodyPart.Shoe)
  534. {
  535. PlayerManager.DressDatas[2] = PlayerManager.Player.Shoe;
  536. }
  537. else if (bodyPart == BodyPart.Head)
  538. {
  539. PlayerManager.DressDatas[0] = PlayerManager.Player.Head;
  540. }
  541. else if (bodyPart == BodyPart.Wing)
  542. {
  543. PlayerManager.DressDatas[7] = PlayerManager.Player.Wing;
  544. }
  545. else if (bodyPart == BodyPart.Dress)
  546. {
  547. PlayerManager.DressDatas[1] = PlayerManager.Player.Dress;
  548. }
  549. else if (bodyPart == BodyPart.Headwear)
  550. {
  551. PlayerManager.DressDatas[3] = PlayerManager.Player.HeadWear;
  552. }
  553. else
  554. {
  555. throw new Exception();
  556. }
  557. }
  558. public void OnLevelChange()
  559. {
  560. if (Unavailable)
  561. {
  562. return;
  563. }
  564. if (IsBought)
  565. {
  566. return;
  567. }
  568. if (BuyLevel <= Manager.GardenLevel)
  569. {
  570. BuyBtn.interactable = true;
  571. BuyBtn.image.material = null;
  572. }
  573. }
  574. public ExchangeInfo GetExchangeValue(float rate, StaticsManager.ConsumeModule consumeModule)
  575. {
  576. ExchangeInfo info = ExchangeInfo.GetExchangeInfo(BuyCurrent, BuyCost, rate);
  577. ExchangeInfo.GetExchangeValue(info, consumeModule);
  578. return info;
  579. }
  580. public static List<KV<Current, KV<int, double>>> GetTotalBuyCost(bool excludeBought, List<int> closeIDs)
  581. {
  582. int coinAmount = 0;
  583. int diamondAmount = 0;
  584. double totalCoin = 0;
  585. double totalDiamond = 0;
  586. foreach (var closeID in closeIDs)
  587. {
  588. if (PlayerManager.CloseItemDictionary[closeID].Sprites == null) continue;
  589. if (PlayerManager.CloseItemDictionary[closeID].ArmatureName == "Empty") continue;
  590. CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
  591. if (closeItem.IsBought && excludeBought) continue;
  592. if (closeItem.BuyCurrent == Current.Coin)
  593. {
  594. totalCoin += closeItem.BuyCost;
  595. coinAmount++;
  596. }
  597. if (closeItem.BuyCurrent == Current.Diamond)
  598. {
  599. totalDiamond += closeItem.BuyCost;
  600. diamondAmount++;
  601. }
  602. }
  603. List<KV<Current, KV<int, double>>> results = new List<KV<Current, KV<int, double>>>();
  604. results.Add(new KV<Current, KV<int, double>>(Current.Coin, new KV<int, double>(coinAmount, totalCoin)));
  605. results.Add(new KV<Current, KV<int, double>>(Current.Diamond, new KV<int, double>(diamondAmount, totalDiamond)));
  606. return results;
  607. }
  608. }
  609. public enum PlayerDirection
  610. {
  611. Left = 0,
  612. Right = 1,
  613. }
  614. public class Player : Regist , IPointerClickHandler
  615. {
  616. #region Config
  617. public static string IdleAnimationName = "newAnimation";
  618. public static string JumpAnimationName = "newAnimation1";
  619. public static string WalkAnimationName = "newAnimation2";
  620. public static string RunAnimationName = "newAnimation3";
  621. public static bool InDressRoom;
  622. public static float InDressRoomJumpFrequency;
  623. public float JumpTime;
  624. public float JumpTimer;
  625. public PlayerDirection PlayerDirection
  626. {
  627. get { return playerDirection; }
  628. set
  629. {
  630. playerDirection = value;
  631. Flip(playerDirection);
  632. }
  633. }
  634. public PlayerDirection playerDirection = PlayerDirection.Left;
  635. public bool IsDisplayInUGUI;
  636. public float UGUIScale;
  637. public bool PlayAnimFlag1;
  638. public bool PlayAnimFlag2;
  639. public string CurrentAnimationName;
  640. public Material Material;
  641. public MeshFilter ExpressionMeshFilter;
  642. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  643. private string ExpressionName;
  644. private Coroutine ResetExpressionCoroutine;
  645. public static Dictionary<string, Vector3> LeftExpressionPositionDictionary = new Dictionary<string, Vector3>
  646. {
  647. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  648. {"汗颜", new Vector3(0.35f, 0.91f, -0.00001f)},
  649. {"惊讶", new Vector3(0.09f, -0.07f, -0.00001f)},
  650. {"开心", new Vector3(0.1f, -0.22f, -0.00001f)},
  651. {"哭", new Vector3(0.07f, -0.64f, -0.00001f)},
  652. {"期待", new Vector3(0.04f, -0.20f, -0.00001f)},
  653. {"色咪咪", new Vector3(0.03f, -0.09f, -0.00001f)},
  654. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  655. };
  656. public static Dictionary<string, Vector3> RightExpressionPositionDictionary = new Dictionary<string, Vector3>
  657. {
  658. {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
  659. {"汗颜", new Vector3(-0.22f, 0.91f, -0.00001f)},
  660. {"惊讶", new Vector3(-0.09f, -0.07f, -0.00001f)},
  661. {"开心", new Vector3(-0.1f, -0.22f, -0.00001f)},
  662. {"哭", new Vector3(-0.07f, -0.64f, -0.00001f)},
  663. {"期待", new Vector3(-0.04f, -0.20f, -0.00001f)},
  664. {"色咪咪", new Vector3(-0.03f, -0.09f, -0.00001f)},
  665. {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
  666. };
  667. #region 换装
  668. public Transform Shadow;
  669. private Transform Pivot
  670. {
  671. get
  672. {
  673. if (pivot == null)
  674. {
  675. pivot = UAC.transform.FindChild(PlayerLabel.Pivot);
  676. }
  677. return pivot;
  678. }
  679. }
  680. private Transform pivot;
  681. public string Eye;
  682. public string Top;
  683. public string Shoe;
  684. public string Head;
  685. public string Wing;
  686. public string Dress;
  687. public string Mouse;
  688. public string HeadWear;
  689. public string LeftLongSleeve;
  690. public string LeftShortSleeve;
  691. public string RightLongSleeve;
  692. public string RightShortSleeve;
  693. private string TempClose;
  694. public DragonBones.Slot NeckSlot;
  695. public DragonBones.Slot LeftHandSlot;
  696. public DragonBones.Slot RightHandSlot;
  697. public DragonBones.Slot LeftLegSlot;
  698. public DragonBones.Slot RightLegSlot;
  699. public DragonBones.Slot LeftShortSleeveSlot;
  700. public DragonBones.Slot RightShortSleeveSlot;
  701. public DragonBones.Slot EyeSlot;
  702. public DragonBones.Slot TopSlot;
  703. public DragonBones.Slot HeadSlot;
  704. public DragonBones.Slot DressSlot;
  705. public DragonBones.Slot WingSlot;
  706. public DragonBones.Slot MouseSlot;
  707. public DragonBones.Slot LeftShoeSlot;
  708. public DragonBones.Slot RightShoeSlot;
  709. public DragonBones.Slot HeadWearSlot;
  710. public UnityArmatureComponent UAC;
  711. //public UnityArmatureComponent LeftShortSleeveUAC;
  712. //public UnityArmatureComponent RightShortSleeveUAC;
  713. public UnityArmatureComponent LeftLongSleeveUAC;
  714. public UnityArmatureComponent RightLongSleeveUAC;
  715. #endregion
  716. #endregion
  717. public override bool InitAtOnce()
  718. {
  719. if (base.InitAtOnce())
  720. {
  721. return true;
  722. }
  723. enabled = true;
  724. Auxiliary.CompileDic(transform, ChildDic);
  725. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  726. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  727. Shadow = ChildDic[PlayerLabel.Shadow];
  728. Shadow.CreateStreamScale
  729. (
  730. new List<float>() {0, 0, 0},
  731. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  732. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  733. true,
  734. true,
  735. Curve.EaseOutQuad
  736. );
  737. MeshFilter meshFilter = Shadow.GetComponent<MeshFilter>();
  738. meshFilter.mesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(ResourceLabel.FlowerShadow, Folder.Scene));
  739. meshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), meshFilter.mesh.vertices.Length).ToList());
  740. return false;
  741. }
  742. public void Update()
  743. {
  744. if (InDressRoom)
  745. {
  746. JumpTimer += Time.deltaTime;
  747. if (JumpTimer > JumpTime)
  748. {
  749. if (!PlayAnimFlag1 && !PlayAnimFlag2)
  750. {
  751. PlayAnim(JumpAnimationName);
  752. }
  753. PlayAnimFlag2 = true;
  754. }
  755. if (JumpTimer > InDressRoomJumpFrequency)
  756. {
  757. PlayAnimFlag2 = false;
  758. JumpTime = Mathf.Lerp(0, InDressRoomJumpFrequency, Random.Range(0f, 1f));
  759. JumpTimer = 0;
  760. }
  761. }
  762. //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
  763. //{
  764. // MoveThread();
  765. //}
  766. }
  767. public void OnAnimStart(string str, EventObject eventObject)
  768. {
  769. if (eventObject.animationState.name == JumpAnimationName)
  770. {
  771. Shadow.StreamReForScale();
  772. PlayAnimFlag1 = true;
  773. TempClose = Eye;
  774. ChangeClose(BodyPart.Eye, "眼睛表情1");
  775. }
  776. else if (eventObject.animationState.name == IdleAnimationName)
  777. {
  778. PlayAnimFlag1 = false;
  779. if (TempClose != null)
  780. {
  781. ChangeClose(BodyPart.Eye, TempClose);
  782. }
  783. }
  784. }
  785. public void PlayAnim(string animName)
  786. {
  787. if (PlayAnimFlag1)
  788. {
  789. return;
  790. }
  791. if (UAC.anim.lastAnimationName == animName)
  792. {
  793. return;
  794. }
  795. if (SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
  796. {
  797. CurrentAnimationName = animName;
  798. }
  799. UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
  800. }
  801. public float GetFadeInTime(string lastAnimation, string targetAnimation)
  802. {
  803. if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
  804. return -1f;
  805. else
  806. return 0.1f;
  807. //throw new Exception();
  808. }
  809. public void SetAllCollider(bool enable)
  810. {
  811. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  812. for (int i = 0; i < colliders.Length; i++)
  813. {
  814. colliders[i].enabled = enable;
  815. }
  816. }
  817. public void OnPointerClick(PointerEventData eventData)
  818. {
  819. AudioManager.PlayClip(AudioLabel.GetCurrent);
  820. PlayAnim(JumpAnimationName);
  821. }
  822. public void ResetExpression()
  823. {
  824. ExpressionMeshFilter.SetActive(false);
  825. EyeSlot.UnityTransform.GetChild(0).SetActive(true);
  826. MouseSlot.UnityTransform.GetChild(0).SetActive(true);
  827. }
  828. public void ChangeExpression(string expressionName, float duration)
  829. {
  830. ExpressionName = expressionName;
  831. ExpressionMeshFilter.sharedMesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(expressionName, Folder.Scene));
  832. ExpressionMeshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), ExpressionMeshFilter.mesh.vertices.Length).ToList());
  833. ExpressionMeshFilter.transform.parent = EyeSlot.UnityTransform;
  834. ExpressionMeshFilter.SetActive(true);
  835. EyeSlot.UnityTransform.GetChild(0).SetActive(false);
  836. MouseSlot.UnityTransform.GetChild(0).SetActive(false);
  837. FlipExpression(expressionName, PlayerDirection);
  838. if (ResetExpressionCoroutine != null)
  839. Auxiliary.Instance.StopCoroutine(ResetExpressionCoroutine);
  840. ResetExpressionCoroutine = Auxiliary.Instance.DelayCall
  841. (
  842. () =>
  843. {
  844. ResetExpression();
  845. },
  846. duration
  847. );
  848. }
  849. public void Flip(PlayerDirection direction)
  850. {
  851. FlipExpression(ExpressionName, direction);
  852. if (direction == PlayerDirection.Left)
  853. {
  854. UAC.armature.flipX = false;
  855. playerDirection = PlayerDirection.Left;
  856. }
  857. else if (direction == PlayerDirection.Right)
  858. {
  859. UAC.armature.flipX = true;
  860. playerDirection = PlayerDirection.Right;
  861. }
  862. else
  863. {
  864. throw new Exception();
  865. }
  866. DelayCall.Call(1, () => Shadow.SetX(Pivot.position.x));
  867. }
  868. public void FlipExpression(string expressionName, PlayerDirection direction)
  869. {
  870. if (string.IsNullOrEmpty(ExpressionName))
  871. {
  872. return;
  873. }
  874. if (direction == PlayerDirection.Left)
  875. {
  876. ExpressionMeshFilter.transform.eulerAngles = new Vector3();
  877. ExpressionMeshFilter.transform.localPosition = LeftExpressionPositionDictionary[ExpressionName];
  878. }
  879. else if (direction == PlayerDirection.Right)
  880. {
  881. UAC.armature.flipX = true;
  882. ExpressionMeshFilter.transform.eulerAngles = new Vector3(0, 180, 0);
  883. ExpressionMeshFilter.transform.localPosition = RightExpressionPositionDictionary[ExpressionName];
  884. playerDirection = PlayerDirection.Right;
  885. }
  886. else
  887. {
  888. throw new Exception();
  889. }
  890. }
  891. public void SaveDressDatas(bool showNavigate)
  892. {
  893. AudioManager.PlayClip(AudioLabel.ClickButton);
  894. List<CloseItem> closeUnitList = new List<CloseItem>();
  895. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Head]]);
  896. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Dress]]);
  897. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Shoe]]);
  898. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[HeadWear]]);
  899. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Top]]);
  900. if (Wing != "Empty")
  901. {
  902. closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Wing]]);
  903. }
  904. for (int i = 0; i < closeUnitList.Count; i++)
  905. {
  906. if (!closeUnitList[i].IsBought)
  907. {
  908. if (showNavigate)
  909. {
  910. BuyDressNavigate(closeUnitList);
  911. }
  912. return;
  913. }
  914. }
  915. PlayerManager.DressDatas[0] = Head;
  916. PlayerManager.DressDatas[1] = Dress;
  917. PlayerManager.DressDatas[2] = Shoe;
  918. PlayerManager.DressDatas[3] = HeadWear;
  919. PlayerManager.DressDatas[4] = Top;
  920. PlayerManager.DressDatas[7] = Wing;
  921. PlayerManager.DressDatas[8] = LeftLongSleeve;
  922. PlayerManager.DressDatas[9] = LeftShortSleeve;
  923. PlayerManager.DressDatas[10] = RightLongSleeve;
  924. PlayerManager.DressDatas[11] = RightShortSleeve;
  925. Toast.Show(1.5f, Language.GetStr(LanguageLabel.UI__P_SaveSucceed));
  926. }
  927. public void ResetDressDatas()
  928. {
  929. AudioManager.PlayClip(AudioLabel.ClickButton);
  930. List<string> dressData = new List<string>(PlayerManager.DressDatas);
  931. dressData[5] = Eye;
  932. PlayerManager.BuildPlayer(dressData);
  933. }
  934. public List<int> GetCurrentChangableDressIDs()
  935. {
  936. List<int> ids = new List<int>();
  937. ids.Add(PlayerManager.CloseIDDictionary[Head]);
  938. ids.Add(PlayerManager.CloseIDDictionary[Dress]);
  939. ids.Add(PlayerManager.CloseIDDictionary[Shoe]);
  940. ids.Add(PlayerManager.CloseIDDictionary[HeadWear]);
  941. ids.Add(PlayerManager.CloseIDDictionary[Top]);
  942. ids.Add(PlayerManager.CloseIDDictionary[Wing]);
  943. ids.Add(PlayAnimFlag1 ? PlayerManager.CloseIDDictionary[TempClose] : PlayerManager.CloseIDDictionary[Eye]);
  944. ids.Add(PlayerManager.CloseIDDictionary[Mouse]);
  945. ids.Add(PlayerManager.CloseIDDictionary[Wing]);
  946. return ids;
  947. }
  948. public static List<string> DressIDToDressName(List<int> ids)
  949. {
  950. List<string> names = new List<string>();
  951. foreach (var id in ids)
  952. {
  953. names.Add(PlayerManager.CloseItemDictionary[id].ArmatureName);
  954. }
  955. return names;
  956. }
  957. public List<string> GetCurrentDressNames()
  958. {
  959. List<string> names = new List<string>();
  960. return names;
  961. }
  962. public List<string> GetCurrentChangableDressNames()
  963. {
  964. List<string> names = new List<string>();
  965. names.Add(Head);
  966. names.Add(Dress);
  967. names.Add(Shoe);
  968. names.Add(HeadWear);
  969. names.Add(Top);
  970. names.Add(Wing);
  971. if (PlayAnimFlag1) names.Add(TempClose);
  972. else names.Add(Eye);
  973. names.Add(Mouse);
  974. names.Add(Wing);
  975. return names;
  976. }
  977. public void BuyDressNavigate(List<CloseItem> closeUnitList)
  978. {
  979. for (int i = 0; i < closeUnitList.Count; i++)
  980. {
  981. if (closeUnitList[i].IsBought)
  982. {
  983. closeUnitList.RemoveAt(i--);
  984. }
  985. else
  986. {
  987. closeUnitList[i].BuyBtn.onClick.Invoke();
  988. closeUnitList.RemoveAt(i--);
  989. ResourceManager.Get(CanvasLabel.Pa_Info).GetTweenCG().AddEventOnetime
  990. (
  991. EventType.BackwardFinish,
  992. () =>
  993. {
  994. if (closeUnitList.Count == 0)
  995. {
  996. SaveDressDatas(false);
  997. }
  998. else
  999. {
  1000. BuyDressNavigate(closeUnitList);
  1001. }
  1002. }
  1003. );
  1004. return;
  1005. }
  1006. }
  1007. }
  1008. public void LeaveDressroom()
  1009. {
  1010. bool allSave = true;
  1011. bool allBought = true;
  1012. List<string> currentDerssData = new List<string>() { Head, Dress, Shoe, HeadWear, Top, Wing };
  1013. if (currentDerssData[0] != PlayerManager.DressDatas[0]) allSave = false;
  1014. if (currentDerssData[1] != PlayerManager.DressDatas[1]) allSave = false;
  1015. if (currentDerssData[2] != PlayerManager.DressDatas[2]) allSave = false;
  1016. if (currentDerssData[3] != PlayerManager.DressDatas[3]) allSave = false;
  1017. if (currentDerssData[4] != PlayerManager.DressDatas[4]) allSave = false;
  1018. if (currentDerssData[5] != PlayerManager.DressDatas[7]) allSave = false;
  1019. for (int i = 0; i < currentDerssData.Count; i++)
  1020. {
  1021. if (!PlayerManager.CloseIDDictionary.ContainsKey(currentDerssData[i]))
  1022. {
  1023. continue;
  1024. }
  1025. int id = PlayerManager.CloseIDDictionary[currentDerssData[i]];
  1026. allBought = allBought && PlayerManager.CloseItemDictionary[id].IsBought;
  1027. //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
  1028. //allSave = allSave && currentDerssData[i] == PlayerManager.DressDatas[i];
  1029. //Debug.Log(currentDerssData[i] + " " + PlayerManager.DressDatas[i]);
  1030. }
  1031. //Debug.Log(allBought);
  1032. //Debug.Log(allSave);
  1033. if (allBought)
  1034. {
  1035. if (allSave)
  1036. {
  1037. ExitDressRoom();
  1038. }
  1039. else
  1040. {
  1041. ResetDressDatas();
  1042. ExitDressRoom();
  1043. }
  1044. }
  1045. else
  1046. {
  1047. Bubble.Show
  1048. (
  1049. null, Language.GetStr(LanguageLabel.UI__P_Return), null, null,
  1050. () =>
  1051. {
  1052. ResetDressDatas();
  1053. ResourceManager.Get(CanvasLabel.K_Bubble).GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
  1054. }
  1055. );
  1056. }
  1057. }
  1058. public void ExitDressRoom()
  1059. {
  1060. Manager.SceneSwitchFlag = false;
  1061. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1062. tweenRoot.AddEventOnetime
  1063. (
  1064. EventType.BackwardFinish,
  1065. () =>
  1066. {
  1067. transform.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
  1068. transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  1069. transform.localScale = ResourceManager.Get(GardenLabel.GardenPlayerPos).lossyScale;
  1070. ResourceManager.Get(ResourceLabel.Garden).TweenForSr();
  1071. ResourceManager.Get(DressroomLabel.DressRoom).TweenBacSr();
  1072. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  1073. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenBacCG();
  1074. }
  1075. );
  1076. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1077. tweenRoot.AddEventOnetime
  1078. (
  1079. EventType.BackwardFinish,
  1080. () =>
  1081. {
  1082. SetAllCollider(true);
  1083. InDressRoom = false;
  1084. JumpTimer = 0;
  1085. PlayAnim(IdleAnimationName);
  1086. DeactiveShadow();
  1087. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenForCG();
  1088. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1089. }
  1090. );
  1091. }
  1092. public void EnterDressRoom()
  1093. {
  1094. if (Manager.SceneSwitchFlag)
  1095. {
  1096. return;
  1097. }
  1098. ResourceManager.Get(CanvasLabel.B_SignIn0).TweenBacCG();
  1099. InDressRoom = true;
  1100. JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
  1101. Manager.SceneSwitchFlag = true;
  1102. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  1103. SetAllCollider(false);
  1104. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
  1105. tweenRoot.AddEventOnetime
  1106. (
  1107. EventType.BackwardFinish,
  1108. () =>
  1109. {
  1110. GardenManager.RetrieveAllElf();
  1111. IAPManager.RetrieveADChest();
  1112. ActiveShadow();
  1113. transform.SetParent(ResourceManager.Get(DressroomLabel.DressRoom));
  1114. transform.position = ResourceManager.Get(DressroomLabel.DressRoomPos).position;
  1115. transform.localScale = ResourceManager.Get(DressroomLabel.DressRoomPos).lossyScale;
  1116. ResourceManager.Get(ResourceLabel.Garden).TweenBacSr();
  1117. ResourceManager.Get(DressroomLabel.DressRoom).TweenForSr();
  1118. ResourceManager.Get(CanvasLabel.P_DressRoom).TweenForCG();
  1119. }
  1120. );
  1121. tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
  1122. tweenRoot.AddEventOnetime
  1123. (
  1124. EventType.ForwardFinish,
  1125. () =>
  1126. {
  1127. ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
  1128. }
  1129. );
  1130. }
  1131. public void ActiveShadow()
  1132. {
  1133. ChildDic[PlayerLabel.ShadowParent].SetActive(true);
  1134. ChildDic[PlayerLabel.ShadowParent].SetLZ(3);
  1135. }
  1136. public void DeactiveShadow()
  1137. {
  1138. Shadow.GetStreamScale().Pause();
  1139. Shadow.GetStreamScale().InOrigin = true;
  1140. ChildDic[PlayerLabel.ShadowParent].SetActive(false);
  1141. }
  1142. public void DisplayInUI(float scale)
  1143. {
  1144. UGUIScale = scale;
  1145. scale *= ResourceManager.Get<Canvas>(CanvasLabel.Canvas).scaleFactor;
  1146. MeshFilter[] meshFilters = UAC.GetComponentsInChildren<MeshFilter>(true);
  1147. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1148. for (int i = 0; i < meshRenderers.Length; i++)
  1149. {
  1150. MeshFilter meshFilter = meshFilters[i];
  1151. MeshRenderer meshRenderer = meshRenderers[i];
  1152. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1153. if (unityUGUIDisplay == null) unityUGUIDisplay = meshRenderer.AddComponent<UnityUGUIDisplay>();
  1154. unityUGUIDisplay.Enable(meshFilter, meshRenderer);
  1155. unityUGUIDisplay.raycastTarget = false;
  1156. meshRenderer.enabled = false;
  1157. UAC.transform.localScale = new Vector3(scale, scale, 1);
  1158. SetAllCollider(false);
  1159. DeactiveShadow();
  1160. }
  1161. IsDisplayInUGUI = true;
  1162. ResetDepth();
  1163. }
  1164. public void DisplayInScene()
  1165. {
  1166. MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
  1167. foreach (var meshRenderer in meshRenderers)
  1168. {
  1169. UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
  1170. if (unityUGUIDisplay == null) continue;
  1171. unityUGUIDisplay.Disable();
  1172. meshRenderer.enabled = true;
  1173. UAC.transform.localScale = Vector3.one;
  1174. SetAllCollider(true);
  1175. ActiveShadow();
  1176. }
  1177. IsDisplayInUGUI = false;
  1178. ResetDepth();
  1179. }
  1180. #region 换装
  1181. public void CorrectPivot()
  1182. {
  1183. List<Transform> children = new List<Transform>();
  1184. while (transform.childCount > 0)
  1185. {
  1186. children.Add(transform.GetChild(0));
  1187. children.Back(0).parent = null;
  1188. }
  1189. Vector3 offset = Pivot.position - transform.position;
  1190. children[0].position += offset;
  1191. children[1].position += offset;
  1192. transform.position += offset;
  1193. foreach (var collider in GetComponents<BoxCollider2D>())
  1194. {
  1195. collider.offset -= new Vector2(offset.x, offset.y);
  1196. }
  1197. for (int i = 0; i < children.Count; i++)
  1198. {
  1199. children[i].parent = transform;
  1200. }
  1201. }
  1202. public UnityArmatureComponent Build()
  1203. {
  1204. if (!PlayerManager.Inited)
  1205. {
  1206. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  1207. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex, Folder.Config), ResourceLabel.StandTexture);
  1208. PlayerManager.Inited = true;
  1209. }
  1210. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  1211. UAC.transform.parent = transform;
  1212. UAC.transform.localScale = new Vector3(1, 1, 1);
  1213. UAC.transform.localPosition = new Vector3();
  1214. UAC.anim.Play(IdleAnimationName);
  1215. UAC.AddEventListener(EventObject.START, OnAnimStart);
  1216. Eye = "眼睛1";
  1217. Top = "上衣1";
  1218. Shoe = "鞋子1";
  1219. Head = "脑壳1";
  1220. Wing = "Empty";
  1221. Dress = "裙子1";
  1222. Mouse = "嘴巴1";
  1223. HeadWear = "头饰品1";
  1224. NeckSlot = UAC.armature.GetSlot("脖子");
  1225. LeftHandSlot = UAC.armature.GetSlot("左手");
  1226. RightHandSlot = UAC.armature.GetSlot("右手");
  1227. LeftLegSlot = UAC.armature.GetSlot("左腿");
  1228. RightLegSlot = UAC.armature.GetSlot("右腿");
  1229. LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
  1230. RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
  1231. LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
  1232. RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
  1233. EyeSlot = UAC.armature.GetSlot("眼睛");
  1234. TopSlot = UAC.armature.GetSlot("上衣");
  1235. HeadSlot = UAC.armature.GetSlot("脑壳");
  1236. WingSlot = UAC.armature.GetSlot("翅膀");
  1237. DressSlot = UAC.armature.GetSlot("裙子");
  1238. MouseSlot = UAC.armature.GetSlot("嘴巴");
  1239. LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
  1240. RightShoeSlot = UAC.armature.GetSlot("鞋子右");
  1241. HeadWearSlot = UAC.armature.GetSlot("头饰品");
  1242. ChangeClose(BodyPart.Eye, "眼睛1", false);
  1243. ChangeClose(BodyPart.Top, "上衣1", false);
  1244. ChangeClose(BodyPart.Shoe, "鞋子1", false);
  1245. ChangeClose(BodyPart.Head, "脑壳1", false);
  1246. ChangeClose(BodyPart.Dress, "裙子1", false);
  1247. ChangeClose(BodyPart.Mouse, "嘴巴1", false);
  1248. ChangeClose(BodyPart.Headwear, "头饰品1", false);
  1249. ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
  1250. ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
  1251. ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
  1252. ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
  1253. CorrectPivot();
  1254. Material = UAC.GetComponentInChildren<MeshRenderer>().sharedMaterial;
  1255. Shadow.GetComponent<MeshRenderer>().sharedMaterial = Material;
  1256. ExpressionMeshFilter = ChildDic[PlayerLabel.ExpressionMeshFilter].GetComponent<MeshFilter>();
  1257. ExpressionMeshFilter.GetComponent<MeshRenderer>().sharedMaterial = Material;
  1258. return UAC;
  1259. }
  1260. public UnityArmatureComponent BuildPink()
  1261. {
  1262. Build();
  1263. ChangeClose(BodyPart.Eye, "眼睛3", false);
  1264. ChangeClose(BodyPart.Top, "上衣3", false);
  1265. ChangeClose(BodyPart.Shoe, "鞋子3", false);
  1266. ChangeClose(BodyPart.Head, "脑壳3", false);
  1267. ChangeClose(BodyPart.Wing, "Empty", false);
  1268. ChangeClose(BodyPart.Dress, "裙子3", false);
  1269. ChangeClose(BodyPart.Mouse, "嘴巴3", false);
  1270. ChangeClose(BodyPart.Headwear, "头饰品3", false);
  1271. ResetDepth();
  1272. return UAC;
  1273. }
  1274. public UnityArmatureComponent BuildBlond()
  1275. {
  1276. Build();
  1277. ChangeClose(BodyPart.Wing, "Empty", false);
  1278. ResetDepth();
  1279. return UAC;
  1280. }
  1281. public UnityArmatureComponent BuildBrown()
  1282. {
  1283. Build();
  1284. ChangeClose(BodyPart.Eye, "眼睛2", false);
  1285. ChangeClose(BodyPart.Top, "上衣2", false);
  1286. ChangeClose(BodyPart.Shoe, "鞋子2", false);
  1287. ChangeClose(BodyPart.Head, "脑壳2", false);
  1288. ChangeClose(BodyPart.Wing, "Empty", false);
  1289. ChangeClose(BodyPart.Dress, "裙子2", false);
  1290. ChangeClose(BodyPart.Mouse, "嘴巴2", false);
  1291. ChangeClose(BodyPart.Headwear, "头饰品2", false);
  1292. ResetDepth();
  1293. return UAC;
  1294. }
  1295. public void ResetDepth()
  1296. {
  1297. if (IsDisplayInUGUI)
  1298. {
  1299. SetSlotAsFirstChild(TopSlot);
  1300. SetSlotAsFirstChild(DressSlot);
  1301. SetSlotAsFirstChild(LeftShortSleeveSlot);
  1302. SetSlotAsFirstChild(RightShortSleeveSlot);
  1303. LeftLongSleeveUAC.transform.SetAsFirstSibling();
  1304. RightLongSleeveUAC.transform.SetAsFirstSibling();
  1305. SetSlotAsFirstChild(EyeSlot);
  1306. SetSlotAsFirstChild(MouseSlot);
  1307. SetSlotAsFirstChild(LeftShoeSlot);
  1308. SetSlotAsFirstChild(RightShoeSlot);
  1309. SetSlotAsFirstChild(HeadWearSlot);
  1310. SetSlotAsFirstChild(LeftHandSlot);
  1311. SetSlotAsFirstChild(RightHandSlot);
  1312. SetSlotAsFirstChild(HeadSlot);
  1313. SetSlotAsFirstChild(LeftLegSlot);
  1314. SetSlotAsFirstChild(RightLegSlot);
  1315. SetSlotAsFirstChild(NeckSlot);
  1316. SetSlotAsFirstChild(WingSlot);
  1317. }
  1318. else
  1319. {
  1320. //UAC.transform.SetLZ(2.5f);
  1321. UAC.transform.SetLZ(0.7f);
  1322. SetSlotLocalZ(WingSlot, 0.00003f);
  1323. SetSlotLocalZ(EyeSlot, -0.00001f);
  1324. SetSlotLocalZ(TopSlot, -0.00003f);
  1325. SetSlotLocalZ(MouseSlot, -0.00001f);
  1326. SetSlotLocalZ(HeadWearSlot, -0.00001f);
  1327. SetSlotLocalZ(LeftShoeSlot, -0.00001f);
  1328. SetSlotLocalZ(RightShoeSlot, -0.00001f);
  1329. SetSlotLocalZ(LeftLegSlot, 0);
  1330. SetSlotLocalZ(RightLegSlot, 0);
  1331. SetSlotLocalZ(NeckSlot, 0.00001f);
  1332. SetSlotLocalZ(LeftHandSlot, -0.00001f);
  1333. SetSlotLocalZ(RightHandSlot, -0.00001f);
  1334. SetSlotLocalZ(LeftShortSleeveSlot, -0.000015f);
  1335. SetSlotLocalZ(RightShortSleeveSlot, -0.000015f);
  1336. SetSlotLocalZ(HeadSlot, 0);
  1337. if (HeadSlot.UnityTransform != null && HeadSlot.UnityTransform.childCount > 1)
  1338. {
  1339. HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1340. HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1341. }
  1342. SetSlotLocalZ(DressSlot, -0.00002f);
  1343. if (DressSlot.UnityTransform != null && DressSlot.UnityTransform.childCount > 1)
  1344. {
  1345. DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1346. DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1347. }
  1348. LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1349. RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1350. //UAC.transform.SetLZ(2.5f);
  1351. //WingSlot.UnityTransform.SetLZ(0);
  1352. //EyeSlot.UnityTransform.SetLZ(0);
  1353. //TopSlot.UnityTransform.SetLZ(0);
  1354. //MouseSlot.UnityTransform.SetLZ(0);
  1355. //HeadWearSlot.UnityTransform.SetLZ(0);
  1356. //LeftShoeSlot.UnityTransform.SetLZ(0);
  1357. //RightShoeSlot.UnityTransform.SetLZ(0);
  1358. //LeftLegSlot.UnityTransform.SetLZ(0);
  1359. //RightLegSlot.UnityTransform.SetLZ(0);
  1360. //NeckSlot.UnityTransform.SetLZ(0);
  1361. //LeftHandSlot.UnityTransform.SetLZ(0);
  1362. //RightHandSlot.UnityTransform.SetLZ(0);
  1363. //LeftShortSleeveSlot.UnityTransform.SetLZ(0);
  1364. //RightShortSleeveSlot.UnityTransform.SetLZ(0);
  1365. //WingSlot.SetLZ(0.00003f);
  1366. //EyeSlot.SetLZ(-0.00001f);
  1367. //TopSlot.SetLZ(-0.00003f);
  1368. //MouseSlot.SetLZ(-0.00001f);
  1369. //HeadWearSlot.SetLZ(-0.00001f);
  1370. //HeadSlot.UnityTransform.SetLZ(0);
  1371. //if (HeadSlot.UnityTransform.childCount > 1)
  1372. //{
  1373. // HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1374. // HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1375. //}
  1376. //DressSlot.UnityTransform.SetLZ(-0.00002f);
  1377. //if (DressSlot.UnityTransform.childCount > 1)
  1378. //{
  1379. // DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
  1380. // DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
  1381. //}
  1382. //LeftShoeSlot.SetLZ(-0.00001f);
  1383. //RightShoeSlot.SetLZ(-0.00001f);
  1384. //LeftLegSlot.SetLZ(0);
  1385. //RightLegSlot.SetLZ(0);
  1386. //NeckSlot.SetLZ(0.00001f);
  1387. //LeftHandSlot.SetLZ(-0.00001f);
  1388. //RightHandSlot.SetLZ(-0.00001f);
  1389. //LeftShortSleeveSlot.SetLZ(-0.000015f);
  1390. //RightShortSleeveSlot.SetLZ(-0.000015f);
  1391. //LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
  1392. //RightLongSleeveUAC.transform.SetLZ(-0.000015f);
  1393. }
  1394. }
  1395. private void SetSlotLocalZ(DragonBones.Slot slot, float z)
  1396. {
  1397. if (slot.UnityTransform == null)
  1398. {
  1399. UAC.transform.FindChild(slot.name).SetLZ(z);
  1400. }
  1401. else
  1402. {
  1403. slot.UnityTransform.SetLZ(z);
  1404. }
  1405. }
  1406. private void SetSlotAsFirstChild(DragonBones.Slot slot)
  1407. {
  1408. if (slot.UnityTransform == null)
  1409. {
  1410. UAC.transform.FindChild(slot.name).SetAsFirstSibling();
  1411. }
  1412. else
  1413. {
  1414. slot.UnityTransform.SetAsFirstSibling();
  1415. }
  1416. }
  1417. public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
  1418. {
  1419. // Debug.Log (bodyPart + " " + armatureName);
  1420. List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
  1421. if (bodyPart == BodyPart.Eye)
  1422. {
  1423. Eye = armatureName;
  1424. slotList.Add(EyeSlot);
  1425. }
  1426. else if (bodyPart == BodyPart.Top)
  1427. {
  1428. Top = armatureName;
  1429. slotList.Add(TopSlot);
  1430. }
  1431. else if (bodyPart == BodyPart.Shoe)
  1432. {
  1433. Shoe = armatureName;
  1434. slotList.Add(LeftShoeSlot);
  1435. slotList.Add(RightShoeSlot);
  1436. }
  1437. else if (bodyPart == BodyPart.Head)
  1438. {
  1439. Head = armatureName;
  1440. slotList.Add(HeadSlot);
  1441. }
  1442. else if (bodyPart == BodyPart.Wing)
  1443. {
  1444. if (Wing == armatureName)
  1445. {
  1446. return;
  1447. }
  1448. else
  1449. {
  1450. Wing = armatureName;
  1451. slotList.Add(WingSlot);
  1452. }
  1453. }
  1454. else if (bodyPart == BodyPart.Dress)
  1455. {
  1456. Dress = armatureName;
  1457. slotList.Add(DressSlot);
  1458. }
  1459. else if (bodyPart == BodyPart.Mouse)
  1460. {
  1461. Mouse = armatureName;
  1462. slotList.Add(MouseSlot);
  1463. }
  1464. else if (bodyPart == BodyPart.Headwear)
  1465. {
  1466. HeadWear = armatureName;
  1467. slotList.Add(HeadWearSlot);
  1468. }
  1469. else if (bodyPart == BodyPart.Leg)
  1470. {
  1471. slotList.Add(LeftLegSlot);
  1472. slotList.Add(RightLegSlot);
  1473. }
  1474. else if (bodyPart == BodyPart.LeftHand)
  1475. {
  1476. slotList.Add(LeftHandSlot);
  1477. }
  1478. else if (bodyPart == BodyPart.RightHand)
  1479. {
  1480. slotList.Add(RightHandSlot);
  1481. }
  1482. else if (bodyPart == BodyPart.Neck)
  1483. {
  1484. slotList.Add(NeckSlot);
  1485. }
  1486. else if (bodyPart == BodyPart.LeftLongSleeve)
  1487. {
  1488. LeftLongSleeve = armatureName;
  1489. ChangeClose(LeftLongSleeveUAC, armatureName);
  1490. return;
  1491. }
  1492. else if (bodyPart == BodyPart.LeftShortSleeve)
  1493. {
  1494. LeftShortSleeve = armatureName;
  1495. slotList.Add(LeftShortSleeveSlot);
  1496. }
  1497. else if (bodyPart == BodyPart.RightLongSleeve)
  1498. {
  1499. RightLongSleeve = armatureName;
  1500. ChangeClose(RightLongSleeveUAC, armatureName);
  1501. return;
  1502. }
  1503. else if (bodyPart == BodyPart.RightShortSleeve)
  1504. {
  1505. RightShortSleeve = armatureName;
  1506. slotList.Add(RightShortSleeveSlot);
  1507. }
  1508. else
  1509. {
  1510. throw new Exception();
  1511. }
  1512. ChangeClose(slotList, armatureName, setDepth);
  1513. if (bodyPart == BodyPart.Wing)
  1514. {
  1515. 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);
  1516. tweenRoot.PingPong = true;
  1517. tweenRoot.StartForward();
  1518. }
  1519. }
  1520. public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
  1521. {
  1522. for (int i = 0; i < slotList.Count; i++)
  1523. {
  1524. slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName, null, null, null, true);
  1525. slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
  1526. }
  1527. if (setDepth)
  1528. {
  1529. DelayCall.Call
  1530. (
  1531. 1,
  1532. () =>
  1533. {
  1534. ResetDepth();
  1535. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1536. }
  1537. );
  1538. }
  1539. }
  1540. public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
  1541. {
  1542. if (armatureName == "Empty")
  1543. {
  1544. uac.SetActive(false);
  1545. }
  1546. else
  1547. {
  1548. uac.SetActive(true);
  1549. }
  1550. if (setDepth)
  1551. {
  1552. DelayCall.Call
  1553. (
  1554. 1,
  1555. () =>
  1556. {
  1557. ResetDepth();
  1558. if (IsDisplayInUGUI) DisplayInUI(UGUIScale);
  1559. }
  1560. );
  1561. }
  1562. }
  1563. #endregion
  1564. }