Flower.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Serialization;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using Random = UnityEngine.Random;
  10. public enum OpType
  11. {
  12. Rip,
  13. Water,
  14. Fertilize,
  15. }
  16. public class FlowerInfo
  17. {
  18. #region 变量
  19. public bool Plant
  20. {
  21. get { return _Plant; }
  22. set
  23. {
  24. _Plant = value;
  25. if (_Plant)
  26. {
  27. Text.text = "已放置";
  28. }
  29. else
  30. {
  31. Text.text = "";
  32. }
  33. }
  34. }
  35. public bool Unlock
  36. {
  37. get { return _Unlock; }
  38. set
  39. {
  40. _Unlock = value;
  41. if (_Unlock)
  42. {
  43. Text.text = "";
  44. Image.material = null;
  45. Button.interactable = true;
  46. if (Special)
  47. {
  48. if (ManaGarden.MyFlowerSpec == 0)
  49. {
  50. ManaReso.Get("G_Regular").TweenForVec();
  51. ManaReso.SetActive("G_Special", true);
  52. }
  53. ManaGarden.MyFlowerSpec++;
  54. }
  55. else
  56. {
  57. ManaGarden.MyFlowerRegu++;
  58. }
  59. ManaData.SkillPlus += 0.1f;
  60. ManaDebug.Log(string.Format("获得<color=red>{0}</color> 收入<color=red>+10%</color>", Name));
  61. }
  62. }
  63. }
  64. public bool _Plant;
  65. public bool _Unlock;
  66. public int Id;
  67. public bool Special;
  68. public string Name;
  69. public string Description;
  70. public Slot Slot;
  71. public Text Text;
  72. public Sprite Sprite;
  73. public Image Image;
  74. public Button Button;
  75. #endregion
  76. public FlowerInfo(XmlAttributeCollection attributes)
  77. {
  78. Transform tra = ManaReso.Get("FlowerItemG", Folder.PrefabUI, false, ManaReso.Get("G_RegularGrid"), false);
  79. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  80. Auxiliary.CompileDic(tra, dic);
  81. Text = dic["Lab"].GetComponent<Text>();
  82. Image = dic["Icon"].GetComponent<Image>();
  83. Button = dic["FlowerItemG"].GetComponent<Button>();
  84. Id = int.Parse(attributes[0].Value);
  85. Sprite = ManaReso.Load<Sprite>(attributes[3].Value, Folder.Garden);
  86. Name = Language.GetStr("FlowerName", "Flower" + Id);
  87. Description = attributes[2].Value;
  88. Image.sprite = Sprite;
  89. Vector2 newSize = Sprite.rect.size;
  90. newSize.x *= 0.2f;
  91. newSize.y *= 0.2f;
  92. Image.rectTransform.sizeDelta = newSize;
  93. Button.onClick.AddListener
  94. (
  95. () =>
  96. {
  97. ManaGarden.PlantFlower(this);
  98. }
  99. );
  100. }
  101. }
  102. public class Flower : ObjRoot, IPointerClickHandler
  103. {
  104. #region 变量
  105. #region MiniGame
  106. public int Phase
  107. {
  108. get { return _Phase; }
  109. set
  110. {
  111. _Phase = value;
  112. if (Phase == 1)
  113. {
  114. Phase = 0;
  115. OperateIcon.SetActive(false);
  116. ManaReso.GetHudText("得分+15", Color.red, 18, ChildDic["ScoreTra"], ManaReso.Get("D_Status"), true);
  117. ManaMiniGame.Score += 15;
  118. }
  119. }
  120. }
  121. private int _Phase;
  122. private OpType OpType;
  123. private SpriteRenderer FlowerSr;
  124. private SpriteRenderer OperateIcon;
  125. #endregion
  126. public FlowerInfo FlowerInfo
  127. {
  128. get { return _FlowerInfo; }
  129. set
  130. {
  131. _FlowerInfo = value;
  132. FlowerSr.sprite = FlowerInfo.Sprite;
  133. }
  134. }
  135. private FlowerInfo _FlowerInfo;
  136. public int Id;
  137. public Slot Slot;
  138. public Vector3 LocalPos;
  139. private Dictionary<string, Transform> ChildDic;
  140. #endregion
  141. private void Awake()
  142. {
  143. ChildDic = new Dictionary<string, Transform>();
  144. Auxiliary.CompileDic(transform, ChildDic);
  145. FlowerSr = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
  146. OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
  147. }
  148. #region MiniGame
  149. public void GameOver()
  150. {
  151. ChildDic["MiniGame"].SetActive(false);
  152. }
  153. public void GameBegin()
  154. {
  155. ChildDic["MiniGame"].SetActive(true);
  156. OperateIcon.SetActive(false);
  157. }
  158. public void SetFirstOp()
  159. {
  160. OperateIcon.SetAlpha(1);
  161. OperateIcon.material.shader = Shader.Find("DashGame/HighLight");
  162. OperateIcon.SetActive(true);
  163. }
  164. public void SetSecondOp()
  165. {
  166. OperateIcon.SetAlpha(1);
  167. OperateIcon.material.shader = Shader.Find("Sprites/Default");
  168. OperateIcon.SetActive(true);
  169. }
  170. public void SetThirdOp()
  171. {
  172. OperateIcon.SetAlpha(0.5f);
  173. OperateIcon.material.shader = Shader.Find("Sprites/Default");
  174. OperateIcon.SetActive(true);
  175. }
  176. public void CreateOp(int sequence)
  177. {
  178. float random = Random.Range(0f, 1f);
  179. if (random <= 0.3333333f)
  180. {
  181. OpType = OpType.Rip;
  182. OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.SpriteUI);
  183. }
  184. else if (random <= 0.6666666f)
  185. {
  186. OpType = OpType.Water;
  187. OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.SpriteUI);
  188. }
  189. else
  190. {
  191. OpType = OpType.Fertilize;
  192. OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.SpriteUI);
  193. }
  194. if (sequence == 0)
  195. {
  196. SetFirstOp();
  197. }
  198. else if (sequence == 1)
  199. {
  200. SetSecondOp();
  201. }
  202. else
  203. {
  204. SetThirdOp();
  205. }
  206. }
  207. public bool Operate(OpType opType)
  208. {
  209. if (opType != OpType) //错误的操作
  210. {
  211. return false;
  212. }
  213. else //操作正确 植物升级
  214. {
  215. Phase++;
  216. OperateIcon.SetActive(false);
  217. return true;
  218. }
  219. }
  220. #endregion
  221. public void OnPointerClick(PointerEventData eventData)
  222. {
  223. ManaReso.Get("G_Flower").TweenForCG();
  224. ManaGarden.ShowRetrieveCard(FlowerInfo);
  225. }
  226. }