Player.cs 13 KB

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