Flower.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. ManaText.Add(Text, new LanStr("Object", "FlowerItemG_Lab"));
  28. UIPartical.Begin();
  29. }
  30. else
  31. {
  32. Text.text = "";
  33. }
  34. }
  35. }
  36. public bool Unlock
  37. {
  38. get { return _Unlock; }
  39. set
  40. {
  41. _Unlock = value;
  42. if (_Unlock)
  43. {
  44. Text.text = "";
  45. Image.material = null;
  46. Button.interactable = true;
  47. if (Special)
  48. {
  49. if (ManaGarden.MyFlowerSpec == 0)
  50. {
  51. ManaReso.Get("G_Regular").TweenForVec();
  52. ManaReso.SetActive("G_Special", true);
  53. }
  54. ManaGarden.MyFlowerSpec++;
  55. }
  56. else
  57. {
  58. ManaGarden.MyFlowerRegu++;
  59. }
  60. ManaData.SkillPlus += 0.1f;
  61. ManaDebug.Log(string.Format("获得<color=red>{0}</color> 收入<color=red>+10%</color>", Name));
  62. }
  63. }
  64. }
  65. public string Name
  66. {
  67. get
  68. {
  69. return Language.GetStr("FlowerName", _Name);
  70. }
  71. set { _Name = value; }
  72. }
  73. public bool _Plant;
  74. public bool _Unlock;
  75. public string _Name;
  76. public int ID;
  77. public bool Special;
  78. public string Description;
  79. public Slot Slot;
  80. public Text Text;
  81. public Sprite Sprite;
  82. public Image Image;
  83. public Button Button;
  84. public UIPartical UIPartical;
  85. public Transform ItemTra;
  86. #endregion
  87. public FlowerInfo(XmlAttributeCollection attribute)
  88. {
  89. ItemTra = ManaReso.Get("FlowerItemG", Folder.UI, false, ManaReso.Get("G_RegularGrid"), false);
  90. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  91. Auxiliary.CompileDic(ItemTra, dic);
  92. Text = dic["Lab"].GetComponent<Text>();
  93. Image = dic["Icon"].GetComponent<Image>();
  94. Button = dic["FlowerItemG"].GetComponent<Button>();
  95. UIPartical = dic["UIParticle System"].GetComponent<UIPartical>();
  96. ID = int.Parse(attribute[0].Value);
  97. Sprite = ManaReso.Load<Sprite>(attribute[3].Value, Folder.Garden);
  98. _Name = "Flower" + ID;
  99. Description = attribute[2].Value;
  100. Image.sprite = Sprite;
  101. Vector2 newSize = Sprite.rect.size;
  102. newSize.x *= 0.2f;
  103. newSize.y *= 0.2f;
  104. Image.rectTransform.sizeDelta = newSize;
  105. if (Initializer.Tutorial)
  106. {
  107. Button.onClick.AddListener
  108. (
  109. () =>
  110. {
  111. TutorialClick();
  112. }
  113. );
  114. }
  115. else
  116. {
  117. Button.onClick.AddListener
  118. (
  119. () =>
  120. {
  121. RegularClick();
  122. }
  123. );
  124. }
  125. }
  126. private void TutorialClick()
  127. {
  128. ManaGarden.PlantFlower(this);
  129. Tutorial.HightDisable(ItemTra, false);
  130. Tutorial.HightScreen(ManaReso.Get("G_CloseArrow"), ManaReso.Get("G_Close"));
  131. }
  132. private void RegularClick()
  133. {
  134. ManaGarden.PlantFlower(this);
  135. }
  136. }
  137. public class Flower : ObjRoot, IPointerClickHandler
  138. {
  139. #region 变量
  140. #region MiniGame
  141. public int Phase
  142. {
  143. get { return _Phase; }
  144. set
  145. {
  146. _Phase = value;
  147. if (Phase == 1)
  148. {
  149. Phase = 0;
  150. OperateBk.SetActive(false);
  151. OperateIcon.SetActive(false);
  152. OperateOutline.SetActive(false);
  153. ManaReso.GetHudText("得分+15", Color.white, 25, ChildDic["ScorePosTra"], ManaReso.Get("D_Status"), true);
  154. ManaMiniGame.Score += 15;
  155. }
  156. }
  157. }
  158. private int _Phase;
  159. public OpType OpType;
  160. public SpriteRenderer FlowerIcon;
  161. public SpriteRenderer OperateBk;
  162. public SpriteRenderer OperateIcon;
  163. public SpriteRenderer OperateOutline;
  164. #endregion
  165. public bool Award
  166. {
  167. get { return _Award; }
  168. set
  169. {
  170. _Award = value;
  171. if (_Award)
  172. {
  173. ShowAward();
  174. }
  175. else
  176. {
  177. GetAward();
  178. }
  179. }
  180. }
  181. public FlowerInfo FlowerInfo
  182. {
  183. get { return _FlowerInfo; }
  184. set
  185. {
  186. _FlowerInfo = value;
  187. FlowerIcon.sprite = FlowerInfo.Sprite;
  188. }
  189. }
  190. public bool _Award;
  191. private FlowerInfo _FlowerInfo;
  192. public int ID;
  193. public Slot Slot;
  194. public Vector3 LocalPos;
  195. public Animator ParticleAC;
  196. public Transform GoldBk;
  197. public Transform GoldIcon;
  198. private Dictionary<string, Transform> ChildDic;
  199. #endregion
  200. public void Regist()
  201. {
  202. ChildDic = new Dictionary<string, Transform>();
  203. Auxiliary.CompileDic(transform, ChildDic);
  204. GoldBk = ChildDic["GoldBk"];
  205. GoldIcon = ChildDic["GoldIcon"];
  206. ParticleAC = ChildDic["FlashLight"].GetComponent<Animator>();
  207. FlowerIcon = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
  208. OperateBk = ChildDic["OperateBk"].GetComponent<SpriteRenderer>();
  209. OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
  210. OperateOutline = ChildDic["OperateOutline"].GetComponent<SpriteRenderer>();
  211. Tween tween = FlowerIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, false, true, true, Curve.EaseOutQuad);
  212. tween.OnForwardFinish += () =>
  213. {
  214. FlowerIcon.TweenBacSr();
  215. };
  216. tween = OperateIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, false, true, true, Curve.EaseOutQuad);
  217. tween.OnForwardFinish += () =>
  218. {
  219. OperateIcon.TweenBacSr();
  220. };
  221. tween = OperateBk.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, false, true, true, Curve.EaseOutQuad);
  222. tween.OnForwardFinish += () =>
  223. {
  224. OperateBk.TweenBacSr();
  225. };
  226. OperateBk.CreateTweenScale(OperateBk.transform.localScale + new Vector3(0.1f, 0.1f, 0.1f), 0.25f, false, true, Curve.EaseOutQuad);
  227. }
  228. #region MiniGame
  229. public void GameOver()
  230. {
  231. ChildDic["MiniGame"].SetActive(false);
  232. OperateBk.TweenBacScale();
  233. }
  234. public void GameBegin()
  235. {
  236. ChildDic["MiniGame"].SetActive(true);
  237. OperateIcon.SetActive(false);
  238. }
  239. public void SetFirstOp()
  240. {
  241. OperateBk.TweenForScale();
  242. OperateIcon.SetAlpha(1);
  243. OperateOutline.SetAlpha(1);
  244. OperateIcon.SetActive(true);
  245. OperateOutline.SetActive(true);
  246. }
  247. public void SetSecondOp()
  248. {
  249. OperateIcon.SetAlpha(1);
  250. OperateOutline.SetAlpha(1);
  251. OperateIcon.SetActive(true);
  252. OperateOutline.SetActive(false);
  253. }
  254. public void SetThirdOp()
  255. {
  256. OperateIcon.SetAlpha(0.5f);
  257. OperateOutline.SetAlpha(0.5f);
  258. OperateIcon.SetActive(true);
  259. OperateOutline.SetActive(false);
  260. }
  261. public void CreateOp(int sequence)
  262. {
  263. float random = Random.Range(0f, 1f);
  264. OperateBk.SetActive(true);
  265. if (random <= 0.3333333f)
  266. {
  267. OpType = OpType.Rip;
  268. OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.UI);
  269. }
  270. else if (random <= 0.6666666f)
  271. {
  272. OpType = OpType.Water;
  273. OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.UI);
  274. }
  275. else
  276. {
  277. OpType = OpType.Fertilize;
  278. OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.UI);
  279. }
  280. if (sequence == 0)
  281. {
  282. SetFirstOp();
  283. }
  284. else if (sequence == 1)
  285. {
  286. SetSecondOp();
  287. }
  288. else
  289. {
  290. SetThirdOp();
  291. }
  292. }
  293. public bool Operate(OpType opType)
  294. {
  295. if (opType != OpType) //错误的操作
  296. {
  297. OperateBk.TweenForSr();
  298. FlowerIcon.TweenForSr();
  299. OperateIcon.TweenForSr();
  300. OperateIcon.Shake(1, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
  301. return false;
  302. }
  303. else //操作正确 植物升级
  304. {
  305. Phase++;
  306. PlayParticle();
  307. OperateBk.TweenBacScale();
  308. return true;
  309. }
  310. }
  311. #endregion
  312. public void PlayAnim(ObjType obj)
  313. {
  314. Animator animator = ManaReso.GetAnim(FlowerIcon.bounds, obj, FlowerIcon.transform.position, transform).GetComponentInChildren<Animator>();
  315. animator.SetTrigger("Play");
  316. }
  317. public void PlayParticle()
  318. {
  319. ParticleAC.SetTrigger("Play");
  320. }
  321. public void GetAward()
  322. {
  323. PlayParticle();
  324. ManaGarden.Award = true;
  325. int coin = Mathf.CeilToInt(ManaData.CoinPerson*Random.Range(0.05f, 0.08f)*ManaData.SkillPlus);
  326. ManaData.Coin += coin;
  327. ManaData.FlowerCoin += coin;
  328. ManaReso.GetHudText("+" + coin, Color.white, 25, ChildDic["GoldPosTra"], ManaReso.Get("A_HudParent"), true);
  329. GoldBk.SetActive(false);
  330. }
  331. public void ShowAward()
  332. {
  333. GoldBk.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, false, true, true, Curve.EaseOutQuad);
  334. GoldIcon.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, false, true, true, Curve.EaseOutQuad);
  335. GoldBk.SetY(transform.position.y + 2.5f);
  336. GoldBk.TweenForSr();
  337. GoldIcon.TweenForSr();
  338. GoldBk.Move2D
  339. (
  340. GoldBk.transform.localPosition + new Vector3(0, 0.5f, 0),
  341. 1f,
  342. true,
  343. Curve.EaseOutQuad
  344. );
  345. }
  346. public void OnPointerClick(PointerEventData eventData)
  347. {
  348. if (eventData.rawPointerPress.transform == transform)
  349. {
  350. ManaReso.Get("G_Flower").TweenForCG();
  351. ManaGarden.ShowRetrieveCard(FlowerInfo);
  352. }
  353. else if (eventData.rawPointerPress.transform == GoldBk)
  354. {
  355. Award = false;
  356. }
  357. }
  358. }