PlayerManager.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. DressData = ConfigManager.GetDefaultDressDatas();
  131. break;
  132. }
  133. }
  134. BuildPlayer(DressData);
  135. Player.SetAllCollider(true);
  136. Player.Flip(PlayerDirection.Left);
  137. Player.transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  138. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  139. ResourceManager.TransformDictionary.Add(tra.name, tra);
  140. return Player;
  141. }
  142. public Player GetRawPlayer()
  143. {
  144. Transform trans = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, null, false, ObjType.Player);
  145. var player = trans.GetComponent<Player>();
  146. if (player == null)
  147. {
  148. player = trans.AddScript<Player>();
  149. player.BuildBlond();
  150. }
  151. //BuildPlayer(dressData, player, false);
  152. return player;
  153. }
  154. public static void BuildPlayer(List<string> dressData, Player player = null, bool resetDepth = true)
  155. {
  156. if (player == null)
  157. {
  158. player = Player;
  159. }
  160. player.ChangeClose(BodyPart.Head, dressData[0], resetDepth);
  161. player.ChangeClose(BodyPart.Dress, dressData[1], resetDepth);
  162. player.ChangeClose(BodyPart.Shoe, dressData[2], resetDepth);
  163. player.ChangeClose(BodyPart.Headwear, dressData[3], resetDepth);
  164. player.ChangeClose(BodyPart.Top, dressData[4], resetDepth);
  165. player.ChangeClose(BodyPart.Eye, dressData[5], resetDepth);
  166. player.ChangeClose(BodyPart.Mouse, dressData[6], resetDepth);
  167. player.ChangeClose(BodyPart.Wing, dressData[7], resetDepth);
  168. player.ChangeClose(BodyPart.LeftLongSleeve, dressData[8], resetDepth);
  169. player.ChangeClose(BodyPart.LeftShortSleeve, dressData[9], resetDepth);
  170. player.ChangeClose(BodyPart.RightLongSleeve, dressData[10], resetDepth);
  171. player.ChangeClose(BodyPart.RightShortSleeve, dressData[11], resetDepth);
  172. }
  173. public static void CreateCloseItems(List<XmlAttributeCollection> attributeList)
  174. {
  175. for (int i = 0; i < attributeList.Count; i++)
  176. {
  177. new CloseItem(attributeList[i]);
  178. }
  179. }
  180. public static void InitDressRoom()
  181. {
  182. //foreach (var kv in CloseItemDictionary)
  183. //{
  184. // Debug.Log(kv.Value.ArmatureName);
  185. //}
  186. for (int i = 0; i < BoughtCloseIDs.Count; i++)
  187. {
  188. CloseItemDictionary[BoughtCloseIDs[i]].Unlock();
  189. }
  190. }
  191. public static Texture2D GetCloseTexture(string closeName)
  192. {
  193. if (CloseTextureDictionary.ContainsKey(closeName))
  194. {
  195. return CloseTextureDictionary[closeName];
  196. }
  197. else
  198. {
  199. if (CloseSpriteDictionary.ContainsKey(closeName))
  200. {
  201. Texture2D texture = CloseSpriteDictionary[closeName].ToTexture();
  202. CloseTextureDictionary.Add(closeName, texture);
  203. return texture;
  204. }
  205. else
  206. {
  207. Debug.LogError("");
  208. return null;
  209. }
  210. }
  211. }
  212. }