Flower.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. public List<Transform> ElfList = new List<Transform>();
  193. private Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  194. #endregion
  195. public override void RegistImmed()
  196. {
  197. enabled = true;
  198. Auxiliary.CompileDic(transform, ChildDic);
  199. GoldBk = ChildDic["GoldBk"];
  200. GoldIcon = ChildDic["GoldIcon"];
  201. ParticleAC = ChildDic["FlashLight"].GetComponent<Animator>();
  202. FlowerIcon = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
  203. OperateBk = ChildDic["OperateBk"].GetComponent<SpriteRenderer>();
  204. OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
  205. OperateOutline = ChildDic["OperateOutline"].GetComponent<SpriteRenderer>();
  206. Tween tween = FlowerIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad);
  207. tween.OnForwardFinish += () =>
  208. {
  209. FlowerIcon.TweenBacSr();
  210. };
  211. tween = OperateIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad);
  212. tween.OnForwardFinish += () =>
  213. {
  214. OperateIcon.TweenBacSr();
  215. };
  216. tween = OperateBk.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad);
  217. tween.OnForwardFinish += () =>
  218. {
  219. OperateBk.TweenBacSr();
  220. };
  221. OperateBk.CreateTweenScale(OperateBk.transform.localScale + new Vector3(0.1f, 0.1f, 0.1f), 0.25f, false, true, Curve.EaseOutQuad);
  222. }
  223. #region MiniGame
  224. public void GameOver()
  225. {
  226. ChildDic["MiniGame"].SetActive(false);
  227. OperateBk.TweenBacScale();
  228. }
  229. public void GameBegin()
  230. {
  231. ChildDic["MiniGame"].SetActive(true);
  232. OperateIcon.SetActive(false);
  233. }
  234. public void SetFirstOp()
  235. {
  236. OperateBk.TweenForScale();
  237. OperateIcon.SetAlpha(1);
  238. OperateOutline.SetAlpha(1);
  239. OperateIcon.SetActive(true);
  240. OperateOutline.SetActive(true);
  241. }
  242. public void SetSecondOp()
  243. {
  244. OperateIcon.SetAlpha(1);
  245. OperateOutline.SetAlpha(1);
  246. OperateIcon.SetActive(true);
  247. OperateOutline.SetActive(false);
  248. }
  249. public void SetThirdOp()
  250. {
  251. OperateIcon.SetAlpha(0.5f);
  252. OperateOutline.SetAlpha(0.5f);
  253. OperateIcon.SetActive(true);
  254. OperateOutline.SetActive(false);
  255. }
  256. public void CreateOp(int sequence)
  257. {
  258. float random = Random.Range(0f, 1f);
  259. OperateBk.SetActive(true);
  260. if (random <= 0.3333333f)
  261. {
  262. OpType = OpType.Rip;
  263. OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.UI);
  264. }
  265. else if (random <= 0.6666666f)
  266. {
  267. OpType = OpType.Water;
  268. OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.UI);
  269. }
  270. else
  271. {
  272. OpType = OpType.Fertilize;
  273. OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.UI);
  274. }
  275. if (sequence == 0)
  276. {
  277. SetFirstOp();
  278. }
  279. else if (sequence == 1)
  280. {
  281. SetSecondOp();
  282. }
  283. else
  284. {
  285. SetThirdOp();
  286. }
  287. }
  288. public void CreateOp(int sequence, OpType opType)
  289. {
  290. OpType = opType;
  291. OperateBk.SetActive(true);
  292. if (opType == OpType.Rip)
  293. {
  294. OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.UI);
  295. }
  296. else if (opType == OpType.Water)
  297. {
  298. OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.UI);
  299. }
  300. else if (opType == OpType.Fertilize)
  301. {
  302. OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.UI);
  303. }
  304. if (sequence == 0)
  305. {
  306. SetFirstOp();
  307. }
  308. else if (sequence == 1)
  309. {
  310. SetSecondOp();
  311. }
  312. else
  313. {
  314. SetThirdOp();
  315. }
  316. }
  317. public bool Operate(OpType opType)
  318. {
  319. if (opType != OpType) //错误的操作
  320. {
  321. OperateBk.TweenForSr();
  322. FlowerIcon.TweenForSr();
  323. OperateIcon.TweenForSr();
  324. OperateIcon.Shake(1, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
  325. return false;
  326. }
  327. else //操作正确 植物升级
  328. {
  329. Phase++;
  330. PlayParticle();
  331. OperateBk.TweenBacScale();
  332. return true;
  333. }
  334. }
  335. #endregion
  336. public void PlayAnim(ObjType obj)
  337. {
  338. Transform elf = ManaReso.GetAnim(FlowerIcon.bounds, obj, FlowerIcon.transform.position, transform);
  339. Animator animator = elf.GetComponentInChildren<Animator>();
  340. ElfList.Add(elf);
  341. animator.SetTrigger("Play");
  342. }
  343. public void PlayParticle()
  344. {
  345. ParticleAC.SetTrigger("Play");
  346. }
  347. public void GetAward()
  348. {
  349. PlayParticle();
  350. ManaGarden.Award = true;
  351. int coin = Mathf.CeilToInt(ManaData.CoinPerson*Random.Range(0.05f, 0.08f)*ManaData.SkillPlus);
  352. ManaData.Coin += coin;
  353. ManaData.FlowerCoin += coin;
  354. ManaReso.GetHudText("+" + coin, Color.white, 25, ChildDic["GoldPosTra"], ManaReso.Get("A_HudParent"), true);
  355. GoldBk.SetActive(false);
  356. }
  357. public void ShowAward()
  358. {
  359. GoldBk.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, true, true, Curve.EaseOutQuad);
  360. GoldIcon.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, true, true, Curve.EaseOutQuad);
  361. GoldBk.SetY(transform.position.y + 2.5f);
  362. GoldBk.TweenForSr();
  363. GoldIcon.TweenForSr();
  364. GoldBk.Move2D
  365. (
  366. GoldBk.transform.localPosition + new Vector3(0, 0.5f, 0),
  367. 1f,
  368. true,
  369. Curve.EaseOutQuad
  370. );
  371. }
  372. public void OnPointerClick(PointerEventData eventData)
  373. {
  374. if (eventData.rawPointerPress.transform == transform)
  375. {
  376. ManaReso.Get("G_Flower").TweenForCG();
  377. ManaGarden.ShowRetrieveCard(FlowerInfo);
  378. }
  379. else if (eventData.rawPointerPress.transform == GoldBk)
  380. {
  381. Award = false;
  382. }
  383. }
  384. }