ManaGarden.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Linq;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. public class ManaGarden : Regist
  11. {
  12. #region 变量
  13. public static int MyFlower
  14. {
  15. get { return _MyFlower; }
  16. set
  17. {
  18. _MyFlower = value;
  19. ManaReso.SetText("F_FlowerLab", string.Format("{0}", MyFlower));
  20. ManaReso.SetText("G_CollectLab1", string.Format("{0}/{1}", MyFlower, TotalFlower));
  21. }
  22. }
  23. public static int MyFlowerSpec
  24. {
  25. get { return _MyFlowerSpec; }
  26. set
  27. {
  28. _MyFlowerSpec = value;
  29. MyFlower = _MyFlowerSpec + _MyFlowerRegu;
  30. }
  31. }
  32. public static int MyFlowerRegu
  33. {
  34. get { return _MyFlowerRegu; }
  35. set
  36. {
  37. _MyFlowerRegu = value;
  38. MyFlower = _MyFlowerSpec + _MyFlowerRegu;
  39. }
  40. }
  41. public static int TotalFlower
  42. {
  43. get { return _TotalFlower; }
  44. set { _TotalFlower = value; }
  45. }
  46. public static int TotalFlowerSpec
  47. {
  48. get { return _TotalFlowerSpec; }
  49. set
  50. {
  51. _TotalFlowerSpec = value;
  52. TotalFlower = _TotalFlowerSpec + _TotalFlowerRegu;
  53. }
  54. }
  55. public static int TotalFlowerRegu
  56. {
  57. get { return _TotalFlowerRegu; }
  58. set
  59. {
  60. _TotalFlowerRegu = value;
  61. TotalFlower = _TotalFlowerSpec + _TotalFlowerRegu;
  62. }
  63. }
  64. private static int _MyFlower;
  65. private static int _MyFlowerSpec;
  66. private static int _MyFlowerRegu;
  67. private static int _TotalFlower;
  68. private static int _TotalFlowerSpec;
  69. private static int _TotalFlowerRegu;
  70. public static int SeleId;
  71. public static Flower SeleFlower;
  72. public static Transform SelePosTra;
  73. public static List<Flower> PlantList;
  74. public static List<Transform> PosTraList;
  75. public static Dictionary<int, FlowerInfo> FlowerInfoDic;
  76. #endregion
  77. private void Awake()
  78. {
  79. ManaReso.Get("Garden", Folder.Object, true, transform, true).AddScript<Garden>();
  80. #region 生成FlowerItem
  81. PlantList = new List<Flower>();
  82. FlowerInfoDic = new Dictionary<int, FlowerInfo>();
  83. List<XmlAttributeCollection> attributesList = Data.GetFlowerConfig();
  84. for (int i = 0; i < attributesList.Count; i++)
  85. {
  86. FlowerInfo flowerInfo = new FlowerInfo(attributesList[i]);
  87. if (flowerInfo.Special)
  88. {
  89. TotalFlowerSpec++;
  90. }
  91. else
  92. {
  93. TotalFlowerRegu++;
  94. }
  95. FlowerInfoDic.Add(flowerInfo.Id, flowerInfo);
  96. }
  97. #endregion
  98. }
  99. public override void RegistValueA()
  100. {
  101. SeleId = 1;
  102. PosTraList = new List<Transform>()
  103. {
  104. ManaReso.Get("FlowerTraA1"),
  105. ManaReso.Get("FlowerTraA2"),
  106. ManaReso.Get("FlowerTraA3"),
  107. ManaReso.Get("FlowerTraA4"),
  108. ManaReso.Get("FlowerTraA5"),
  109. ManaReso.Get("FlowerTraA6"),
  110. ManaReso.Get("FlowerTraA7"),
  111. ManaReso.Get("FlowerTraA8"),
  112. ManaReso.Get("FlowerTraA9"),
  113. ManaReso.Get("FlowerTraB1"),
  114. ManaReso.Get("FlowerTraB2"),
  115. ManaReso.Get("FlowerTraB3"),
  116. ManaReso.Get("FlowerTraB4"),
  117. ManaReso.Get("FlowerTraB5"),
  118. ManaReso.Get("FlowerTraB6"),
  119. ManaReso.Get("FlowerTraB7"),
  120. ManaReso.Get("FlowerTraB8"),
  121. ManaReso.Get("FlowerTraB9"),
  122. };
  123. }
  124. public static void SetFlowerCard(int id)
  125. {
  126. SeleId = id;
  127. FlowerInfo flowerInfo = FlowerInfoDic[id];
  128. ManaReso.SetText("H_Lab", flowerInfo.Name);
  129. Image image = ManaReso.Get<Image>("H_Icon2");
  130. image.sprite = flowerInfo.Sprite;
  131. Vector2 newSize = flowerInfo.Sprite.rect.size;
  132. newSize.x *= 0.65f;
  133. newSize.y *= 0.65f;
  134. image.rectTransform.sizeDelta = newSize;
  135. }
  136. public static void RetriveFlower()
  137. {
  138. ManaReso.Save(SeleFlower);
  139. PlantList.Remove(SeleFlower);
  140. FlowerInfo flowerInfo = FlowerInfoDic[SeleFlower.Id];
  141. flowerInfo.Plant = false;
  142. SeleFlower.ParTra.SetCollider(true);
  143. }
  144. public static void RetriveFlowerAll()
  145. {
  146. for (int i = 0; i < PlantList.Count; i++)
  147. {
  148. ManaReso.Save(PlantList[i]);
  149. PlantList[i].ParTra.SetCollider(true);
  150. PlantList.RemoveAt(i--);
  151. }
  152. foreach (var kv in FlowerInfoDic)
  153. {
  154. kv.Value.Plant = false;
  155. }
  156. }
  157. public static void PlantFlower()
  158. {
  159. FlowerInfo flowerInfo = FlowerInfoDic[SeleId];
  160. if (flowerInfo.Plant)
  161. {
  162. ManaDebug.Log("已经种植过了");
  163. }
  164. else
  165. {
  166. flowerInfo.Plant = true;
  167. Flower flower = ManaReso.GetFlower(SeleId, true, SelePosTra);
  168. PlantList.Add(flower);
  169. }
  170. }
  171. public static void PlantFlower(int id)
  172. {
  173. Transform posTra = null;
  174. for (int i = 0; i < PosTraList.Count; i++)
  175. {
  176. if (PosTraList[i].childCount == 0)
  177. {
  178. posTra = PosTraList[i];
  179. break;
  180. }
  181. }
  182. if (posTra == null)
  183. {
  184. ManaDebug.Log("已经没有空地了");
  185. }
  186. else
  187. {
  188. FlowerInfo flowerInfo = FlowerInfoDic[id];
  189. if (flowerInfo.Plant)
  190. {
  191. ManaDebug.Log("已经种植过了");
  192. }
  193. else
  194. {
  195. flowerInfo.Plant = true;
  196. Flower flower = ManaReso.GetFlower(id, true, posTra);
  197. PlantList.Add(flower);
  198. posTra.SetCollider(false);
  199. }
  200. }
  201. }
  202. public static void PlantFlower(int id, Transform posTra)
  203. {
  204. FlowerInfo flowerInfo = FlowerInfoDic[id];
  205. flowerInfo.Plant = true;
  206. Flower flower = ManaReso.GetFlower(id, true, posTra);
  207. PlantList.Add(flower);
  208. posTra.SetCollider(false);
  209. }
  210. }