PlayerManager.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.StandTex, Folder.Config), ResourceLabel.StandTexture);
  45. Inited = true;
  46. }
  47. Initializer.DebugText.text = "error : mp1";
  48. if (!TutorialManager.NewplayerTutorial || TutorialManager.NewplayerTutorialIndex != 1)
  49. {
  50. GetPlayer();
  51. DressDatas = ConfigManager.GetDressData();
  52. }
  53. else
  54. {
  55. DefaultPinkPlayer = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get(TutorialLabel.PinkPlayerPos), false, ObjType.Player);
  56. DefaultBlondPlayer = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get(TutorialLabel.BlondPlayerPos), false, ObjType.Player);
  57. DefaultBrownPlayer = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get(TutorialLabel.BrownPlayerPos), false, ObjType.Player);
  58. if (DefaultPinkPlayer.GetComponent<Player>() == null)
  59. {
  60. DefaultPinkPlayer.AddScript<Player>().BuildPink();
  61. }
  62. if (DefaultBlondPlayer.GetComponent<Player>() == null)
  63. {
  64. DefaultBlondPlayer.AddScript<Player>().BuildBlond();
  65. }
  66. if (DefaultBrownPlayer.GetComponent<Player>() == null)
  67. {
  68. DefaultBrownPlayer.AddScript<Player>().BuildBrown();
  69. }
  70. Vector3 tutorialPlayerScale = new Vector3(0.8f, 0.8f, 0.8f);
  71. DefaultPinkPlayer.localScale = tutorialPlayerScale;
  72. DefaultBlondPlayer.localScale = tutorialPlayerScale;
  73. DefaultBrownPlayer.localScale = tutorialPlayerScale;
  74. SelectedPlayer = DefaultBlondPlayer;
  75. }
  76. #endregion
  77. #region DressRoom
  78. Initializer.DebugText.text = "error : mp2";
  79. List<XmlAttributeCollection> attributeList = ConfigManager.GetDressRoomConfig();
  80. Player.InDressRoomJumpFrequency = float.Parse(attributeList[0][1].Value);
  81. Initializer.DebugText.text = "error : mp3";
  82. DressRoom = ResourceManager.Get(ResourceLabel.DressRoom, Folder.UI, true, null, true, ObjType.DressRoom);
  83. DressRoom.SetActive(false);
  84. DontDestroyOnLoad(DressRoom);
  85. Initializer.DebugText.text = "error : mp4";
  86. List<int> dressList = ConfigManager.GetDressList();
  87. Initializer.DebugText.text = "error : mp5";
  88. for (int i = 0; i < dressList.Count; i++)
  89. {
  90. BoughtCloseIDs.Add(dressList[i]);
  91. }
  92. #endregion
  93. }
  94. public override void FirstInit()
  95. {
  96. Instance = this;
  97. ResourceManager.Get(ResourceLabel.DressRoom).CreateTweenSr(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  98. }
  99. public Player GetPlayer(XmlNode xmlNode = null)
  100. {
  101. List<string> DressData = new List<string>();
  102. if (xmlNode == null)
  103. {
  104. DressData = ConfigManager.GetDressData();
  105. }
  106. else
  107. {
  108. DressData = ConfigManager.GetDressData(xmlNode);
  109. }
  110. Transform tra = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, transform, false, ObjType.Player);
  111. tra.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
  112. Player = tra.GetComponent<Player>();
  113. if (Player == null)
  114. {
  115. Player = tra.AddScript<Player>();
  116. Player.Build();
  117. }
  118. for (int i = 0; i < 8; i++)
  119. {
  120. if (i == 7 && DressData[i] == "Empty")
  121. {
  122. continue;
  123. }
  124. string armatureName = DressData[i];
  125. if (!CloseItemDictionary.Values.ToList().MyContains(item => item.ArmatureName == armatureName))
  126. {
  127. Debug.Log(armatureName);
  128. DressData = ConfigManager.GetDefaultDressDatas();
  129. break;
  130. }
  131. }
  132. BuildPlayer(DressData);
  133. Player.SetAllCollider(true);
  134. Player.Flip(PlayerDirection.Left);
  135. Player.transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  136. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  137. ResourceManager.TransformDictionary.Add(tra.name, tra);
  138. return Player;
  139. }
  140. public Player GetRawPlayer()
  141. {
  142. Transform trans = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, null, false, ObjType.Player);
  143. var player = trans.GetComponent<Player>();
  144. if (player == null)
  145. {
  146. player = trans.AddScript<Player>();
  147. player.BuildBlond();
  148. }
  149. //BuildPlayer(dressData, player, false);
  150. return player;
  151. }
  152. public static void BuildPlayer(List<string> dressData, Player player = null, bool resetDepth = true)
  153. {
  154. if (player == null)
  155. {
  156. player = Player;
  157. }
  158. player.ChangeClose(BodyPart.Head, dressData[0], resetDepth);
  159. player.ChangeClose(BodyPart.Dress, dressData[1], resetDepth);
  160. player.ChangeClose(BodyPart.Shoe, dressData[2], resetDepth);
  161. player.ChangeClose(BodyPart.Headwear, dressData[3], resetDepth);
  162. player.ChangeClose(BodyPart.Top, dressData[4], resetDepth);
  163. player.ChangeClose(BodyPart.Eye, dressData[5], resetDepth);
  164. player.ChangeClose(BodyPart.Mouse, dressData[6], resetDepth);
  165. player.ChangeClose(BodyPart.Wing, dressData[7], resetDepth);
  166. player.ChangeClose(BodyPart.LeftLongSleeve, dressData[8], resetDepth);
  167. player.ChangeClose(BodyPart.LeftShortSleeve, dressData[9], resetDepth);
  168. player.ChangeClose(BodyPart.RightLongSleeve, dressData[10], resetDepth);
  169. player.ChangeClose(BodyPart.RightShortSleeve, dressData[11], resetDepth);
  170. }
  171. public static void CreateCloseItems(List<XmlAttributeCollection> attributeList)
  172. {
  173. for (int i = 0; i < attributeList.Count; i++)
  174. {
  175. new CloseItem(attributeList[i]);
  176. }
  177. }
  178. public static void InitDressRoom()
  179. {
  180. //foreach (var kv in CloseItemDictionary)
  181. //{
  182. // Debug.Log(kv.Value.ArmatureName);
  183. //}
  184. for (int i = 0; i < BoughtCloseIDs.Count; i++)
  185. {
  186. CloseItemDictionary[BoughtCloseIDs[i]].Unlock();
  187. }
  188. }
  189. public static Texture2D GetCloseTexture(string closeName)
  190. {
  191. if (CloseTextureDictionary.ContainsKey(closeName))
  192. {
  193. return CloseTextureDictionary[closeName];
  194. }
  195. else
  196. {
  197. if (CloseSpriteDictionary.ContainsKey(closeName))
  198. {
  199. Texture2D texture = CloseSpriteDictionary[closeName].ToTexture();
  200. CloseTextureDictionary.Add(closeName, texture);
  201. return texture;
  202. }
  203. else
  204. {
  205. Debug.LogError("");
  206. return null;
  207. }
  208. }
  209. }
  210. }