Player.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. using DragonBones;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using System.Linq;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using Slot = DragonBones.Slot;
  8. using Transform = UnityEngine.Transform;
  9. public class Player : Regist , IPointerClickHandler
  10. {
  11. #region 变量
  12. public static bool InDressRoom;
  13. public static float JumpFrequency;
  14. public bool AnimLock1;
  15. public bool AnimLock2;
  16. public float JumpTime;
  17. public float JumpTimer;
  18. private string Eye;
  19. private string Top;
  20. private string Shoe;
  21. private string Head;
  22. private string Dress;
  23. private string Mouse;
  24. private string RightShoe;
  25. private string HeadWear;
  26. public UnityArmatureComponent EyeUac;
  27. public UnityArmatureComponent TopUac;
  28. public UnityArmatureComponent HeadUac;
  29. public UnityArmatureComponent DressUac;
  30. public UnityArmatureComponent MouseUac;
  31. public UnityArmatureComponent LeftShoeUac;
  32. public UnityArmatureComponent RightShoeUac;
  33. public UnityArmatureComponent HeadWearUac;
  34. private List<string> EyeList = new List<string>();
  35. private List<string> TopList = new List<string>();
  36. private List<string> ShoeList = new List<string>();
  37. private List<string> HeadList = new List<string>();
  38. private List<string> DressList = new List<string>();
  39. private List<string> MouseList = new List<string>();
  40. private List<string> HeadWearList = new List<string>();
  41. public UnityArmatureComponent UAC;
  42. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  43. #endregion
  44. public override bool RegistImmed()
  45. {
  46. if (base.RegistImmed())
  47. {
  48. return true;
  49. }
  50. enabled = true;
  51. Auxiliary.CompileDic(transform, ChildDic);
  52. Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
  53. Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
  54. StreamScale streamScale = ChildDic["Shadow"].CreateStreamScale
  55. (
  56. new List<float>() {0, 0, 0},
  57. new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
  58. new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
  59. true,
  60. true,
  61. Curve.EaseOutQuad
  62. );
  63. streamScale.AddEventOnetime
  64. (
  65. EventType.ForwardFinish,
  66. () =>
  67. {
  68. if (!InDressRoom)
  69. {
  70. ManaPlayer.Player.ChildDic["Shadow"].SetActive(false);
  71. }
  72. }
  73. );
  74. return false;
  75. }
  76. public void FixedUpdate()
  77. {
  78. if (InDressRoom)
  79. {
  80. JumpTimer += Time.fixedDeltaTime;
  81. if (JumpTimer > JumpTime)
  82. {
  83. if (!AnimLock1 && !AnimLock2)
  84. {
  85. PlayAnim("newAnimation1");
  86. }
  87. AnimLock2 = true;
  88. }
  89. if (JumpTimer > JumpFrequency)
  90. {
  91. AnimLock2 = false;
  92. JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0f, 1f));
  93. JumpTimer = 0;
  94. }
  95. }
  96. }
  97. public void PlayAnim(string animName)
  98. {
  99. if (AnimLock1)
  100. {
  101. return;
  102. }
  103. UAC.anim.Play(animName);
  104. }
  105. public void SetAllCollider(bool enable)
  106. {
  107. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  108. for (int i = 0; i < colliders.Length; i++)
  109. {
  110. colliders[i].enabled = enable;
  111. }
  112. }
  113. public void OnPointerClick(PointerEventData eventData)
  114. {
  115. EnterDressRoom();
  116. }
  117. public void Save()
  118. {
  119. ExitDressRoom();
  120. }
  121. public void Reset()
  122. {
  123. }
  124. public void ExitDressRoom()
  125. {
  126. ManaCenter.SceneSwitchLock = false;
  127. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  128. tweenRoot.AddEventOnetime
  129. (
  130. EventType.BackwardFinish,
  131. () =>
  132. {
  133. ManaPlayer.Player.ChildDic["Shadow"].SetActive(false);
  134. ManaPlayer.Player.transform.position = ManaReso.Get("PlayerPosTra").position;
  135. ManaPlayer.Player.transform.localScale = ManaReso.Get("PlayerPosTra").lossyScale;
  136. ManaReso.Get("Garden").TweenForSr();
  137. ManaReso.Get("DressRoom").TweenBacSr();
  138. ManaReso.Get("C_Main").TweenForCG();
  139. ManaReso.Get("P_DressRoom").TweenBacCG();
  140. }
  141. );
  142. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  143. tweenRoot.AddEventOnetime
  144. (
  145. EventType.BackwardFinish,
  146. () =>
  147. {
  148. SetAllCollider(true);
  149. InDressRoom = false;
  150. ManaReso.Get("I_BlackMask").TweenForCG();
  151. }
  152. );
  153. }
  154. public void EnterDressRoom()
  155. {
  156. if (ManaCenter.SceneSwitchLock)
  157. {
  158. return;
  159. }
  160. InDressRoom = true;
  161. JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0f, 1f));
  162. ManaCenter.SceneSwitchLock = true;
  163. ManaReso.Get("C_Main").TweenBacCG();
  164. SetAllCollider(false);
  165. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
  166. tweenRoot.AddEventOnetime
  167. (
  168. EventType.BackwardFinish,
  169. () =>
  170. {
  171. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  172. {
  173. ManaGarden.PlantList[i].Flower.RetrieveElf();
  174. }
  175. ManaPlayer.Player.ChildDic["Shadow"].SetActive(true);
  176. ManaPlayer.Player.transform.position = ManaReso.Get("P_PlayerPos").position;
  177. ManaPlayer.Player.transform.localScale = ManaReso.Get("P_PlayerPos").lossyScale;
  178. ManaReso.Get("Garden").TweenBacSr();
  179. ManaReso.Get("DressRoom").TweenForSr();
  180. ManaReso.Get("P_DressRoom").TweenForCG();
  181. }
  182. );
  183. tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
  184. tweenRoot.AddEventOnetime
  185. (
  186. EventType.ForwardFinish,
  187. () =>
  188. {
  189. ManaReso.Get("I_BlackMask").TweenForCG();
  190. }
  191. );
  192. }
  193. #region 换装
  194. public UnityArmatureComponent Build()
  195. {
  196. if (!ManaPlayer.Complete)
  197. {
  198. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  199. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("Closet_ske", Folder.Config));
  200. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  201. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("Closet_tex", Folder.Config), "Closet_texture");
  202. ManaPlayer.Complete = true;
  203. }
  204. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  205. UAC.transform.parent = transform;
  206. UAC.transform.localScale = new Vector3(1, 1, 1);
  207. UAC.transform.localPosition = new Vector3();
  208. UAC.anim.Play("newAnimation");
  209. EyeList.Add("眼睛1");
  210. TopList.Add("上衣1");
  211. ShoeList.Add("鞋子1");
  212. HeadList.Add("脑壳1");
  213. DressList.Add("裙子1");
  214. MouseList.Add("嘴巴1");
  215. HeadWearList.Add("头饰品1");
  216. EyeList.Add("眼睛2");
  217. TopList.Add("上衣2");
  218. ShoeList.Add("鞋子2");
  219. HeadList.Add("脑壳2");
  220. DressList.Add("裙子2");
  221. MouseList.Add("嘴巴2");
  222. HeadWearList.Add("头饰品2");
  223. EyeList.Add("眼睛3");
  224. TopList.Add("上衣3");
  225. ShoeList.Add("鞋子3");
  226. HeadList.Add("脑壳3");
  227. DressList.Add("裙子3");
  228. MouseList.Add("嘴巴3");
  229. HeadWearList.Add("头饰品3");
  230. Eye = EyeList[0];
  231. Top = TopList[0];
  232. Shoe = ShoeList[0];
  233. Head = HeadList[0];
  234. Dress = DressList[0];
  235. Mouse = MouseList[0];
  236. HeadWear = HeadWearList[0];
  237. List<List<TextureAtlasData>> textureAtlasDatalist = UnityFactory.factory.GetAllTextureAtlasData().Values.ToList();
  238. for (int i = 0; i < textureAtlasDatalist.Count; i++)
  239. {
  240. Debug.Log(textureAtlasDatalist[i][0].imagePath);
  241. }
  242. return UAC;
  243. }
  244. public UnityArmatureComponent BuildPink()
  245. {
  246. Build();
  247. Eye = "眼睛3";
  248. Top = "上衣3";
  249. Shoe = "鞋子3";
  250. Head = "脑壳3";
  251. Dress = "裙子3";
  252. Mouse = "嘴巴3";
  253. HeadWear = "头饰品3";
  254. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  255. UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top);
  256. UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head);
  257. UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress);
  258. UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse);
  259. UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  260. UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  261. UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear);
  262. EyeUac = transform.FindChild("Armature/眼睛3").GetComponent<UnityArmatureComponent>();
  263. TopUac = transform.FindChild("Armature/上衣3").GetComponent<UnityArmatureComponent>();
  264. HeadUac = transform.FindChild("Armature/脑壳3").GetComponent<UnityArmatureComponent>();
  265. DressUac = transform.FindChild("Armature/裙子3").GetComponent<UnityArmatureComponent>();
  266. MouseUac = transform.FindChild("Armature/嘴巴3").GetComponent<UnityArmatureComponent>();
  267. LeftShoeUac = transform.FindChild("Armature/鞋子3").GetComponent<UnityArmatureComponent>();
  268. HeadWearUac = transform.FindChild("Armature/头饰品3").GetComponent<UnityArmatureComponent>();
  269. RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
  270. ResetDepth();
  271. UAC.AddEventListener(EventObject.START, OnStart);
  272. return UAC;
  273. }
  274. public UnityArmatureComponent BuildBlond()
  275. {
  276. Build();
  277. Eye = "眼睛1";
  278. Top = "上衣1";
  279. Shoe = "鞋子1";
  280. Head = "脑壳1";
  281. Dress = "裙子1";
  282. Mouse = "嘴巴1";
  283. HeadWear = "头饰品1";
  284. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  285. UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top);
  286. UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head);
  287. UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress);
  288. UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse);
  289. UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  290. UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  291. UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear);
  292. EyeUac = transform.FindChild("Armature/眼睛1").GetComponent<UnityArmatureComponent>();
  293. TopUac = transform.FindChild("Armature/上衣1").GetComponent<UnityArmatureComponent>();
  294. HeadUac = transform.FindChild("Armature/脑壳1").GetComponent<UnityArmatureComponent>();
  295. DressUac = transform.FindChild("Armature/裙子1").GetComponent<UnityArmatureComponent>();
  296. MouseUac = transform.FindChild("Armature/嘴巴1").GetComponent<UnityArmatureComponent>();
  297. LeftShoeUac = transform.FindChild("Armature/鞋子1").GetComponent<UnityArmatureComponent>();
  298. HeadWearUac = transform.FindChild("Armature/头饰品1").GetComponent<UnityArmatureComponent>();
  299. RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
  300. ResetDepth();
  301. UAC.AddEventListener(EventObject.START, OnStart);
  302. return UAC;
  303. }
  304. public UnityArmatureComponent BuildBrown()
  305. {
  306. Build();
  307. Eye = "眼睛2";
  308. Top = "上衣2";
  309. Shoe = "鞋子2";
  310. Head = "脑壳2";
  311. Dress = "裙子2";
  312. Mouse = "嘴巴2";
  313. HeadWear = "头饰品2";
  314. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  315. UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top);
  316. UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head);
  317. UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress);
  318. UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse);
  319. UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  320. UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  321. UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear);
  322. EyeUac = transform.FindChild("Armature/眼睛2").GetComponent<UnityArmatureComponent>();
  323. TopUac = transform.FindChild("Armature/上衣2").GetComponent<UnityArmatureComponent>();
  324. HeadUac = transform.FindChild("Armature/脑壳2").GetComponent<UnityArmatureComponent>();
  325. DressUac = transform.FindChild("Armature/裙子2").GetComponent<UnityArmatureComponent>();
  326. MouseUac = transform.FindChild("Armature/嘴巴2").GetComponent<UnityArmatureComponent>();
  327. LeftShoeUac = transform.FindChild("Armature/鞋子2").GetComponent<UnityArmatureComponent>();
  328. HeadWearUac = transform.FindChild("Armature/头饰品2").GetComponent<UnityArmatureComponent>();
  329. RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
  330. ResetDepth();
  331. UAC.AddEventListener(EventObject.START, OnStart);
  332. return UAC;
  333. }
  334. public void OnStart(string str, EventObject eventObject)
  335. {
  336. if (eventObject.animationState.name == "newAnimation1")
  337. {
  338. ChildDic["Shadow"].StreamReForScale();
  339. AnimLock1 = true;
  340. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature("眼睛表情1");
  341. EyeUac = transform.FindChild("Armature/眼睛表情1").GetComponent<UnityArmatureComponent>();
  342. }
  343. else if (eventObject.animationState.name == "newAnimation")
  344. {
  345. AnimLock1 = false;
  346. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  347. EyeUac = transform.FindChild("Armature/" + Eye).GetComponent<UnityArmatureComponent>();
  348. }
  349. ResetDepth();
  350. }
  351. public void PrevEye()
  352. {
  353. int index = EyeList.IndexOf(Eye);
  354. Eye = EyeList.Prev(index);
  355. ChangeClose(EyeUac, Eye);
  356. ResetDepth();
  357. }
  358. public void PrevTop()
  359. {
  360. int index = TopList.IndexOf(Top);
  361. Top = TopList.Prev(index);
  362. ChangeClose(TopUac, Top);
  363. ResetDepth();
  364. }
  365. public void PrevShoe()
  366. {
  367. int index = ShoeList.IndexOf(Shoe);
  368. Shoe = ShoeList.Prev(index);
  369. ChangeClose(LeftShoeUac, Shoe);
  370. ChangeClose(RightShoeUac, Shoe);
  371. ResetDepth();
  372. }
  373. public void PrevHead()
  374. {
  375. int index = HeadList.IndexOf(Head);
  376. Head = HeadList.Prev(index);
  377. ChangeClose(HeadUac, Head);
  378. ResetDepth();
  379. }
  380. public void PrevDress()
  381. {
  382. int index = DressList.IndexOf(Dress);
  383. Dress = DressList.Prev(index);
  384. ChangeClose(DressUac, Dress);
  385. ResetDepth();
  386. }
  387. public void PrevMouse()
  388. {
  389. int index = MouseList.IndexOf(Mouse);
  390. Mouse = MouseList.Prev(index);
  391. ChangeClose(MouseUac, Mouse);
  392. ResetDepth();
  393. }
  394. public void PrevHeadWear()
  395. {
  396. int index = HeadWearList.IndexOf(HeadWear);
  397. HeadWear = HeadWearList.Prev(index);
  398. ChangeClose(HeadWearUac, HeadWear);
  399. ResetDepth();
  400. }
  401. public void NextEye()
  402. {
  403. int index = EyeList.IndexOf(Eye);
  404. Eye = EyeList.Next(index);
  405. ChangeClose(EyeUac, Eye);
  406. ResetDepth();
  407. }
  408. public void NextTop()
  409. {
  410. int index = TopList.IndexOf(Top);
  411. Top = TopList.Next(index);
  412. ChangeClose(TopUac, Top);
  413. ResetDepth();
  414. }
  415. public void NextShoe()
  416. {
  417. int index = ShoeList.IndexOf(Shoe);
  418. Shoe = ShoeList.Next(index);
  419. ChangeClose(LeftShoeUac, Shoe);
  420. ChangeClose(RightShoeUac, Shoe);
  421. ResetDepth();
  422. }
  423. public void NextHead()
  424. {
  425. int index = HeadList.IndexOf(Head);
  426. Head = HeadList.Next(index);
  427. ChangeClose(HeadUac, Head);
  428. ResetDepth();
  429. }
  430. public void NextDress()
  431. {
  432. int index = DressList.IndexOf(Dress);
  433. Dress = DressList.Next(index);
  434. ChangeClose(DressUac, Dress);
  435. ResetDepth();
  436. }
  437. public void NextMouse()
  438. {
  439. int index = MouseList.IndexOf(Mouse);
  440. Mouse = MouseList.Next(index);
  441. ChangeClose(MouseUac, Mouse);
  442. ResetDepth();
  443. }
  444. public void NextHeadWear()
  445. {
  446. int index = HeadWearList.IndexOf(HeadWear);
  447. HeadWear = HeadWearList.Next(index);
  448. ChangeClose(HeadWearUac, HeadWear);
  449. ResetDepth();
  450. }
  451. public void ResetDepth()
  452. {
  453. UAC.transform.SetLZ(2);
  454. HeadUac.transform.SetLZ(0);
  455. EyeUac.transform.SetLZ(-0.001f);
  456. TopUac.transform.SetLZ(-0.003f);
  457. DressUac.transform.SetLZ(-0.002f);
  458. MouseUac.transform.SetLZ(-0.001f);
  459. LeftShoeUac.transform.SetLZ(-0.001f);
  460. RightShoeUac.transform.SetLZ(-0.001f);
  461. HeadWearUac.transform.SetLZ(-0.001f);
  462. transform.FindChild("Armature/左腿").SetLZ(0);
  463. transform.FindChild("Armature/右腿").SetLZ(0);
  464. transform.FindChild("Armature/脖子").SetLZ(0);
  465. transform.FindChild("Armature/左手").SetLZ(-0.001f);
  466. transform.FindChild("Armature/右手").SetLZ(-0.001f);
  467. }
  468. public void ChangeClose(UnityArmatureComponent uac, string armatureName)
  469. {
  470. //DragonBones.Slot slot = null;
  471. //if (uac.armature != null)
  472. //{
  473. // slot = uac.armature.parent;
  474. // uac.Dispose(false);
  475. //}
  476. //GameObject go = uac.gameObject;
  477. //uac = UnityFactory.factory.BuildArmatureComponent(armatureName, "Closet_ske", null, null, go);
  478. //if (uac == null)
  479. //{
  480. // uac = UnityFactory.factory.BuildArmatureComponent(armatureName, "stand_ske", null, null, go);
  481. //}
  482. //uac.name = armatureName;
  483. //if (slot != null)
  484. //{
  485. // slot.childArmature = uac.armature;
  486. //}
  487. //uac.sortingLayerName = uac.sortingLayerName;
  488. //uac.sortingOrder = uac.sortingOrder;
  489. }
  490. #endregion
  491. }