Player.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. private UnityArmatureComponent EyeUac;
  18. private UnityArmatureComponent TopUac;
  19. private UnityArmatureComponent HeadUac;
  20. private UnityArmatureComponent DressUac;
  21. private UnityArmatureComponent MouseUac;
  22. private UnityArmatureComponent LeftShoeUac;
  23. private UnityArmatureComponent RightShoeUac;
  24. private 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. 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.animation.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. UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
  85. UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top);
  86. UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head);
  87. UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress);
  88. UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse);
  89. UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  90. UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe);
  91. UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear);
  92. EyeUac = transform.FindChild("Armature/眼睛1").GetComponent<UnityArmatureComponent>();
  93. TopUac = transform.FindChild("Armature/上衣1").GetComponent<UnityArmatureComponent>();
  94. HeadUac = transform.FindChild("Armature/脑壳1").GetComponent<UnityArmatureComponent>();
  95. DressUac = transform.FindChild("Armature/裙子1").GetComponent<UnityArmatureComponent>();
  96. MouseUac = transform.FindChild("Armature/嘴巴1").GetComponent<UnityArmatureComponent>();
  97. LeftShoeUac = transform.FindChild("Armature/鞋子1").GetComponent<UnityArmatureComponent>();
  98. RightShoeUac = transform.FindChild("Armature/鞋子1").GetComponent<UnityArmatureComponent>();
  99. HeadWearUac = transform.FindChild("Armature/头饰品1").GetComponent<UnityArmatureComponent>();
  100. RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
  101. return UAC;
  102. }
  103. public UnityArmatureComponent BuildPink()
  104. {
  105. Build();
  106. NextEye();
  107. NextTop();
  108. NextShoe();
  109. NextHead();
  110. NextDress();
  111. NextMouse();
  112. NextHeadWear();
  113. NextEye();
  114. NextTop();
  115. NextShoe();
  116. NextHead();
  117. NextDress();
  118. NextMouse();
  119. NextHeadWear();
  120. return UAC;
  121. }
  122. public UnityArmatureComponent BuildBlond()
  123. {
  124. Build();
  125. ResetDepth();
  126. return UAC;
  127. }
  128. public UnityArmatureComponent BuildBrown()
  129. {
  130. Build();
  131. NextEye();
  132. NextTop();
  133. NextShoe();
  134. NextHead();
  135. NextDress();
  136. NextMouse();
  137. NextHeadWear();
  138. return UAC;
  139. }
  140. public void PrevEye()
  141. {
  142. int index = EyeList.IndexOf(Eye);
  143. Eye = EyeList.Prev(index);
  144. ChangeClose(EyeUac, Eye);
  145. ResetDepth();
  146. }
  147. public void PrevTop()
  148. {
  149. int index = TopList.IndexOf(Top);
  150. Top = TopList.Prev(index);
  151. ChangeClose(TopUac, Top);
  152. ResetDepth();
  153. }
  154. public void PrevShoe()
  155. {
  156. int index = ShoeList.IndexOf(Shoe);
  157. Shoe = ShoeList.Prev(index);
  158. ChangeClose(LeftShoeUac, Shoe);
  159. ChangeClose(RightShoeUac, Shoe);
  160. ResetDepth();
  161. }
  162. public void PrevHead()
  163. {
  164. int index = HeadList.IndexOf(Head);
  165. Head = HeadList.Prev(index);
  166. ChangeClose(HeadUac, Head);
  167. ResetDepth();
  168. }
  169. public void PrevDress()
  170. {
  171. int index = DressList.IndexOf(Dress);
  172. Dress = DressList.Prev(index);
  173. ChangeClose(DressUac, Dress);
  174. ResetDepth();
  175. }
  176. public void PrevMouse()
  177. {
  178. int index = MouseList.IndexOf(Mouse);
  179. Mouse = MouseList.Prev(index);
  180. ChangeClose(MouseUac, Mouse);
  181. ResetDepth();
  182. }
  183. public void PrevHeadWear()
  184. {
  185. int index = HeadWearList.IndexOf(HeadWear);
  186. HeadWear = HeadWearList.Prev(index);
  187. ChangeClose(HeadWearUac, HeadWear);
  188. ResetDepth();
  189. }
  190. public void NextEye()
  191. {
  192. int index = EyeList.IndexOf(Eye);
  193. Eye = EyeList.Next(index);
  194. ChangeClose(EyeUac, Eye);
  195. ResetDepth();
  196. }
  197. public void NextTop()
  198. {
  199. int index = TopList.IndexOf(Top);
  200. Top = TopList.Next(index);
  201. ChangeClose(TopUac, Top);
  202. ResetDepth();
  203. }
  204. public void NextShoe()
  205. {
  206. int index = ShoeList.IndexOf(Shoe);
  207. Shoe = ShoeList.Next(index);
  208. ChangeClose(LeftShoeUac, Shoe);
  209. ChangeClose(RightShoeUac, Shoe);
  210. ResetDepth();
  211. }
  212. public void NextHead()
  213. {
  214. int index = HeadList.IndexOf(Head);
  215. Head = HeadList.Next(index);
  216. ChangeClose(HeadUac, Head);
  217. ResetDepth();
  218. }
  219. public void NextDress()
  220. {
  221. int index = DressList.IndexOf(Dress);
  222. Dress = DressList.Next(index);
  223. ChangeClose(DressUac, Dress);
  224. ResetDepth();
  225. }
  226. public void NextMouse()
  227. {
  228. int index = MouseList.IndexOf(Mouse);
  229. Mouse = MouseList.Next(index);
  230. ChangeClose(MouseUac, Mouse);
  231. ResetDepth();
  232. }
  233. public void NextHeadWear()
  234. {
  235. int index = HeadWearList.IndexOf(HeadWear);
  236. HeadWear = HeadWearList.Next(index);
  237. ChangeClose(HeadWearUac, HeadWear);
  238. ResetDepth();
  239. }
  240. public void ResetDepth()
  241. {
  242. HeadUac.transform.SetLZ(0);
  243. EyeUac.transform.SetLZ(-0.001f);
  244. TopUac.transform.SetLZ(-0.003f);
  245. DressUac.transform.SetLZ(-0.002f);
  246. MouseUac.transform.SetLZ(-0.001f);
  247. LeftShoeUac.transform.SetLZ(-0.001f);
  248. RightShoeUac.transform.SetLZ(-0.001f);
  249. HeadWearUac.transform.SetLZ(-0.001f);
  250. transform.FindChild("Armature/左腿").SetLZ(0);
  251. transform.FindChild("Armature/右腿").SetLZ(0);
  252. transform.FindChild("Armature/脖子").SetLZ(0);
  253. transform.FindChild("Armature/左手").SetLZ(-0.001f);
  254. transform.FindChild("Armature/右手").SetLZ(-0.001f);
  255. }
  256. public void ChangeClose(UnityArmatureComponent uac, string armatureName)
  257. {
  258. global::DragonBones.Slot slot = null;
  259. if (uac.armature != null)
  260. {
  261. slot = uac.armature.parent;
  262. uac.Dispose(false);
  263. }
  264. uac.armatureName = armatureName;
  265. uac = UnityFactory.factory.BuildArmatureComponent(uac.armatureName, "Closet_ske", null, null, uac.gameObject);
  266. if (slot != null)
  267. {
  268. slot.childArmature = uac.armature;
  269. }
  270. uac.sortingLayerName = uac.sortingLayerName;
  271. uac.sortingOrder = uac.sortingOrder;
  272. }
  273. #endregion
  274. }