ManaPlayer.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 Object = UnityEngine.Object;
  15. using Transform = UnityEngine.Transform;
  16. public class ManaPlayer : Regist
  17. {
  18. #region 变量
  19. public static bool Complete;
  20. public static Transform SeleTra;
  21. public static Player Player;
  22. public static Transform DressRoom;
  23. public static Transform PlayerPink;
  24. public static Transform PlayerBlond;
  25. public static Transform PlayerBrown;
  26. public static ManaPlayer Instance;
  27. public static List<int>BoughtCloseList = new List<int>();
  28. public static List<string> DressData = new List<string>();
  29. public static Dictionary<int, CloseUnit> CloseUnitDic = new Dictionary<int, CloseUnit>();
  30. public static Dictionary<string, int> CloseIDDic = new Dictionary<string, int>();
  31. public static Dictionary<string, Sprite> CloseSpriteDic = new Dictionary<string, Sprite>();
  32. #endregion
  33. public override void Instantiate()
  34. {
  35. #region Player
  36. if (!Complete)
  37. {
  38. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  39. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  40. Complete = true;
  41. }
  42. if (!ManaTutorial.TutorialA || ManaTutorial.TutorialIndexA != 1)
  43. {
  44. GetPlayer();
  45. DressData = ManaData.GetDressData();
  46. }
  47. else
  48. {
  49. PlayerPink = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos3"), false, ObjType.Player);
  50. PlayerBlond = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos2"), false, ObjType.Player);
  51. PlayerBrown = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos1"), false, ObjType.Player);
  52. if (PlayerPink.GetComponent<Player>() == null)
  53. {
  54. PlayerPink.AddScript<Player>().BuildPink();
  55. //PlayerPink.transform.position = ManaReso.Get("PlayerPos3").position;
  56. }
  57. if (PlayerBlond.GetComponent<Player>() == null)
  58. {
  59. PlayerBlond.AddScript<Player>().BuildBlond();
  60. //PlayerPink.transform.position = ManaReso.Get("PlayerPos2").position;
  61. }
  62. if (PlayerBrown.GetComponent<Player>() == null)
  63. {
  64. PlayerBrown.AddScript<Player>().BuildBrown();
  65. //PlayerPink.transform.position = ManaReso.Get("PlayerPos1").position;
  66. }
  67. PlayerPink.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  68. PlayerBlond.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  69. PlayerBrown.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  70. SeleTra = PlayerBlond;
  71. }
  72. #endregion
  73. #region DressRoom
  74. List<XmlAttributeCollection> attributeList = ManaData.GetDressRoomConfig();
  75. Player.JumpFrequency = float.Parse(attributeList[0][1].Value);
  76. DressRoom = ManaReso.Get("DressRoom", Folder.Discard, true, null, true, ObjType.DressRoom);
  77. DressRoom.SetActive(false);
  78. List<int> dressList = ManaData.GetDressList();
  79. for (int i = 0; i < dressList.Count; i++)
  80. {
  81. BoughtCloseList.Add(dressList[i]);
  82. }
  83. #endregion
  84. }
  85. public override void RegistValueA()
  86. {
  87. Instance = this;
  88. ManaReso.Get("DressRoom").CreateTweenSr(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  89. }
  90. public static void InitializeDressRoom()
  91. {
  92. if (Initializer.Instance.DebugMode)
  93. {
  94. #if UNITY_EDITOR
  95. string assetPath = AssetDatabase.GetAssetPath(ManaReso.Load<Texture2D>("stand_texture", Folder.Scene));
  96. Object[] objects = AssetDatabase.LoadAllAssetsAtPath(assetPath);
  97. for (int i = 0; i < objects.Length; i++)
  98. {
  99. Sprite sprite = objects[i] as Sprite;
  100. if (sprite != null)
  101. {
  102. CloseSpriteDic.Add(sprite.name, sprite);
  103. }
  104. }
  105. #endif
  106. }
  107. else
  108. {
  109. Object[] objects = Bundle.Scene.LoadAssetWithSubAssets("stand_texture", typeof(Sprite));
  110. for (int i = 0; i < objects.Length; i++)
  111. {
  112. Sprite sprite = (Sprite)objects[i];
  113. CloseSpriteDic.Add(sprite.name, sprite);
  114. }
  115. }
  116. List<XmlAttributeCollection> attributeList = ManaData.GetDressRoomConfig();
  117. for (int i = 1; i < attributeList.Count; i++)
  118. {
  119. new CloseUnit(attributeList[i]);
  120. }
  121. for (int i = 0; i < BoughtCloseList.Count; i++)
  122. {
  123. CloseUnitDic[BoughtCloseList[i]].Unlock();
  124. }
  125. }
  126. public Player GetPlayer(XmlNode xmlNode = null)
  127. {
  128. List<string> DressData = new List<string>();
  129. if (xmlNode == null)
  130. {
  131. DressData = ManaData.GetDressData();
  132. }
  133. else
  134. {
  135. DressData = ManaData.GetDressData(xmlNode);
  136. }
  137. Transform tra = ManaReso.Get("Player", Folder.Scene, false, transform, false, ObjType.Player);
  138. tra.SetParent(ManaReso.Get("GardenNormal"));
  139. Player = tra.GetComponent<Player>();
  140. if (Player == null)
  141. {
  142. Player = tra.AddScript<Player>();
  143. Player.Build();
  144. }
  145. BuildPlayer(DressData);
  146. Player.SetAllCollider(true);
  147. Player.UAC.armature.flipX = false;
  148. Player.transform.position = ManaReso.Get("PlayerPosTra").position;
  149. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  150. ManaReso.TraDic.Add(tra.name, tra);
  151. return Player;
  152. }
  153. public static void BuildPlayer(List<string> dressData, Player player = null)
  154. {
  155. if (player == null)
  156. {
  157. player = Player;
  158. }
  159. player.ChangeClose(BodyPart.Head, dressData[0]);
  160. player.ChangeClose(BodyPart.Dress, dressData[1]);
  161. player.ChangeClose(BodyPart.Shoe, dressData[2]);
  162. player.ChangeClose(BodyPart.Headwear, dressData[3]);
  163. player.ChangeClose(BodyPart.Top, dressData[4]);
  164. player.ChangeClose(BodyPart.Eye, dressData[5]);
  165. player.ChangeClose(BodyPart.Mouse, dressData[6]);
  166. player.ChangeClose(BodyPart.Wing, dressData[7]);
  167. player.ChangeClose(BodyPart.LeftLongSleeve, dressData[8]);
  168. player.ChangeClose(BodyPart.LeftShortSleeve, dressData[9]);
  169. player.ChangeClose(BodyPart.RightLongSleeve, dressData[10]);
  170. player.ChangeClose(BodyPart.RightShortSleeve, dressData[11]);
  171. }
  172. }