PlayerManager.cs 7.5 KB

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