ManaGarden.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Linq;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. public class ManaGarden : MonoBehaviour
  10. {
  11. #region 变量
  12. public static Flower SelFlower;
  13. public static Transform SelFlowerTra;
  14. public static List<Sprite> FlowerIconList;
  15. public static List<Flower> PlantFlowerList;
  16. public static List<Transform> FlowerTraList;
  17. public static Dictionary<ObjType, Text> FlowerItemDic;
  18. #endregion
  19. private void Awake()
  20. {
  21. ManaReso.Get("Garden", Folder.Object, transform).AddComponent<Garden>();
  22. }
  23. public static void UpdateCollectSta()
  24. {
  25. ManaReso.SetText("G_Lab", ((FlowerItemDic.Count * 100) / 25f).ToString("0") + '%');
  26. ManaReso.SetText("G_IconLab", FlowerItemDic.Count + "/35");
  27. ManaReso.SetText("G_CollectLab", FlowerItemDic.Count + "/25");
  28. ManaReso.Get<Image>("G_CollectBk2").fillAmount = FlowerItemDic.Count / 25f;
  29. }
  30. public static void ShowFlowerCard(Flower flower = null)
  31. {
  32. ManaReso.Get("H_FlowerCard").Forward(TweenType.Alpha);
  33. if (flower != null)
  34. {
  35. SelFlower = flower;
  36. ManaReso.SetActive("H_Prev", false);
  37. ManaReso.SetActive("H_Next", false);
  38. ManaReso.SetActive("H_Place", false);
  39. ManaReso.SetActive("H_Retrieve", true);
  40. UpdateFlowerIcon(SelFlower.Sprite);
  41. }
  42. else
  43. {
  44. ManaReso.SetActive("H_Prev", true);
  45. ManaReso.SetActive("H_Next", true);
  46. ManaReso.SetActive("H_Place", true);
  47. ManaReso.SetActive("H_Retrieve", false);
  48. }
  49. }
  50. public static void UpdateFlowerIcon(Sprite sprite)
  51. {
  52. ManaReso.SetSprite("H_Icon", sprite);
  53. string spriteName = sprite.name;
  54. if (spriteName == "Flower0")
  55. {
  56. ManaReso.SetText("H_Lab", "波斯菊");
  57. }
  58. else if (spriteName == "Flower1")
  59. {
  60. ManaReso.SetText("H_Lab", "牵牛花");
  61. }
  62. else if (spriteName == "Flower2")
  63. {
  64. ManaReso.SetText("H_Lab", "蒲公英");
  65. }
  66. else if (spriteName == "Flower3")
  67. {
  68. ManaReso.SetText("H_Lab", "向日葵");
  69. }
  70. else if (spriteName == "Flower4")
  71. {
  72. ManaReso.SetText("H_Lab", "马蹄莲");
  73. }
  74. else if (spriteName == "Flower5")
  75. {
  76. ManaReso.SetText("H_Lab", "康乃馨");
  77. }
  78. else if (spriteName == "Flower6")
  79. {
  80. ManaReso.SetText("H_Lab", "郁金香");
  81. }
  82. else if (spriteName == "Flower7")
  83. {
  84. ManaReso.SetText("H_Lab", "三色堇");
  85. }
  86. else if (spriteName == "Flower8")
  87. {
  88. ManaReso.SetText("H_Lab", "铃兰");
  89. }
  90. else if (spriteName == "Flower9")
  91. {
  92. ManaReso.SetText("H_Lab", "三叶草");
  93. }
  94. else if (spriteName == "Flower10")
  95. {
  96. ManaReso.SetText("H_Lab", "粉色小花");
  97. }
  98. else if (spriteName == "Flower11")
  99. {
  100. ManaReso.SetText("H_Lab", "紫色小花");
  101. }
  102. else
  103. {
  104. throw new Exception();
  105. }
  106. }
  107. public static void SaveFlower()
  108. {
  109. ManaReso.Get("H_FlowerCard").Backward(TweenType.Alpha);
  110. ManaReso.SaveToPool(SelFlower.gameObject);
  111. SelFlower.PosTra.SetCollider(true);
  112. PlantFlowerList.Remove(SelFlower);
  113. bool plantSta = false;
  114. for (int i = 0; i < PlantFlowerList.Count; i++)
  115. {
  116. if (PlantFlowerList[i].Sprite == SelFlower.Sprite)
  117. {
  118. plantSta = true;
  119. break;
  120. }
  121. }
  122. if (!plantSta)
  123. {
  124. FlowerItemDic[SelFlower.ObjType].SetActive(false);
  125. }
  126. }
  127. public static void SaveAllFlower()
  128. {
  129. for (int i = 0; i < PlantFlowerList.Count; i++)
  130. {
  131. ManaReso.SaveToPool(PlantFlowerList[i]);
  132. PlantFlowerList[i].PosTra.SetCollider(true);
  133. PlantFlowerList.RemoveAt(i);
  134. i--;
  135. }
  136. foreach (var kvp in FlowerItemDic)
  137. {
  138. kvp.Value.SetActive(false);
  139. }
  140. }
  141. public static void PlantFlower(ObjType objType)
  142. {
  143. bool haveSpace = false;
  144. for (int i = 0; i < FlowerTraList.Count; i++)
  145. {
  146. if (FlowerTraList[i].childCount == 0)
  147. {
  148. haveSpace = true;
  149. Flower flower = ManaReso.GetFlower(true, FlowerTraList[i], objType);
  150. flower.PosTra = FlowerTraList[i];
  151. PlantFlowerList.Add(flower);
  152. FlowerTraList[i].SetCollider(false);
  153. FlowerItemDic[objType].SetActive(true);
  154. break;
  155. }
  156. }
  157. if (!haveSpace)
  158. {
  159. ManaMessage.Show("没有空地了", 1);
  160. }
  161. }
  162. public static void PlantFlower(Transform postTra, ObjType objType)
  163. {
  164. Flower flower = ManaReso.GetFlower(true, postTra, objType);
  165. flower.PosTra = postTra;
  166. PlantFlowerList.Add(flower);
  167. postTra.SetCollider(false);
  168. FlowerItemDic[objType ].SetActive(true);
  169. }
  170. }