Player.cs 9.7 KB

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