ManaPlayer.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 ManaPlayer : Regist
  18. {
  19. #region 变量
  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 ManaPlayer Instance;
  28. public static List<int>BoughtCloseList = new List<int>();
  29. public static List<string> DressData = new List<string>();
  30. public static Dictionary<int, CloseUnit> CloseUnitDic = new Dictionary<int, CloseUnit>();
  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 Instantiate()
  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(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  42. Initializer.DebugLab.text = "error : mp0-2";
  43. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  44. Complete = true;
  45. }
  46. Initializer.DebugLab.text = "error : mp1";
  47. if (!ManaTutorial.TutorialA || ManaTutorial.TutorialIndexA != 1)
  48. {
  49. GetPlayer();
  50. DressData = ManaData.GetDressData();
  51. }
  52. else
  53. {
  54. PlayerPink = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos3"), false, ObjType.Player);
  55. PlayerBlond = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos2"), false, ObjType.Player);
  56. PlayerBrown = ManaReso.Get("Player", Folder.Scene, false, ManaReso.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 = ManaData.GetDressRoomConfig();
  81. Player.JumpFrequency = float.Parse(attributeList[0][1].Value);
  82. Initializer.DebugLab.text = "error : mp3";
  83. DressRoom = ManaReso.Get("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 = ManaData.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 RegistValueA()
  96. {
  97. Instance = this;
  98. ManaReso.Get("DressRoom").CreateTweenSr(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  99. }
  100. public static void InitializeDressRoom()
  101. {
  102. // if (Initializer.Instance.DebugMode)
  103. // {
  104. //#if UNITY_EDITOR
  105. // string assetPath = AssetDatabase.GetAssetPath(ManaReso.Load<Texture2D>("stand_texture", Folder.Scene));
  106. // Object[] objects = AssetDatabase.LoadAllAssetsAtPath(assetPath);
  107. // for (int i = 0; i < objects.Length; i++)
  108. // {
  109. // Sprite sprite = objects[i] as Sprite;
  110. // if (sprite != null)
  111. // {
  112. // CloseSpriteDic.Add(sprite.name, sprite);
  113. // }
  114. // }
  115. //#endif
  116. // }
  117. // else
  118. // {
  119. // Object[] objects = Bundle.Scene.LoadAssetWithSubAssets("stand_texture", typeof(Sprite));
  120. // for (int i = 0; i < objects.Length; i++)
  121. // {
  122. // Sprite sprite = (Sprite)objects[i];
  123. // CloseSpriteDic.Add(sprite.name, sprite);
  124. // }
  125. // }
  126. List<XmlAttributeCollection> attributeList = ManaData.GetDressRoomConfig();
  127. for (int i = 1; i < attributeList.Count; i++)
  128. {
  129. new CloseUnit(attributeList[i]);
  130. }
  131. for (int i = 0; i < BoughtCloseList.Count; i++)
  132. {
  133. //Debug.Log(BoughtCloseList[i]);
  134. CloseUnitDic[BoughtCloseList[i]].Unlock();
  135. }
  136. }
  137. public Player GetPlayer(XmlNode xmlNode = null)
  138. {
  139. List<string> DressData = new List<string>();
  140. if (xmlNode == null)
  141. {
  142. DressData = ManaData.GetDressData();
  143. }
  144. else
  145. {
  146. DressData = ManaData.GetDressData(xmlNode);
  147. }
  148. Transform tra = ManaReso.Get("Player", Folder.Scene, false, transform, false, ObjType.Player);
  149. tra.SetParent(ManaReso.Get("GardenNormal"));
  150. Player = tra.GetComponent<Player>();
  151. if (Player == null)
  152. {
  153. Player = tra.AddScript<Player>();
  154. Player.Build();
  155. }
  156. BuildPlayer(DressData);
  157. Player.SetAllCollider(true);
  158. Player.Flip(PlayerDirection.Left);
  159. Player.transform.position = ManaReso.Get("PlayerPosTra").position;
  160. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  161. ManaReso.TraDic.Add(tra.name, tra);
  162. return Player;
  163. }
  164. public static void BuildPlayer(List<string> dressData, Player player = null)
  165. {
  166. if (player == null)
  167. {
  168. player = Player;
  169. }
  170. player.ChangeClose(BodyPart.Head, dressData[0]);
  171. player.ChangeClose(BodyPart.Dress, dressData[1]);
  172. player.ChangeClose(BodyPart.Shoe, dressData[2]);
  173. player.ChangeClose(BodyPart.Headwear, dressData[3]);
  174. player.ChangeClose(BodyPart.Top, dressData[4]);
  175. player.ChangeClose(BodyPart.Eye, dressData[5]);
  176. player.ChangeClose(BodyPart.Mouse, dressData[6]);
  177. player.ChangeClose(BodyPart.Wing, dressData[7]);
  178. player.ChangeClose(BodyPart.LeftLongSleeve, dressData[8]);
  179. player.ChangeClose(BodyPart.LeftShortSleeve, dressData[9]);
  180. player.ChangeClose(BodyPart.RightLongSleeve, dressData[10]);
  181. player.ChangeClose(BodyPart.RightShortSleeve, dressData[11]);
  182. }
  183. }