Player.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. using DragonBones;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.EventSystems;
  6. using Slot = DragonBones.Slot;
  7. using Transform = UnityEngine.Transform;
  8. public class Player : Regist , IPointerClickHandler
  9. {
  10. #region 变量
  11. public bool AnimLock;
  12. private string Eye;
  13. private string Top;
  14. private string Shoe;
  15. private string Head;
  16. private string Dress;
  17. private string Mouse;
  18. private string RightShoe;
  19. private string HeadWear;
  20. public UnityArmatureComponent EyeUac;
  21. public UnityArmatureComponent TopUac;
  22. public UnityArmatureComponent HeadUac;
  23. public UnityArmatureComponent DressUac;
  24. public UnityArmatureComponent MouseUac;
  25. public UnityArmatureComponent LeftShoeUac;
  26. public UnityArmatureComponent RightShoeUac;
  27. public UnityArmatureComponent HeadWearUac;
  28. private List<string> EyeList = new List<string>();
  29. private List<string> TopList = new List<string>();
  30. private List<string> ShoeList = new List<string>();
  31. private List<string> HeadList = new List<string>();
  32. private List<string> DressList = new List<string>();
  33. private List<string> MouseList = new List<string>();
  34. private List<string> HeadWearList = new List<string>();
  35. public UnityArmatureComponent UAC;
  36. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  37. #endregion
  38. public override bool RegistImmed()
  39. {
  40. if (base.RegistImmed())
  41. {
  42. return true;
  43. }
  44. enabled = true;
  45. Auxiliary.CompileDic(transform, ChildDic);
  46. return false;
  47. }
  48. public void PlayAnim(string animName)
  49. {
  50. if (AnimLock)
  51. {
  52. return;
  53. }
  54. UAC.anim.Play(animName);
  55. }
  56. public void SetAllCollider(bool enable)
  57. {
  58. BoxCollider2D[] colliders = GetComponentsInChildren<BoxCollider2D>();
  59. for (int i = 0; i < colliders.Length; i++)
  60. {
  61. colliders[i].enabled = enable;
  62. }
  63. }
  64. public void OnPointerClick(PointerEventData eventData)
  65. {
  66. PlayAnim("newAnimation1");
  67. }
  68. #region 换装
  69. public UnityArmatureComponent Build()
  70. {
  71. if (!ManaPlayer.Complete)
  72. {
  73. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  74. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("Closet_ske", Folder.Config));
  75. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  76. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("Closet_tex", Folder.Config), "Closet_texture");
  77. ManaPlayer.Complete = true;
  78. }
  79. UAC = UnityFactory.factory.BuildArmatureComponent("Armature");
  80. UAC.transform.parent = transform;
  81. UAC.transform.localScale = new Vector3(1, 1, 1);
  82. UAC.transform.localPosition = new Vector3();
  83. UAC.anim.Play("newAnimation");
  84. EyeList.Add("眼睛1");
  85. TopList.Add("上衣1");
  86. ShoeList.Add("鞋子1");
  87. HeadList.Add("脑壳1");
  88. DressList.Add("裙子1");
  89. MouseList.Add("嘴巴1");
  90. HeadWearList.Add("头饰品1");
  91. EyeList.Add("眼睛2");
  92. TopList.Add("上衣2");
  93. ShoeList.Add("鞋子2");
  94. HeadList.Add("脑壳2");
  95. DressList.Add("裙子2");
  96. MouseList.Add("嘴巴2");
  97. HeadWearList.Add("头饰品2");
  98. EyeList.Add("眼睛3");
  99. TopList.Add("上衣3");
  100. ShoeList.Add("鞋子3");
  101. HeadList.Add("脑壳3");
  102. DressList.Add("裙子3");
  103. MouseList.Add("嘴巴3");
  104. HeadWearList.Add("头饰品3");
  105. Eye = EyeList[0];
  106. Top = TopList[0];
  107. Shoe = ShoeList[0];
  108. Head = HeadList[0];
  109. Dress = DressList[0];
  110. Mouse = MouseList[0];
  111. HeadWear = HeadWearList[0];
  112. return UAC;
  113. }
  114. public UnityArmatureComponent BuildPink()
  115. {
  116. Build();
  117. Eye = "眼睛3";
  118. Top = "上衣3";
  119. Shoe = "鞋子3";
  120. Head = "脑壳3";
  121. Dress = "裙子3";
  122. Mouse = "嘴巴3";
  123. HeadWear = "头饰品3";
  124. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  125. UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top);
  126. UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head);
  127. UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress);
  128. UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse);
  129. UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  130. UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  131. UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear);
  132. EyeUac = transform.FindChild("Armature/眼睛3").GetComponent<UnityArmatureComponent>();
  133. TopUac = transform.FindChild("Armature/上衣3").GetComponent<UnityArmatureComponent>();
  134. HeadUac = transform.FindChild("Armature/脑壳3").GetComponent<UnityArmatureComponent>();
  135. DressUac = transform.FindChild("Armature/裙子3").GetComponent<UnityArmatureComponent>();
  136. MouseUac = transform.FindChild("Armature/嘴巴3").GetComponent<UnityArmatureComponent>();
  137. LeftShoeUac = transform.FindChild("Armature/鞋子3").GetComponent<UnityArmatureComponent>();
  138. HeadWearUac = transform.FindChild("Armature/头饰品3").GetComponent<UnityArmatureComponent>();
  139. RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
  140. ResetDepth();
  141. UAC.AddEventListener(EventObject.START, OnStart);
  142. return UAC;
  143. }
  144. public UnityArmatureComponent BuildBlond()
  145. {
  146. Build();
  147. Eye = "眼睛1";
  148. Top = "上衣1";
  149. Shoe = "鞋子1";
  150. Head = "脑壳1";
  151. Dress = "裙子1";
  152. Mouse = "嘴巴1";
  153. HeadWear = "头饰品1";
  154. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  155. UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top);
  156. UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head);
  157. UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress);
  158. UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse);
  159. UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  160. UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  161. UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear);
  162. EyeUac = transform.FindChild("Armature/眼睛1").GetComponent<UnityArmatureComponent>();
  163. TopUac = transform.FindChild("Armature/上衣1").GetComponent<UnityArmatureComponent>();
  164. HeadUac = transform.FindChild("Armature/脑壳1").GetComponent<UnityArmatureComponent>();
  165. DressUac = transform.FindChild("Armature/裙子1").GetComponent<UnityArmatureComponent>();
  166. MouseUac = transform.FindChild("Armature/嘴巴1").GetComponent<UnityArmatureComponent>();
  167. LeftShoeUac = transform.FindChild("Armature/鞋子1").GetComponent<UnityArmatureComponent>();
  168. HeadWearUac = transform.FindChild("Armature/头饰品1").GetComponent<UnityArmatureComponent>();
  169. RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
  170. ResetDepth();
  171. UAC.AddEventListener(EventObject.START, OnStart);
  172. return UAC;
  173. }
  174. public UnityArmatureComponent BuildBrown()
  175. {
  176. Build();
  177. Eye = "眼睛2";
  178. Top = "上衣2";
  179. Shoe = "鞋子2";
  180. Head = "脑壳2";
  181. Dress = "裙子2";
  182. Mouse = "嘴巴2";
  183. HeadWear = "头饰品2";
  184. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  185. UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top);
  186. UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head);
  187. UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress);
  188. UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse);
  189. UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  190. UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  191. UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear);
  192. EyeUac = transform.FindChild("Armature/眼睛2").GetComponent<UnityArmatureComponent>();
  193. TopUac = transform.FindChild("Armature/上衣2").GetComponent<UnityArmatureComponent>();
  194. HeadUac = transform.FindChild("Armature/脑壳2").GetComponent<UnityArmatureComponent>();
  195. DressUac = transform.FindChild("Armature/裙子2").GetComponent<UnityArmatureComponent>();
  196. MouseUac = transform.FindChild("Armature/嘴巴2").GetComponent<UnityArmatureComponent>();
  197. LeftShoeUac = transform.FindChild("Armature/鞋子2").GetComponent<UnityArmatureComponent>();
  198. HeadWearUac = transform.FindChild("Armature/头饰品2").GetComponent<UnityArmatureComponent>();
  199. RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
  200. ResetDepth();
  201. UAC.AddEventListener(EventObject.START, OnStart);
  202. return UAC;
  203. }
  204. public void OnStart(string str, EventObject eventObject)
  205. {
  206. if (eventObject.animationState.name == "newAnimation1")
  207. {
  208. AnimLock = true;
  209. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature("眼睛表情1");
  210. EyeUac = transform.FindChild("Armature/眼睛表情1").GetComponent<UnityArmatureComponent>();
  211. }
  212. else if (eventObject.animationState.name == "newAnimation")
  213. {
  214. AnimLock = false;
  215. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  216. EyeUac = transform.FindChild("Armature/" + Eye).GetComponent<UnityArmatureComponent>();
  217. }
  218. ResetDepth();
  219. }
  220. public void PrevEye()
  221. {
  222. int index = EyeList.IndexOf(Eye);
  223. Eye = EyeList.Prev(index);
  224. ChangeClose(EyeUac, Eye);
  225. ResetDepth();
  226. }
  227. public void PrevTop()
  228. {
  229. int index = TopList.IndexOf(Top);
  230. Top = TopList.Prev(index);
  231. ChangeClose(TopUac, Top);
  232. ResetDepth();
  233. }
  234. public void PrevShoe()
  235. {
  236. int index = ShoeList.IndexOf(Shoe);
  237. Shoe = ShoeList.Prev(index);
  238. ChangeClose(LeftShoeUac, Shoe);
  239. ChangeClose(RightShoeUac, Shoe);
  240. ResetDepth();
  241. }
  242. public void PrevHead()
  243. {
  244. int index = HeadList.IndexOf(Head);
  245. Head = HeadList.Prev(index);
  246. ChangeClose(HeadUac, Head);
  247. ResetDepth();
  248. }
  249. public void PrevDress()
  250. {
  251. int index = DressList.IndexOf(Dress);
  252. Dress = DressList.Prev(index);
  253. ChangeClose(DressUac, Dress);
  254. ResetDepth();
  255. }
  256. public void PrevMouse()
  257. {
  258. int index = MouseList.IndexOf(Mouse);
  259. Mouse = MouseList.Prev(index);
  260. ChangeClose(MouseUac, Mouse);
  261. ResetDepth();
  262. }
  263. public void PrevHeadWear()
  264. {
  265. int index = HeadWearList.IndexOf(HeadWear);
  266. HeadWear = HeadWearList.Prev(index);
  267. ChangeClose(HeadWearUac, HeadWear);
  268. ResetDepth();
  269. }
  270. public void NextEye()
  271. {
  272. int index = EyeList.IndexOf(Eye);
  273. Eye = EyeList.Next(index);
  274. ChangeClose(EyeUac, Eye);
  275. ResetDepth();
  276. }
  277. public void NextTop()
  278. {
  279. int index = TopList.IndexOf(Top);
  280. Top = TopList.Next(index);
  281. ChangeClose(TopUac, Top);
  282. ResetDepth();
  283. }
  284. public void NextShoe()
  285. {
  286. int index = ShoeList.IndexOf(Shoe);
  287. Shoe = ShoeList.Next(index);
  288. ChangeClose(LeftShoeUac, Shoe);
  289. ChangeClose(RightShoeUac, Shoe);
  290. ResetDepth();
  291. }
  292. public void NextHead()
  293. {
  294. int index = HeadList.IndexOf(Head);
  295. Head = HeadList.Next(index);
  296. ChangeClose(HeadUac, Head);
  297. ResetDepth();
  298. }
  299. public void NextDress()
  300. {
  301. int index = DressList.IndexOf(Dress);
  302. Dress = DressList.Next(index);
  303. ChangeClose(DressUac, Dress);
  304. ResetDepth();
  305. }
  306. public void NextMouse()
  307. {
  308. int index = MouseList.IndexOf(Mouse);
  309. Mouse = MouseList.Next(index);
  310. ChangeClose(MouseUac, Mouse);
  311. ResetDepth();
  312. }
  313. public void NextHeadWear()
  314. {
  315. int index = HeadWearList.IndexOf(HeadWear);
  316. HeadWear = HeadWearList.Next(index);
  317. ChangeClose(HeadWearUac, HeadWear);
  318. ResetDepth();
  319. }
  320. public void ResetDepth()
  321. {
  322. UAC.transform.SetLZ(2);
  323. HeadUac.transform.SetLZ(0);
  324. EyeUac.transform.SetLZ(-0.001f);
  325. TopUac.transform.SetLZ(-0.003f);
  326. DressUac.transform.SetLZ(-0.002f);
  327. MouseUac.transform.SetLZ(-0.001f);
  328. LeftShoeUac.transform.SetLZ(-0.001f);
  329. RightShoeUac.transform.SetLZ(-0.001f);
  330. HeadWearUac.transform.SetLZ(-0.001f);
  331. transform.FindChild("Armature/左腿").SetLZ(0);
  332. transform.FindChild("Armature/右腿").SetLZ(0);
  333. transform.FindChild("Armature/脖子").SetLZ(0);
  334. transform.FindChild("Armature/左手").SetLZ(-0.001f);
  335. transform.FindChild("Armature/右手").SetLZ(-0.001f);
  336. }
  337. public void ChangeClose(UnityArmatureComponent uac, string armatureName)
  338. {
  339. //DragonBones.Slot slot = null;
  340. //if (uac.armature != null)
  341. //{
  342. // slot = uac.armature.parent;
  343. // uac.Dispose(false);
  344. //}
  345. //GameObject go = uac.gameObject;
  346. //uac = UnityFactory.factory.BuildArmatureComponent(armatureName, "Closet_ske", null, null, go);
  347. //if (uac == null)
  348. //{
  349. // uac = UnityFactory.factory.BuildArmatureComponent(armatureName, "stand_ske", null, null, go);
  350. //}
  351. //uac.name = armatureName;
  352. //if (slot != null)
  353. //{
  354. // slot.childArmature = uac.armature;
  355. //}
  356. //uac.sortingLayerName = uac.sortingLayerName;
  357. //uac.sortingOrder = uac.sortingOrder;
  358. }
  359. #endregion
  360. }