ManaGarden.cs 7.9 KB

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