PlayerManager.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. BuildPlayer(DressData);
  118. Player.SetAllCollider(true);
  119. Player.Flip(PlayerDirection.Left);
  120. Player.transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
  121. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  122. ResourceManager.TransformDictionary.Add(tra.name, tra);
  123. return Player;
  124. }
  125. public Player GetRawPlayer()
  126. {
  127. Transform trans = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, null, false, ObjType.Player);
  128. var player = trans.GetComponent<Player>();
  129. if (player == null)
  130. {
  131. player = trans.AddScript<Player>();
  132. player.BuildBlond();
  133. }
  134. //BuildPlayer(dressData, player, false);
  135. return player;
  136. }
  137. public static void BuildPlayer(List<string> dressData, Player player = null, bool resetDepth = true)
  138. {
  139. if (player == null)
  140. {
  141. player = Player;
  142. }
  143. player.ChangeClose(BodyPart.Head, dressData[0], resetDepth);
  144. player.ChangeClose(BodyPart.Dress, dressData[1], resetDepth);
  145. player.ChangeClose(BodyPart.Shoe, dressData[2], resetDepth);
  146. player.ChangeClose(BodyPart.Headwear, dressData[3], resetDepth);
  147. player.ChangeClose(BodyPart.Top, dressData[4], resetDepth);
  148. player.ChangeClose(BodyPart.Eye, dressData[5], resetDepth);
  149. player.ChangeClose(BodyPart.Mouse, dressData[6], resetDepth);
  150. player.ChangeClose(BodyPart.Wing, dressData[7], resetDepth);
  151. player.ChangeClose(BodyPart.LeftLongSleeve, dressData[8], resetDepth);
  152. player.ChangeClose(BodyPart.LeftShortSleeve, dressData[9], resetDepth);
  153. player.ChangeClose(BodyPart.RightLongSleeve, dressData[10], resetDepth);
  154. player.ChangeClose(BodyPart.RightShortSleeve, dressData[11], resetDepth);
  155. }
  156. public static void InitDressRoom()
  157. {
  158. List<XmlAttributeCollection> attributeList = ConfigManager.GetDressRoomConfig();
  159. for (int i = 1; i < attributeList.Count; i++)
  160. {
  161. new CloseItem(attributeList[i]);
  162. }
  163. for (int i = 0; i < BoughtCloseIDs.Count; i++)
  164. {
  165. //Debug.Log(BoughtCloseList[i]);
  166. CloseItemDictionary[BoughtCloseIDs[i]].Unlock();
  167. }
  168. }
  169. }