Player.cs 9.2 KB

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