PlayerManager.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using DragonBones;
  2. #if UNITY_EDITOR
  3. using UnityEditor;
  4. #endif
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using System;
  8. using System.Xml;
  9. using System.Text;
  10. using System.Linq;
  11. using System.Collections;
  12. using System.Diagnostics;
  13. using System.Collections.Generic;
  14. using Debug = UnityEngine.Debug;
  15. using Object = UnityEngine.Object;
  16. using Transform = UnityEngine.Transform;
  17. public class PlayerManager : Regist
  18. {
  19. #region Config
  20. public static bool Inited;
  21. public static Player Player;
  22. public static Transform DressRoom;
  23. public static Transform DefaultPinkPlayer;
  24. public static Transform DefaultBlondPlayer;
  25. public static Transform DefaultBrownPlayer;
  26. public static Transform SelectedPlayer;
  27. public static PlayerManager Instance;
  28. public static List<int>BoughtCloseIDs = new List<int>();
  29. public static List<string> DressDatas = new List<string>();
  30. public static Dictionary<int, CloseItem> CloseItemDictionary = new Dictionary<int, CloseItem>();
  31. public static Dictionary<string, int> CloseIDDictionary = new Dictionary<string, int>();
  32. public static Dictionary<string, Sprite> CloseSpriteDictionary = new Dictionary<string, Sprite>();
  33. public static Dictionary<string, Texture2D> CloseTextureDictionary = new Dictionary<string, Texture2D>();
  34. #endregion
  35. public override void InstantiatePrefabs()
  36. {
  37. #region Player
  38. Initializer.DebugText.text = "error : mp0";
  39. if (!Inited)
  40. {
  41. //Initializer.DebugText.text = "error : mp0-1";
  42. //UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  43. //Initializer.DebugText.text = "error : mp0-2";
  44. //UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex0, Folder.Config), ResourceLabel.StandTexture0);
  45. //Initializer.DebugText.text = "error : mp0-3";
  46. //UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex1, Folder.Config), ResourceLabel.StandTexture1);
  47. Inited = true;
  48. }
  49. Initializer.DebugText.text = "error : mp1";
  50. if (!TutorialManager.NewplayerTutorial || TutorialManager.NewplayerTutorialIndex != 1)
  51. {
  52. GetPlayer();
  53. DressDatas = ConfigManager.GetDressData();
  54. }
  55. else
  56. {
  57. DefaultPinkPlayer = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get(TutorialLabel.PinkPlayerPos), false, ObjType.Player);
  58. DefaultBlondPlayer = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get(TutorialLabel.BlondPlayerPos), false, ObjType.Player);
  59. DefaultBrownPlayer = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get(TutorialLabel.BrownPlayerPos), false, ObjType.Player);
  60. if (DefaultPinkPlayer.GetComponent<Player>() == null)
  61. {
  62. DefaultPinkPlayer.AddScript<Player>().BuildPink();
  63. }
  64. if (DefaultBlondPlayer.GetComponent<Player>() == null)
  65. {
  66. DefaultBlondPlayer.AddScript<Player>().BuildBlond();
  67. }
  68. if (DefaultBrownPlayer.GetComponent<Player>() == null)
  69. {
  70. DefaultBrownPlayer.AddScript<Player>().BuildBrown();
  71. }
  72. Vector3 tutorialPlayerScale = new Vector3(0.8f, 0.8f, 0.8f);
  73. DefaultPinkPlayer.localScale = tutorialPlayerScale;
  74. DefaultBlondPlayer.localScale = tutorialPlayerScale;
  75. DefaultBrownPlayer.localScale = tutorialPlayerScale;
  76. SelectedPlayer = DefaultBlondPlayer;
  77. }
  78. #endregion
  79. #region DressRoom
  80. Initializer.DebugText.text = "error : mp2";
  81. List<XmlAttributeCollection> attributeList = ConfigManager.GetDressRoomConfig();
  82. Player.InDressRoomJumpFrequency = float.Parse(attributeList[0][1].Value);
  83. Initializer.DebugText.text = "error : mp3";
  84. DressRoom = ResourceManager.Get(ResourceLabel.DressRoom, Folder.UI, true, null, true, ObjType.DressRoom);
  85. DressRoom.SetActive(false);
  86. DontDestroyOnLoad(DressRoom);
  87. Initializer.DebugText.text = "error : mp4";
  88. List<int> dressList = ConfigManager.GetDressList();
  89. Initializer.DebugText.text = "error : mp5";
  90. for (int i = 0; i < dressList.Count; i++)
  91. {
  92. BoughtCloseIDs.Add(dressList[i]);
  93. }
  94. #endregion
  95. }
  96. public override void FirstInit()
  97. {
  98. Instance = this;
  99. ResourceManager.Get(ResourceLabel.DressRoom).CreateTweenSr(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  100. }
  101. public Player GetPlayer(XmlNode xmlNode = null)
  102. {
  103. List<string> DressData = new List<string>();
  104. if (xmlNode == null)
  105. {
  106. DressData = ConfigManager.GetDressData();
  107. }
  108. else
  109. {
  110. DressData = ConfigManager.GetDressData(xmlNode);
  111. }
  112. Transform tra = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, transform, false, ObjType.Player);
  113. tra.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
  114. Player = tra.GetComponent<Player>();
  115. if (Player == null)
  116. {
  117. Player = tra.AddScript<Player>();
  118. Player.Build();
  119. }
  120. for (int i = 0; i < 8; i++)
  121. {
  122. if (i == 7 && DressData[i] == "Empty")
  123. {
  124. continue;
  125. }
  126. string armatureName = DressData[i];
  127. if (!CloseItemDictionary.Values.ToList().MyContains(item => item.ArmatureName == armatureName))
  128. {
  129. Debug.Log(armatureName);
  130. if (i == 0)
  131. {
  132. DressData[0] = "脑壳-缺失";
  133. }
  134. else if (i == 1)
  135. {
  136. DressData[1] = "裙子-缺失";
  137. }
  138. else if (i == 2)
  139. {
  140. DressData[2] = "鞋子-缺失";
  141. }
  142. else if (i == 3)
  143. {
  144. DressData[3] = "头饰-缺失";
  145. }
  146. else if (i == 4)
  147. {
  148. DressData[4] = "上衣-缺失";
  149. DressData[8] = "Empty";
  150. DressData[9] = "Empty";
  151. DressData[10] = "Empty";
  152. DressData[11] = "Empty";
  153. }
  154. else if (i == 5)
  155. {
  156. DressData[5] = "眼睛1";
  157. }
  158. else if (i == 6)
  159. {
  160. DressData[6] = "嘴巴1";
  161. }
  162. else if (i == 7)
  163. {
  164. DressData[7] = "翅膀-缺失";
  165. }
  166. //DressData = ConfigManager.GetDefaultDressDatas();
  167. }
  168. }
  169. BuildPlayer(DressData);
  170. Player.SetAllCollider(true);
  171. Player.Flip(PlayerDirection.Left);
  172. Player.transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  173. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  174. ResourceManager.TransformDictionary.Add(tra.name, tra);
  175. return Player;
  176. }
  177. public Player GetRawPlayer()
  178. {
  179. Transform trans = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, null, false, ObjType.Player);
  180. var player = trans.GetComponent<Player>();
  181. if (player == null)
  182. {
  183. player = trans.AddScript<Player>();
  184. player.BuildBlond();
  185. }
  186. //BuildPlayer(dressData, player, false);
  187. return player;
  188. }
  189. public static void BuildPlayer(List<string> dressData, Player player = null, bool resetDepth = true)
  190. {
  191. if (player == null)
  192. {
  193. player = Player;
  194. }
  195. player.ChangeClose(BodyPart.Head, dressData[0], resetDepth);
  196. player.ChangeClose(BodyPart.Dress, dressData[1], resetDepth);
  197. player.ChangeClose(BodyPart.Shoe, dressData[2], resetDepth);
  198. player.ChangeClose(BodyPart.Headwear, dressData[3], resetDepth);
  199. player.ChangeClose(BodyPart.Top, dressData[4], resetDepth);
  200. player.ChangeClose(BodyPart.Eye, dressData[5], resetDepth);
  201. player.ChangeClose(BodyPart.Mouse, dressData[6], resetDepth);
  202. player.ChangeClose(BodyPart.Wing, dressData[7], resetDepth);
  203. player.ChangeClose(BodyPart.LeftLongSleeve, dressData[8], resetDepth);
  204. player.ChangeClose(BodyPart.LeftShortSleeve, dressData[9], resetDepth);
  205. player.ChangeClose(BodyPart.RightLongSleeve, dressData[10], resetDepth);
  206. player.ChangeClose(BodyPart.RightShortSleeve, dressData[11], resetDepth);
  207. }
  208. public static void CreateCloseItems(List<XmlAttributeCollection> attributeList)
  209. {
  210. for (int i = 0; i < attributeList.Count; i++)
  211. {
  212. new CloseItem(attributeList[i]);
  213. }
  214. }
  215. public static void InitDressRoom()
  216. {
  217. //foreach (var kv in CloseItemDictionary)
  218. //{
  219. // Debug.Log(kv.Value.ArmatureName);
  220. //}
  221. for (int i = 0; i < BoughtCloseIDs.Count; i++)
  222. {
  223. CloseItemDictionary[BoughtCloseIDs[i]].Unlock();
  224. }
  225. }
  226. public static Texture2D GetCloseTexture(string closeName)
  227. {
  228. if (CloseTextureDictionary.ContainsKey(closeName))
  229. {
  230. return CloseTextureDictionary[closeName];
  231. }
  232. else
  233. {
  234. if (CloseSpriteDictionary.ContainsKey(closeName))
  235. {
  236. Texture2D texture = CloseSpriteDictionary[closeName].ToTexture();
  237. CloseTextureDictionary.Add(closeName, texture);
  238. return texture;
  239. }
  240. else
  241. {
  242. Debug.LogError("");
  243. return null;
  244. }
  245. }
  246. }
  247. }