Player.cs 10 KB

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