Player.cs 13 KB

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