ManaGarden.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 == 0)
  96. {
  97. return;
  98. }
  99. if (spareList.Count == 1)
  100. {
  101. Award = false;
  102. spareList[0].Award = true;
  103. AwardTimer = Random.Range(20, 60);
  104. }
  105. else
  106. {
  107. spareList.Random().Award = true;
  108. AwardTimer = Random.Range(20, 60);
  109. }
  110. }
  111. }
  112. }
  113. public override void Instantiate()
  114. {
  115. ManaReso.Get("Garden", Folder.Garden, true, transform, true).AddScript<Garden>();
  116. #region 生成FlowerItem
  117. PlantList = new List<Slot>();
  118. FlowerInfoList = new List<FlowerInfo>();
  119. List<XmlAttributeCollection> attributesList = Data.GetFlowerConfig();
  120. for (int i = 0; i < attributesList.Count; i++)
  121. {
  122. FlowerInfo flowerInfo = new FlowerInfo(attributesList[i]);
  123. if (flowerInfo.Special)
  124. {
  125. TotalFlowerSpec++;
  126. }
  127. else
  128. {
  129. TotalFlowerRegu++;
  130. }
  131. FlowerInfoList.Add(flowerInfo);
  132. }
  133. #endregion
  134. }
  135. public override void RegistValueA()
  136. {
  137. Award = true;
  138. AwardLock = false;
  139. AwardTimer = Random.Range(20, 60);
  140. SlotList = new List<Slot>()
  141. {
  142. ManaReso.Get("SlotA1").AddComponent<Slot>(),
  143. ManaReso.Get("SlotA2").AddComponent<Slot>(),
  144. ManaReso.Get("SlotA3").AddComponent<Slot>(),
  145. ManaReso.Get("SlotA4").AddComponent<Slot>(),
  146. ManaReso.Get("SlotA5").AddComponent<Slot>(),
  147. ManaReso.Get("SlotA6").AddComponent<Slot>(),
  148. ManaReso.Get("SlotA7").AddComponent<Slot>(),
  149. ManaReso.Get("SlotA8").AddComponent<Slot>(),
  150. ManaReso.Get("SlotA9").AddComponent<Slot>(),
  151. ManaReso.Get("SlotB1").AddComponent<Slot>(),
  152. ManaReso.Get("SlotB2").AddComponent<Slot>(),
  153. ManaReso.Get("SlotB3").AddComponent<Slot>(),
  154. ManaReso.Get("SlotB4").AddComponent<Slot>(),
  155. ManaReso.Get("SlotB5").AddComponent<Slot>(),
  156. ManaReso.Get("SlotB6").AddComponent<Slot>(),
  157. ManaReso.Get("SlotB7").AddComponent<Slot>(),
  158. ManaReso.Get("SlotB8").AddComponent<Slot>(),
  159. ManaReso.Get("SlotB9").AddComponent<Slot>(),
  160. };
  161. }
  162. public static void UnlockSlot()
  163. {
  164. for (int i = 0; i < SlotList.Count; i++)
  165. {
  166. if (SlotList[i].Valid == false)
  167. {
  168. ManaData.Slot++;
  169. SlotList[i].Valid = true;
  170. SlotList[i].Available = true;
  171. return;
  172. }
  173. }
  174. ManaDebug.Log("所有土地已解锁");
  175. }
  176. public static void SetFlowerCard(FlowerInfo flowerInfo)
  177. {
  178. SeleFlowerInfo = flowerInfo;
  179. ManaText.Add(ManaReso.Get<Text>("H_Lab"), new LanStr("FlowerName", flowerInfo._Name));
  180. Image image = ManaReso.Get<Image>("H_Icon2");
  181. image.sprite = flowerInfo.Sprite;
  182. Vector2 newSize = flowerInfo.Sprite.rect.size;
  183. newSize.x *= 0.65f;
  184. newSize.y *= 0.65f;
  185. image.rectTransform.sizeDelta = newSize;
  186. }
  187. public static void ShowPlantCard(Slot slot, FlowerInfo flowerInfo)
  188. {
  189. ManaReso.Get("H_FlowerCard").TweenForCG();
  190. ManaReso.SetActive("H_Grid", true);
  191. ManaReso.SetActive("H_Prev", true);
  192. ManaReso.SetActive("H_Next", true);
  193. ManaReso.SetActive("H_Place", true);
  194. ManaReso.SetActive("H_Icon1", false);
  195. ManaReso.SetActive("H_Retrieve", false);
  196. SeleSlot = slot;
  197. SetFlowerCard(flowerInfo);
  198. }
  199. public static void ShowRetrieveCard(FlowerInfo flowerInfo)
  200. {
  201. SeleSlot = flowerInfo.Slot;
  202. SetFlowerCard(flowerInfo);
  203. ManaReso.SetActive("H_Grid", false);
  204. ManaReso.SetActive("H_Prev", false);
  205. ManaReso.SetActive("H_Next", false);
  206. ManaReso.SetActive("H_Place", false);
  207. ManaReso.SetActive("H_Icon1", true);
  208. ManaReso.SetActive("H_Retrieve", true);
  209. ManaReso.Get("H_FlowerCard").TweenForCG();
  210. }
  211. public static void RetriveFlower()
  212. {
  213. SeleSlot.Retrieve();
  214. if (PlantList.Count == 0)
  215. {
  216. Award = false;
  217. }
  218. }
  219. public static void RetriveFlowerAll()
  220. {
  221. for (int i = 0; i < PlantList.Count; i++)
  222. {
  223. PlantList[i].Retrieve();
  224. i--;
  225. }
  226. Award = false;
  227. }
  228. public static void PlantFlower()
  229. {
  230. SeleSlot.Plant(SeleFlowerInfo, true);
  231. }
  232. public static void PlantFlower(FlowerInfo flowerInfo)
  233. {
  234. if (flowerInfo.Plant)
  235. {
  236. ShowRetrieveCard(flowerInfo);
  237. }
  238. else
  239. {
  240. Slot slot = null;
  241. for (int i = 0; i < SlotList.Count; i++)
  242. {
  243. if (SlotList[i].Available)
  244. {
  245. slot = SlotList[i];
  246. break;
  247. }
  248. }
  249. if (slot == null)
  250. {
  251. ManaDebug.Log("已经没有空地了");
  252. }
  253. else
  254. {
  255. slot.Plant(flowerInfo, true);
  256. }
  257. }
  258. }
  259. public static void PlantFlower(int id, string parName)
  260. {
  261. Slot slot = ManaReso.Get<Slot>(parName);
  262. FlowerInfo flowerInfo = FlowerInfoList[id];
  263. slot.Plant(flowerInfo, false);
  264. }
  265. }