Player.cs 13 KB

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