Flower.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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.UI, 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 bool Award
  127. {
  128. get { return _Award; }
  129. set
  130. {
  131. _Award = value;
  132. if (_Award)
  133. {
  134. ShowAward();
  135. }
  136. else
  137. {
  138. GetAward();
  139. }
  140. }
  141. }
  142. public FlowerInfo FlowerInfo
  143. {
  144. get { return _FlowerInfo; }
  145. set
  146. {
  147. _FlowerInfo = value;
  148. FlowerSr.sprite = FlowerInfo.Sprite;
  149. }
  150. }
  151. public bool _Award;
  152. private FlowerInfo _FlowerInfo;
  153. public int Id;
  154. public Slot Slot;
  155. public Vector3 LocalPos;
  156. public Transform GoldBk;
  157. public Transform GoldIcon;
  158. private Dictionary<string, Transform> ChildDic;
  159. #endregion
  160. private void Awake()
  161. {
  162. ChildDic = new Dictionary<string, Transform>();
  163. Auxiliary.CompileDic(transform, ChildDic);
  164. GoldBk = ChildDic["GoldBk"];
  165. FlowerSr = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
  166. GoldIcon = ChildDic["GoldIcon"];
  167. OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
  168. }
  169. #region MiniGame
  170. public void GameOver()
  171. {
  172. ChildDic["MiniGame"].SetActive(false);
  173. }
  174. public void GameBegin()
  175. {
  176. ChildDic["MiniGame"].SetActive(true);
  177. OperateIcon.SetActive(false);
  178. }
  179. public void SetFirstOp()
  180. {
  181. OperateIcon.SetAlpha(1);
  182. OperateIcon.material.shader = Shader.Find("DashGame/HighLight");
  183. OperateIcon.SetActive(true);
  184. }
  185. public void SetSecondOp()
  186. {
  187. OperateIcon.SetAlpha(1);
  188. OperateIcon.material.shader = Shader.Find("Sprites/Default");
  189. OperateIcon.SetActive(true);
  190. }
  191. public void SetThirdOp()
  192. {
  193. OperateIcon.SetAlpha(0.5f);
  194. OperateIcon.material.shader = Shader.Find("Sprites/Default");
  195. OperateIcon.SetActive(true);
  196. }
  197. public void CreateOp(int sequence)
  198. {
  199. float random = Random.Range(0f, 1f);
  200. if (random <= 0.3333333f)
  201. {
  202. OpType = OpType.Rip;
  203. OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.UI);
  204. }
  205. else if (random <= 0.6666666f)
  206. {
  207. OpType = OpType.Water;
  208. OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.UI);
  209. }
  210. else
  211. {
  212. OpType = OpType.Fertilize;
  213. OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.UI);
  214. }
  215. if (sequence == 0)
  216. {
  217. SetFirstOp();
  218. }
  219. else if (sequence == 1)
  220. {
  221. SetSecondOp();
  222. }
  223. else
  224. {
  225. SetThirdOp();
  226. }
  227. }
  228. public bool Operate(OpType opType)
  229. {
  230. if (opType != OpType) //错误的操作
  231. {
  232. return false;
  233. }
  234. else //操作正确 植物升级
  235. {
  236. Phase++;
  237. OperateIcon.SetActive(false);
  238. return true;
  239. }
  240. }
  241. #endregion
  242. public void GetAward()
  243. {
  244. ManaGarden.Award = true;
  245. int coin = Mathf.CeilToInt(ManaData.CoinPerson*Random.Range(0.05f, 0.08f)*ManaData.SkillPlus);
  246. ManaData.Coin += coin;
  247. ManaReso.GetHudText("+" + coin, Color.red, 18, ChildDic["GoldTra"], ManaReso.Get("A_HudParent"), true);
  248. GoldBk.SetActive(false);
  249. }
  250. public void ShowAward()
  251. {
  252. GoldBk.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, true, true, Curve.EaseOutQuad);
  253. GoldIcon.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, true, true, Curve.EaseOutQuad);
  254. GoldBk.SetY(transform.position.y + 2.5f);
  255. GoldBk.TweenForSr();
  256. GoldIcon.TweenForSr();
  257. GoldBk.MoveVec
  258. (
  259. GoldBk.transform.position + new Vector3(0, 0.5f, 0),
  260. 1f,
  261. Curve.EaseOutQuad
  262. );
  263. }
  264. public void OnPointerClick(PointerEventData eventData)
  265. {
  266. if (eventData.rawPointerPress.transform == transform)
  267. {
  268. ManaReso.Get("G_Flower").TweenForCG();
  269. ManaGarden.ShowRetrieveCard(FlowerInfo);
  270. }
  271. else if (eventData.rawPointerPress.transform == GoldBk)
  272. {
  273. Award = false;
  274. }
  275. }
  276. }