Flower.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. Button.onClick.AddListener
  106. (
  107. () =>
  108. {
  109. if (ManaTutorial.TutorialA)
  110. {
  111. TutorialClick();
  112. }
  113. else
  114. {
  115. RegularClick();
  116. }
  117. }
  118. );
  119. }
  120. private void TutorialClick()
  121. {
  122. ManaGarden.PlantFlower(this);
  123. Tutorial.HightDisable(0, false);
  124. Tutorial.HightScreen(ManaReso.Get("G_CloseArrow"), ManaReso.Get("G_Close"));
  125. }
  126. private void RegularClick()
  127. {
  128. ManaGarden.PlantFlower(this);
  129. }
  130. }
  131. public class Flower : ObjRoot, IPointerClickHandler
  132. {
  133. #region 变量
  134. #region MiniGame
  135. public int Phase
  136. {
  137. get { return _Phase; }
  138. set
  139. {
  140. _Phase = value;
  141. if (Phase == 1)
  142. {
  143. Phase = 0;
  144. OperateBk.SetActive(false);
  145. OperateIcon.SetActive(false);
  146. OperateOutline.SetActive(false);
  147. ManaReso.GetHudText("得分+15", Color.white, 25, ChildDic["ScorePosTra"], ManaReso.Get("D_Status"), true);
  148. ManaMiniGame.Score += 15;
  149. }
  150. }
  151. }
  152. private int _Phase;
  153. public OpType OpType;
  154. public SpriteRenderer FlowerIcon;
  155. public SpriteRenderer OperateBk;
  156. public SpriteRenderer OperateIcon;
  157. public SpriteRenderer OperateOutline;
  158. #endregion
  159. public bool Award
  160. {
  161. get { return _Award; }
  162. set
  163. {
  164. _Award = value;
  165. if (_Award)
  166. {
  167. ShowAward();
  168. }
  169. else
  170. {
  171. GetAward();
  172. }
  173. }
  174. }
  175. public FlowerInfo FlowerInfo
  176. {
  177. get { return _FlowerInfo; }
  178. set
  179. {
  180. _FlowerInfo = value;
  181. FlowerIcon.sprite = FlowerInfo.Sprite;
  182. }
  183. }
  184. public bool _Award;
  185. private FlowerInfo _FlowerInfo;
  186. public int ID;
  187. public Slot Slot;
  188. public Vector3 LocalPos;
  189. public Animator ParticleAC;
  190. public Transform GoldBk;
  191. public Transform GoldIcon;
  192. private Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  193. #endregion
  194. public override void RegistImmed()
  195. {
  196. enabled = true;
  197. Auxiliary.CompileDic(transform, ChildDic);
  198. GoldBk = ChildDic["GoldBk"];
  199. GoldIcon = ChildDic["GoldIcon"];
  200. ParticleAC = ChildDic["FlashLight"].GetComponent<Animator>();
  201. FlowerIcon = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
  202. OperateBk = ChildDic["OperateBk"].GetComponent<SpriteRenderer>();
  203. OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
  204. OperateOutline = ChildDic["OperateOutline"].GetComponent<SpriteRenderer>();
  205. Tween tween = FlowerIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad);
  206. tween.OnForwardFinish += () =>
  207. {
  208. FlowerIcon.TweenBacSr();
  209. };
  210. tween = OperateIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad);
  211. tween.OnForwardFinish += () =>
  212. {
  213. OperateIcon.TweenBacSr();
  214. };
  215. tween = OperateBk.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad);
  216. tween.OnForwardFinish += () =>
  217. {
  218. OperateBk.TweenBacSr();
  219. };
  220. OperateBk.CreateTweenScale(OperateBk.transform.localScale + new Vector3(0.1f, 0.1f, 0.1f), 0.25f, false, true, Curve.EaseOutQuad);
  221. }
  222. #region MiniGame
  223. public void GameOver()
  224. {
  225. ChildDic["MiniGame"].SetActive(false);
  226. OperateBk.TweenBacScale();
  227. }
  228. public void GameBegin()
  229. {
  230. ChildDic["MiniGame"].SetActive(true);
  231. OperateIcon.SetActive(false);
  232. }
  233. public void SetFirstOp()
  234. {
  235. OperateBk.TweenForScale();
  236. OperateIcon.SetAlpha(1);
  237. OperateOutline.SetAlpha(1);
  238. OperateIcon.SetActive(true);
  239. OperateOutline.SetActive(true);
  240. }
  241. public void SetSecondOp()
  242. {
  243. OperateIcon.SetAlpha(1);
  244. OperateOutline.SetAlpha(1);
  245. OperateIcon.SetActive(true);
  246. OperateOutline.SetActive(false);
  247. }
  248. public void SetThirdOp()
  249. {
  250. OperateIcon.SetAlpha(0.5f);
  251. OperateOutline.SetAlpha(0.5f);
  252. OperateIcon.SetActive(true);
  253. OperateOutline.SetActive(false);
  254. }
  255. public void CreateOp(int sequence)
  256. {
  257. float random = Random.Range(0f, 1f);
  258. OperateBk.SetActive(true);
  259. if (random <= 0.3333333f)
  260. {
  261. OpType = OpType.Rip;
  262. OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.UI);
  263. }
  264. else if (random <= 0.6666666f)
  265. {
  266. OpType = OpType.Water;
  267. OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.UI);
  268. }
  269. else
  270. {
  271. OpType = OpType.Fertilize;
  272. OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.UI);
  273. }
  274. if (sequence == 0)
  275. {
  276. SetFirstOp();
  277. }
  278. else if (sequence == 1)
  279. {
  280. SetSecondOp();
  281. }
  282. else
  283. {
  284. SetThirdOp();
  285. }
  286. }
  287. public void CreateOp(int sequence, OpType opType)
  288. {
  289. OpType = opType;
  290. OperateBk.SetActive(true);
  291. if (opType == OpType.Rip)
  292. {
  293. OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.UI);
  294. }
  295. else if (opType == OpType.Water)
  296. {
  297. OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.UI);
  298. }
  299. else if (opType == OpType.Fertilize)
  300. {
  301. OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.UI);
  302. }
  303. if (sequence == 0)
  304. {
  305. SetFirstOp();
  306. }
  307. else if (sequence == 1)
  308. {
  309. SetSecondOp();
  310. }
  311. else
  312. {
  313. SetThirdOp();
  314. }
  315. }
  316. public bool Operate(OpType opType)
  317. {
  318. if (opType != OpType) //错误的操作
  319. {
  320. OperateBk.TweenForSr();
  321. FlowerIcon.TweenForSr();
  322. OperateIcon.TweenForSr();
  323. OperateIcon.Shake(1, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
  324. return false;
  325. }
  326. else //操作正确 植物升级
  327. {
  328. Phase++;
  329. PlayParticle();
  330. OperateBk.TweenBacScale();
  331. return true;
  332. }
  333. }
  334. #endregion
  335. public void PlayAnim(ObjType obj)
  336. {
  337. Animator animator = ManaReso.GetAnim(FlowerIcon.bounds, obj, FlowerIcon.transform.position, transform).GetComponentInChildren<Animator>();
  338. animator.SetTrigger("Play");
  339. }
  340. public void PlayParticle()
  341. {
  342. ParticleAC.SetTrigger("Play");
  343. }
  344. public void GetAward()
  345. {
  346. PlayParticle();
  347. ManaGarden.Award = true;
  348. int coin = Mathf.CeilToInt(ManaData.CoinPerson*Random.Range(0.05f, 0.08f)*ManaData.SkillPlus);
  349. ManaData.Coin += coin;
  350. ManaData.FlowerCoin += coin;
  351. ManaReso.GetHudText("+" + coin, Color.white, 25, ChildDic["GoldPosTra"], ManaReso.Get("A_HudParent"), true);
  352. GoldBk.SetActive(false);
  353. }
  354. public void ShowAward()
  355. {
  356. GoldBk.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, true, true, Curve.EaseOutQuad);
  357. GoldIcon.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, true, true, Curve.EaseOutQuad);
  358. GoldBk.SetY(transform.position.y + 2.5f);
  359. GoldBk.TweenForSr();
  360. GoldIcon.TweenForSr();
  361. GoldBk.Move2D
  362. (
  363. GoldBk.transform.localPosition + new Vector3(0, 0.5f, 0),
  364. 1f,
  365. true,
  366. Curve.EaseOutQuad
  367. );
  368. }
  369. public void OnPointerClick(PointerEventData eventData)
  370. {
  371. if (eventData.rawPointerPress.transform == transform)
  372. {
  373. ManaReso.Get("G_Flower").TweenForCG();
  374. ManaGarden.ShowRetrieveCard(FlowerInfo);
  375. }
  376. else if (eventData.rawPointerPress.transform == GoldBk)
  377. {
  378. Award = false;
  379. }
  380. }
  381. }