PlayerManager.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 Complete;
  21. public static Transform SeleTra;
  22. public static Player Player;
  23. public static Transform DressRoom;
  24. public static Transform PlayerPink;
  25. public static Transform PlayerBlond;
  26. public static Transform PlayerBrown;
  27. public static PlayerManager Instance;
  28. public static List<int>BoughtCloseList = new List<int>();
  29. public static List<string> DressData = new List<string>();
  30. public static Dictionary<int, CloseItem> CloseItemDic = new Dictionary<int, CloseItem>();
  31. public static Dictionary<string, int> CloseIDDic = new Dictionary<string, int>();
  32. public static Dictionary<string, Sprite> CloseSpriteDic = new Dictionary<string, Sprite>();
  33. #endregion
  34. public override void InstantiatePrefabs()
  35. {
  36. #region Player
  37. Initializer.DebugLab.text = "error : mp0";
  38. if (!Complete)
  39. {
  40. Initializer.DebugLab.text = "error : mp0-1";
  41. UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
  42. Initializer.DebugLab.text = "error : mp0-2";
  43. UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex, Folder.Config), ResourceLabel.StandTexture);
  44. Complete = true;
  45. }
  46. Initializer.DebugLab.text = "error : mp1";
  47. if (!TutorialManager.NewplayerTutorial || TutorialManager.NewplayerTutorialIndex != 1)
  48. {
  49. GetPlayer();
  50. DressData = ConfigManager.GetDressData();
  51. }
  52. else
  53. {
  54. PlayerPink = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get("PlayerPos3"), false, ObjType.Player);
  55. PlayerBlond = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get("PlayerPos2"), false, ObjType.Player);
  56. PlayerBrown = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, ResourceManager.Get("PlayerPos1"), false, ObjType.Player);
  57. if (PlayerPink.GetComponent<Player>() == null)
  58. {
  59. PlayerPink.AddScript<Player>().BuildPink();
  60. //PlayerPink.transform.position = ManaReso.Get("PlayerPos3").position;
  61. }
  62. if (PlayerBlond.GetComponent<Player>() == null)
  63. {
  64. PlayerBlond.AddScript<Player>().BuildBlond();
  65. //PlayerPink.transform.position = ManaReso.Get("PlayerPos2").position;
  66. }
  67. if (PlayerBrown.GetComponent<Player>() == null)
  68. {
  69. PlayerBrown.AddScript<Player>().BuildBrown();
  70. //PlayerPink.transform.position = ManaReso.Get("PlayerPos1").position;
  71. }
  72. PlayerPink.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  73. PlayerBlond.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  74. PlayerBrown.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  75. SeleTra = PlayerBlond;
  76. }
  77. #endregion
  78. #region DressRoom
  79. Initializer.DebugLab.text = "error : mp2";
  80. List<XmlAttributeCollection> attributeList = ConfigManager.GetDressRoomConfig();
  81. Player.JumpFrequency = float.Parse(attributeList[0][1].Value);
  82. Initializer.DebugLab.text = "error : mp3";
  83. DressRoom = ResourceManager.Get(ResourceLabel.DressRoom, Folder.Scene, true, null, true, ObjType.DressRoom);
  84. DressRoom.SetActive(false);
  85. DontDestroyOnLoad(DressRoom);
  86. Initializer.DebugLab.text = "error : mp4";
  87. List<int> dressList = ConfigManager.GetDressList();
  88. Initializer.DebugLab.text = "error : mp5";
  89. for (int i = 0; i < dressList.Count; i++)
  90. {
  91. BoughtCloseList.Add(dressList[i]);
  92. }
  93. #endregion
  94. }
  95. public override void FirstInit()
  96. {
  97. Instance = this;
  98. ResourceManager.Get(ResourceLabel.DressRoom).CreateTweenSr(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  99. }
  100. public static void InitializeDressRoom()
  101. {
  102. List<XmlAttributeCollection> attributeList = ConfigManager.GetDressRoomConfig();
  103. for (int i = 1; i < attributeList.Count; i++)
  104. {
  105. new CloseItem(attributeList[i]);
  106. }
  107. for (int i = 0; i < BoughtCloseList.Count; i++)
  108. {
  109. //Debug.Log(BoughtCloseList[i]);
  110. CloseItemDic[BoughtCloseList[i]].Unlock();
  111. }
  112. }
  113. public Player GetPlayer(XmlNode xmlNode = null)
  114. {
  115. List<string> DressData = new List<string>();
  116. if (xmlNode == null)
  117. {
  118. DressData = ConfigManager.GetDressData();
  119. }
  120. else
  121. {
  122. DressData = ConfigManager.GetDressData(xmlNode);
  123. }
  124. Transform tra = ResourceManager.Get(ResourceLabel.Player, Folder.Scene, false, transform, false, ObjType.Player);
  125. tra.SetParent(ResourceManager.Get("GardenNormal"));
  126. Player = tra.GetComponent<Player>();
  127. if (Player == null)
  128. {
  129. Player = tra.AddScript<Player>();
  130. Player.Build();
  131. }
  132. BuildPlayer(DressData);
  133. Player.SetAllCollider(true);
  134. Player.Flip(PlayerDirection.Left);
  135. Player.transform.position = ResourceManager.Get("PlayerPosTra").position;
  136. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  137. ResourceManager.TraDic.Add(tra.name, tra);
  138. return Player;
  139. }
  140. public static void BuildPlayer(List<string> dressData, Player player = null)
  141. {
  142. if (player == null)
  143. {
  144. player = Player;
  145. }
  146. player.ChangeClose(BodyPart.Head, dressData[0]);
  147. player.ChangeClose(BodyPart.Dress, dressData[1]);
  148. player.ChangeClose(BodyPart.Shoe, dressData[2]);
  149. player.ChangeClose(BodyPart.Headwear, dressData[3]);
  150. player.ChangeClose(BodyPart.Top, dressData[4]);
  151. player.ChangeClose(BodyPart.Eye, dressData[5]);
  152. player.ChangeClose(BodyPart.Mouse, dressData[6]);
  153. player.ChangeClose(BodyPart.Wing, dressData[7]);
  154. player.ChangeClose(BodyPart.LeftLongSleeve, dressData[8]);
  155. player.ChangeClose(BodyPart.LeftShortSleeve, dressData[9]);
  156. player.ChangeClose(BodyPart.RightLongSleeve, dressData[10]);
  157. player.ChangeClose(BodyPart.RightShortSleeve, dressData[11]);
  158. }
  159. }