ManaGarden.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 Slot SeleSlot;
  71. public static FlowerInfo SeleFlowerInfo;
  72. public static List<Slot> SlotList;
  73. public static List<Slot> PlantList;
  74. public static List<FlowerInfo> FlowerInfoList;
  75. #endregion
  76. private void Awake()
  77. {
  78. ManaReso.Get("Garden", Folder.Object, true, transform, true).AddScript<Garden>();
  79. #region 生成FlowerItem
  80. PlantList = new List<Slot>();
  81. FlowerInfoList = new List<FlowerInfo>();
  82. List<XmlAttributeCollection> attributesList = Data.GetFlowerConfig();
  83. for (int i = 0; i < attributesList.Count; i++)
  84. {
  85. FlowerInfo flowerInfo = new FlowerInfo(attributesList[i]);
  86. if (flowerInfo.Special)
  87. {
  88. TotalFlowerSpec++;
  89. }
  90. else
  91. {
  92. TotalFlowerRegu++;
  93. }
  94. FlowerInfoList.Add(flowerInfo);
  95. }
  96. #endregion
  97. }
  98. public override void RegistValueA()
  99. {
  100. SlotList = new List<Slot>()
  101. {
  102. ManaReso.Get("SlotA1").AddComponent<Slot>(),
  103. ManaReso.Get("SlotA2").AddComponent<Slot>(),
  104. ManaReso.Get("SlotA3").AddComponent<Slot>(),
  105. ManaReso.Get("SlotA4").AddComponent<Slot>(),
  106. ManaReso.Get("SlotA5").AddComponent<Slot>(),
  107. ManaReso.Get("SlotA6").AddComponent<Slot>(),
  108. ManaReso.Get("SlotA7").AddComponent<Slot>(),
  109. ManaReso.Get("SlotA8").AddComponent<Slot>(),
  110. ManaReso.Get("SlotA9").AddComponent<Slot>(),
  111. ManaReso.Get("SlotB1").AddComponent<Slot>(),
  112. ManaReso.Get("SlotB2").AddComponent<Slot>(),
  113. ManaReso.Get("SlotB3").AddComponent<Slot>(),
  114. ManaReso.Get("SlotB4").AddComponent<Slot>(),
  115. ManaReso.Get("SlotB5").AddComponent<Slot>(),
  116. ManaReso.Get("SlotB6").AddComponent<Slot>(),
  117. ManaReso.Get("SlotB7").AddComponent<Slot>(),
  118. ManaReso.Get("SlotB8").AddComponent<Slot>(),
  119. ManaReso.Get("SlotB9").AddComponent<Slot>(),
  120. };
  121. }
  122. public static void SetFlowerCard(FlowerInfo flowerInfo)
  123. {
  124. SeleFlowerInfo = flowerInfo;
  125. ManaReso.SetText("H_Lab", flowerInfo.Name);
  126. Image image = ManaReso.Get<Image>("H_Icon2");
  127. image.sprite = flowerInfo.Sprite;
  128. Vector2 newSize = flowerInfo.Sprite.rect.size;
  129. newSize.x *= 0.65f;
  130. newSize.y *= 0.65f;
  131. image.rectTransform.sizeDelta = newSize;
  132. }
  133. public static void ShowPlantCard()
  134. {
  135. }
  136. public static void ShowRetrieveCard(FlowerInfo flowerInfo)
  137. {
  138. SeleSlot = flowerInfo.Slot;
  139. SetFlowerCard(flowerInfo);
  140. ManaReso.SetActive("H_Grid", false);
  141. ManaReso.SetActive("H_Prev", false);
  142. ManaReso.SetActive("H_Next", false);
  143. ManaReso.SetActive("H_Place", false);
  144. ManaReso.SetActive("H_Icon1", true);
  145. ManaReso.SetActive("H_Retrieve", true);
  146. ManaReso.Get("H_FlowerCard").TweenForCG();
  147. }
  148. public static void RetriveFlower()
  149. {
  150. SeleSlot.Retrieve();
  151. }
  152. public static void RetriveFlowerAll()
  153. {
  154. for (int i = 0; i < PlantList.Count; i++)
  155. {
  156. PlantList[i].Retrieve();
  157. i--;
  158. }
  159. }
  160. public static void PlantFlower()
  161. {
  162. SeleSlot.Plant(SeleFlowerInfo);
  163. }
  164. public static void PlantFlower(FlowerInfo flowerInfo)
  165. {
  166. if (flowerInfo.Plant)
  167. {
  168. ShowRetrieveCard(flowerInfo);
  169. }
  170. else
  171. {
  172. Slot slot = null;
  173. for (int i = 0; i < SlotList.Count; i++)
  174. {
  175. if (SlotList[i].Available)
  176. {
  177. slot = SlotList[i];
  178. break;
  179. }
  180. }
  181. if (slot == null)
  182. {
  183. ManaDebug.Log("已经没有空地了");
  184. }
  185. else
  186. {
  187. slot.Plant(flowerInfo);
  188. }
  189. }
  190. }
  191. public static void PlantFlower(int id, string parName)
  192. {
  193. Slot slot = ManaReso.Get<Slot>(parName);
  194. FlowerInfo flowerInfo = FlowerInfoList[id];
  195. slot.Plant(flowerInfo);
  196. }
  197. }