ManaPlayer.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using DragonBones;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System;
  5. using System.Xml;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Collections;
  9. using System.Diagnostics;
  10. using System.Collections.Generic;
  11. using Transform = UnityEngine.Transform;
  12. public class ManaPlayer : Regist
  13. {
  14. #region 变量
  15. public static bool Complete;
  16. public static string SelePlayer = "PlayerBlond";
  17. public static Transform SeleTra;
  18. public static Player Player;
  19. public static Transform DressRoom;
  20. public static Transform PlayerPink;
  21. public static Transform PlayerBlond;
  22. public static Transform PlayerBrown;
  23. public static ManaPlayer Instance;
  24. public static Dictionary<string, Sprite> CloseDic = new Dictionary<string, Sprite>();
  25. #endregion
  26. public override void Instantiate()
  27. {
  28. #region Player
  29. if (!Complete)
  30. {
  31. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("stand_ske", Folder.Config));
  32. UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("Closet_ske", Folder.Config));
  33. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
  34. UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("Closet_tex", Folder.Config), "Closet_texture");
  35. Complete = true;
  36. }
  37. if (!ManaTutorial.TutorialA || ManaTutorial.TutorialIndexA != 1)
  38. {
  39. SelePlayer = ManaData.GetPlayerString("Player");
  40. GetPlayer();
  41. }
  42. else
  43. {
  44. PlayerPink = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos3"), false, ObjType.PlayerPink);
  45. PlayerBlond = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos2"), false, ObjType.PlayerBlond);
  46. PlayerBrown = ManaReso.Get("Player", Folder.Scene, false, ManaReso.Get("PlayerPos1"), false, ObjType.PlayerBrown);
  47. if (PlayerPink.GetComponent<Player>() == null)
  48. {
  49. PlayerPink.AddScript<Player>().BuildPink();
  50. }
  51. if (PlayerBlond.GetComponent<Player>() == null)
  52. {
  53. PlayerBlond.AddScript<Player>().BuildBlond();
  54. }
  55. if (PlayerBrown.GetComponent<Player>() == null)
  56. {
  57. PlayerBrown.AddScript<Player>().BuildBrown();
  58. }
  59. PlayerPink.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  60. PlayerBlond.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  61. PlayerBrown.localScale = new Vector3(0.8f, 0.8f, 0.8f);
  62. SelePlayer = "PlayerBlond";
  63. SeleTra = PlayerBlond;
  64. }
  65. #endregion
  66. #region DressRoom
  67. #region Close
  68. List<List<TextureAtlasData>> textureAtlasDatalist = UnityFactory.factory.GetAllTextureAtlasData().Values.ToList();
  69. for (int i = 0; i < textureAtlasDatalist.Count; i++)
  70. {
  71. for (int j = 0; j < textureAtlasDatalist[i].Count; j++)
  72. {
  73. TextureAtlasData textureAtlasData = textureAtlasDatalist[i][j];
  74. string textureName = textureAtlasData.imagePath.Split('.')[0] + "ture";
  75. foreach (var kv in textureAtlasData.textures)
  76. {
  77. Texture2D texture2D = UnityFactory.AtlasDictionary[textureName];
  78. Rect rect = new Rect(kv.Value.region.x, texture2D.height - kv.Value.region.y - kv.Value.region.height, kv.Value.region.width, kv.Value.region.height);
  79. Sprite sprite = Sprite.Create(texture2D, rect, new Vector2(0.5f, 0.5f));
  80. sprite.name = kv.Value.name;
  81. CloseDic.Add(sprite.name, sprite);
  82. }
  83. }
  84. }
  85. #endregion
  86. DressRoom = ManaReso.Get("DressRoom", Folder.Discard, true, null, true, ObjType.DressRoom);
  87. List<XmlAttributeCollection> attributeList = ManaData.GetDressRoomConfig();
  88. Player.JumpFrequency = float.Parse(attributeList[0][1].Value);
  89. for (int i = 1; i < attributeList.Count; i++)
  90. {
  91. new CloseUnit(attributeList[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 void GetPlayer(string type = null)
  101. {
  102. string player;
  103. if (type == null)
  104. {
  105. player = ManaData.GetPlayerString("Player");
  106. }
  107. else
  108. {
  109. player = type;
  110. }
  111. Transform tra = ManaReso.Get("Player", Folder.Scene, false, transform, ManaReso.Get("PlayerPosTra").position, player.ToEnum<ObjType>());
  112. Player = tra.GetComponent<Player>();
  113. if (Player == null)
  114. {
  115. Player = tra.AddScript<Player>();
  116. if (player == "PlayerPink")
  117. {
  118. Player.BuildPink();
  119. }
  120. else if (player == "PlayerBlond")
  121. {
  122. Player.BuildBlond();
  123. }
  124. else if (player == "PlayerBrown")
  125. {
  126. Player.BuildBrown();
  127. }
  128. }
  129. Player.SetAllCollider(true);
  130. tra.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  131. ManaReso.TraDic.Add(tra.name, tra);
  132. }
  133. }