ManaGarden.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. using Random = UnityEngine.Random;
  11. public class ManaGarden : Regist
  12. {
  13. #region 变量
  14. public static int MyFlower
  15. {
  16. get { return _MyFlower; }
  17. set
  18. {
  19. _MyFlower = value;
  20. ManaReso.SetText("F_FlowerLab", string.Format("{0}", MyFlower));
  21. ManaReso.SetText("G_CollectLab1", string.Format("{0}/{1}", MyFlower, TotalFlower));
  22. }
  23. }
  24. public static int MyFlowerSpec
  25. {
  26. get { return _MyFlowerSpec; }
  27. set
  28. {
  29. _MyFlowerSpec = value;
  30. MyFlower = _MyFlowerSpec + _MyFlowerRegu;
  31. }
  32. }
  33. public static int MyFlowerRegu
  34. {
  35. get { return _MyFlowerRegu; }
  36. set
  37. {
  38. _MyFlowerRegu = value;
  39. MyFlower = _MyFlowerSpec + _MyFlowerRegu;
  40. }
  41. }
  42. public static int TotalFlower
  43. {
  44. get { return _TotalFlower; }
  45. set { _TotalFlower = value; }
  46. }
  47. public static int TotalFlowerSpec
  48. {
  49. get { return _TotalFlowerSpec; }
  50. set
  51. {
  52. _TotalFlowerSpec = value;
  53. TotalFlower = _TotalFlowerSpec + _TotalFlowerRegu;
  54. }
  55. }
  56. public static int TotalFlowerRegu
  57. {
  58. get { return _TotalFlowerRegu; }
  59. set
  60. {
  61. _TotalFlowerRegu = value;
  62. TotalFlower = _TotalFlowerSpec + _TotalFlowerRegu;
  63. }
  64. }
  65. private static int _MyFlower;
  66. private static int _MyFlowerSpec;
  67. private static int _MyFlowerRegu;
  68. private static int _TotalFlower;
  69. private static int _TotalFlowerSpec;
  70. private static int _TotalFlowerRegu;
  71. public static bool Award;
  72. public static bool AwardLock;
  73. public static float AwardTimer;
  74. public static Slot SeleSlot;
  75. public static FlowerInfo SeleFlowerInfo;
  76. public static List<Slot> SlotList;
  77. public static List<Slot> PlantList;
  78. public static List<FlowerInfo> FlowerInfoList;
  79. #endregion
  80. public void FixedUpdate()
  81. {
  82. if (Award && !AwardLock)
  83. {
  84. AwardTimer -= Time.fixedDeltaTime;
  85. if (AwardTimer <= 0)
  86. {
  87. List<Flower> spareList = new List<Flower>();
  88. for (int i = 0; i < PlantList.Count; i++)
  89. {
  90. if (PlantList[i].Flower.Award == false)
  91. {
  92. spareList.Add(PlantList[i].Flower);
  93. }
  94. }
  95. if (spareList.Count == 1)
  96. {
  97. Award = false;
  98. spareList[0].Award = true;
  99. AwardTimer = Random.Range(20, 60);
  100. }
  101. else
  102. {
  103. spareList.Random().Award = true;
  104. AwardTimer = Random.Range(20, 60);
  105. }
  106. }
  107. }
  108. }
  109. public override void Instantiate()
  110. {
  111. ManaReso.Get("Garden", Folder.Garden, true, transform, true).AddScript<Garden>();
  112. #region 生成FlowerItem
  113. PlantList = new List<Slot>();
  114. FlowerInfoList = new List<FlowerInfo>();
  115. List<XmlAttributeCollection> attributesList = Data.GetFlowerConfig();
  116. for (int i = 0; i < attributesList.Count; i++)
  117. {
  118. FlowerInfo flowerInfo = new FlowerInfo(attributesList[i]);
  119. if (flowerInfo.Special)
  120. {
  121. TotalFlowerSpec++;
  122. }
  123. else
  124. {
  125. TotalFlowerRegu++;
  126. }
  127. FlowerInfoList.Add(flowerInfo);
  128. }
  129. #endregion
  130. }
  131. public override void RegistValueA()
  132. {
  133. Award = true;
  134. AwardLock = false;
  135. AwardTimer = Random.Range(20, 60);
  136. SlotList = new List<Slot>()
  137. {
  138. ManaReso.Get("SlotA1").AddComponent<Slot>(),
  139. ManaReso.Get("SlotA2").AddComponent<Slot>(),
  140. ManaReso.Get("SlotA3").AddComponent<Slot>(),
  141. ManaReso.Get("SlotA4").AddComponent<Slot>(),
  142. ManaReso.Get("SlotA5").AddComponent<Slot>(),
  143. ManaReso.Get("SlotA6").AddComponent<Slot>(),
  144. ManaReso.Get("SlotA7").AddComponent<Slot>(),
  145. ManaReso.Get("SlotA8").AddComponent<Slot>(),
  146. ManaReso.Get("SlotA9").AddComponent<Slot>(),
  147. ManaReso.Get("SlotB1").AddComponent<Slot>(),
  148. ManaReso.Get("SlotB2").AddComponent<Slot>(),
  149. ManaReso.Get("SlotB3").AddComponent<Slot>(),
  150. ManaReso.Get("SlotB4").AddComponent<Slot>(),
  151. ManaReso.Get("SlotB5").AddComponent<Slot>(),
  152. ManaReso.Get("SlotB6").AddComponent<Slot>(),
  153. ManaReso.Get("SlotB7").AddComponent<Slot>(),
  154. ManaReso.Get("SlotB8").AddComponent<Slot>(),
  155. ManaReso.Get("SlotB9").AddComponent<Slot>(),
  156. };
  157. }
  158. public static void UnlockSlot()
  159. {
  160. for (int i = 0; i < SlotList.Count; i++)
  161. {
  162. if (SlotList[i].Valid == false)
  163. {
  164. ManaData.Slot++;
  165. SlotList[i].Valid = true;
  166. return;
  167. }
  168. }
  169. ManaDebug.Log("所有土地已解锁");
  170. }
  171. public static void SetFlowerCard(FlowerInfo flowerInfo)
  172. {
  173. SeleFlowerInfo = flowerInfo;
  174. ManaReso.SetText("H_Lab", flowerInfo.Name);
  175. Image image = ManaReso.Get<Image>("H_Icon2");
  176. image.sprite = flowerInfo.Sprite;
  177. Vector2 newSize = flowerInfo.Sprite.rect.size;
  178. newSize.x *= 0.65f;
  179. newSize.y *= 0.65f;
  180. image.rectTransform.sizeDelta = newSize;
  181. }
  182. public static void ShowPlantCard(Slot slot, FlowerInfo flowerInfo)
  183. {
  184. ManaReso.Get("H_FlowerCard").TweenForCG();
  185. ManaReso.SetActive("H_Grid", true);
  186. ManaReso.SetActive("H_Prev", true);
  187. ManaReso.SetActive("H_Next", true);
  188. ManaReso.SetActive("H_Place", true);
  189. ManaReso.SetActive("H_Icon1", false);
  190. ManaReso.SetActive("H_Retrieve", false);
  191. SeleSlot = slot;
  192. SetFlowerCard(flowerInfo);
  193. }
  194. public static void ShowRetrieveCard(FlowerInfo flowerInfo)
  195. {
  196. SeleSlot = flowerInfo.Slot;
  197. SetFlowerCard(flowerInfo);
  198. ManaReso.SetActive("H_Grid", false);
  199. ManaReso.SetActive("H_Prev", false);
  200. ManaReso.SetActive("H_Next", false);
  201. ManaReso.SetActive("H_Place", false);
  202. ManaReso.SetActive("H_Icon1", true);
  203. ManaReso.SetActive("H_Retrieve", true);
  204. ManaReso.Get("H_FlowerCard").TweenForCG();
  205. }
  206. public static void RetriveFlower()
  207. {
  208. SeleSlot.Retrieve();
  209. }
  210. public static void RetriveFlowerAll()
  211. {
  212. for (int i = 0; i < PlantList.Count; i++)
  213. {
  214. PlantList[i].Retrieve();
  215. i--;
  216. }
  217. }
  218. public static void PlantFlower()
  219. {
  220. SeleSlot.Plant(SeleFlowerInfo);
  221. }
  222. public static void PlantFlower(FlowerInfo flowerInfo)
  223. {
  224. if (flowerInfo.Plant)
  225. {
  226. ShowRetrieveCard(flowerInfo);
  227. }
  228. else
  229. {
  230. Slot slot = null;
  231. for (int i = 0; i < SlotList.Count; i++)
  232. {
  233. if (SlotList[i].Available)
  234. {
  235. slot = SlotList[i];
  236. break;
  237. }
  238. }
  239. if (slot == null)
  240. {
  241. ManaDebug.Log("已经没有空地了");
  242. }
  243. else
  244. {
  245. slot.Plant(flowerInfo);
  246. }
  247. }
  248. }
  249. public static void PlantFlower(int id, string parName)
  250. {
  251. Slot slot = ManaReso.Get<Slot>(parName);
  252. FlowerInfo flowerInfo = FlowerInfoList[id];
  253. slot.Plant(flowerInfo);
  254. }
  255. }