ManaPlayer.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using DragonBones;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System;
  5. using System.Xml;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Collections;
  9. using System.Diagnostics;
  10. using System.Collections.Generic;
  11. using Transform = UnityEngine.Transform;
  12. public class ManaPlayer : Regist
  13. {
  14. #region 变量
  15. public static bool Complete;
  16. public static Transform SeleTra;
  17. public static Player Player;
  18. public static Transform DressRoom;
  19. public static Transform PlayerPink;
  20. public static Transform PlayerBlond;
  21. public static Transform PlayerBrown;
  22. public static ManaPlayer Instance;
  23. public static List<int>BoughtCloseList = new List<int>();
  24. public static List<string> DressData = new List<string>();
  25. public static Dictionary<int, CloseUnit> CloseUnitDic = new Dictionary<int, CloseUnit>();
  26. public static Dictionary<string, int> CloseIDDic = new Dictionary<string, int>();
  27. public static Dictionary<string, Sprite> CloseSpriteDic = new Dictionary<string, Sprite>();
  28. #endregion
  29. public override void Instantiate()
  30. {
  31. #region Player
  32. if (!Complete)
  33. {
  34. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  35. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("Closet_ske", Folder.Config));
  36. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  37. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("Closet_tex", Folder.Config), "Closet_texture");
  38. Complete = true;
  39. }
  40. if (!ManaTutorial.TutorialA || ManaTutorial.TutorialIndexA != 1)
  41. {
  42. GetPlayer();
  43. DressData = ManaData.GetDressData();
  44. }
  45. else
  46. {
  47. PlayerPink = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos3"), false, ObjType.Player);
  48. PlayerBlond = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos2"), false, ObjType.Player);
  49. PlayerBrown = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos1"), false, ObjType.Player);
  50. if (PlayerPink.GetComponent<Player>() == null)
  51. {
  52. PlayerPink.AddScript<Player>().BuildPink();
  53. }
  54. if (PlayerBlond.GetComponent<Player>() == null)
  55. {
  56. PlayerBlond.AddScript<Player>().BuildBlond();
  57. }
  58. if (PlayerBrown.GetComponent<Player>() == null)
  59. {
  60. PlayerBrown.AddScript<Player>().BuildBrown();
  61. }
  62. PlayerPink.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  63. PlayerBlond.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  64. PlayerBrown.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  65. SeleTra = PlayerBlond;
  66. }
  67. #endregion
  68. #region DressRoom
  69. #region Close
  70. List<List<TextureAtlasData>> textureAtlasDatalist = UnityFactory.factory.GetAllTextureAtlasData().Values.ToList();
  71. for (int i = 0; i < textureAtlasDatalist.Count; i++)
  72. {
  73. for (int j = 0; j < textureAtlasDatalist[i].Count; j++)
  74. {
  75. TextureAtlasData textureAtlasData = textureAtlasDatalist[i][j];
  76. string textureName = textureAtlasData.imagePath.Split('.')[0] + "ture";
  77. foreach (var kv in textureAtlasData.textures)
  78. {
  79. Texture2D texture2D = UnityFactory.AtlasDictionary[textureName];
  80. Rect rect = new Rect(kv.Value.region.x, texture2D.height - kv.Value.region.y - kv.Value.region.height, kv.Value.region.width, kv.Value.region.height);
  81. Sprite sprite = Sprite.Create(texture2D, rect, new Vector2(0.5f, 0.5f));
  82. sprite.name = kv.Value.name;
  83. CloseSpriteDic.Add(sprite.name, sprite);
  84. }
  85. }
  86. }
  87. #endregion
  88. DressRoom = ManaReso.Get("DressRoom", Folder.Discard, true, null, true, ObjType.DressRoom);
  89. List<XmlAttributeCollection> attributeList = ManaData.GetDressRoomConfig();
  90. Player.JumpFrequency = float.Parse(attributeList[0][1].Value);
  91. for (int i = 1; i < attributeList.Count; i++)
  92. {
  93. new CloseUnit(attributeList[i]);
  94. }
  95. List<int> dressList = ManaData.GetDressList();
  96. for (int i = 0; i < dressList.Count; i++)
  97. {
  98. BoughtCloseList.Add(dressList[i]);
  99. CloseUnitDic[dressList[i]].Unlock();
  100. }
  101. #endregion
  102. }
  103. public override void RegistValueA()
  104. {
  105. Instance = this;
  106. ManaReso.Get("DressRoom").CreateTweenSr(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  107. }
  108. public Player GetPlayer(string type = null, XmlNode xmlNode = null)
  109. {
  110. List<string> DressData = new List<string>();
  111. if (type == null && xmlNode == null)
  112. {
  113. DressData = ManaData.GetDressData();
  114. }
  115. else
  116. {
  117. if (type == null)
  118. {
  119. DressData = ManaData.GetDressData(xmlNode);
  120. }
  121. else
  122. {
  123. if (type == "PlayerBlond")
  124. {
  125. DressData.Add("脑壳1");
  126. DressData.Add("裙子1");
  127. DressData.Add("鞋子1");
  128. DressData.Add("头饰品1");
  129. DressData.Add("上衣1");
  130. DressData.Add("眼睛1");
  131. DressData.Add("嘴巴1");
  132. }
  133. else if (type == "PlayerBrown")
  134. {
  135. DressData.Add("脑壳2");
  136. DressData.Add("裙子2");
  137. DressData.Add("鞋子2");
  138. DressData.Add("头饰品2");
  139. DressData.Add("上衣2");
  140. DressData.Add("眼睛2");
  141. DressData.Add("嘴巴2");
  142. }
  143. else if (type == "PlayerPink")
  144. {
  145. DressData.Add("脑壳3");
  146. DressData.Add("裙子3");
  147. DressData.Add("鞋子3");
  148. DressData.Add("头饰品3");
  149. DressData.Add("上衣3");
  150. DressData.Add("眼睛3");
  151. DressData.Add("嘴巴3");
  152. }
  153. }
  154. }
  155. Transform tra = ManaReso.Get("Player", Folder.Scene, false, transform, ManaReso.Get("PlayerPosTra").position, ObjType.Player);
  156. Player = tra.GetComponent<Player>();
  157. if (Player == null)
  158. {
  159. Player = tra.AddScript<Player>();
  160. Player.BuildBlond();
  161. }
  162. BuildPlayer(DressData);
  163. Player.SetAllCollider(true);
  164. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  165. ManaReso.TraDic.Add(tra.name, tra);
  166. return Player;
  167. }
  168. public static void BuildPlayer(List<string> dressData)
  169. {
  170. Player.ChangeClose(BodyPart.Head, dressData[0]);
  171. Player.ChangeClose(BodyPart.Dress, dressData[1]);
  172. Player.ChangeClose(BodyPart.Shoe, dressData[2]);
  173. Player.ChangeClose(BodyPart.Headwear, dressData[3]);
  174. Player.ChangeClose(BodyPart.Top, dressData[4]);
  175. Player.ChangeClose(BodyPart.Eye, dressData[5]);
  176. Player.ChangeClose(BodyPart.Mouse, dressData[6]);
  177. }
  178. }