Flower.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. Null,
  14. Water,
  15. Fertilize,
  16. }
  17. public class FlowerInfo
  18. {
  19. #region 变量
  20. public bool Plant
  21. {
  22. get { return Plant_; }
  23. set
  24. {
  25. Plant_ = value;
  26. if (Plant_)
  27. {
  28. Text.SetActive(true);
  29. ManaLan.Add(Text, new LanStr("Object", "FlowerItemG_Lab"));
  30. UIPartical.Begin();
  31. }
  32. else
  33. {
  34. Text.SetActive(false);
  35. }
  36. }
  37. }
  38. public bool Unlock
  39. {
  40. get { return Unlock_; }
  41. set
  42. {
  43. Unlock_ = value;
  44. if (Unlock_)
  45. {
  46. Image.material = null;
  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. ManaCenter.SkillPlus += 0.1f;
  61. }
  62. }
  63. }
  64. public string ID
  65. {
  66. get
  67. {
  68. return "Flower" + ID_;
  69. }
  70. }
  71. public string Name
  72. {
  73. get
  74. {
  75. return Language.GetStr("FlowerName", ID);
  76. }
  77. }
  78. public string Description
  79. {
  80. get { return Language.GetStr("FlowerDesc", ID); }
  81. }
  82. public Sprite Icon
  83. {
  84. get { return ManaReso.LoadSprite(Icon_, Folder.Scene); }
  85. }
  86. public int ID_;
  87. public bool Plant_;
  88. public bool Unlock_;
  89. public string Icon_;
  90. public bool Special;
  91. public Slot Slot;
  92. public Text Text;
  93. public Image Image;
  94. public Button Button;
  95. public UIPartical UIPartical;
  96. public Transform FlowerItem;
  97. #endregion
  98. public FlowerInfo(XmlAttributeCollection attribute)
  99. {
  100. FlowerItem = ManaReso.Get("FlowerItem", Folder.UI, false, ManaReso.Get("G_RegularGrid"), false, ObjType.FlowerItem);
  101. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  102. Auxiliary.CompileDic(FlowerItem, dic);
  103. Text = dic["Lab"].GetComponent<Text>();
  104. Image = dic["Icon"].GetComponent<Image>();
  105. Button = dic["FlowerItem"].GetComponent<Button>();
  106. UIPartical = dic["UIParticle System"].GetComponent<UIPartical>();
  107. ID_ = int.Parse(attribute[0].Value);
  108. Icon_ = attribute[3].Value;
  109. Image.sprite = Icon;
  110. Image.Resize(0.2f, 0.2f);
  111. Button.onClick.AddListener
  112. (
  113. () =>
  114. {
  115. if (Unlock)
  116. {
  117. ManaGarden.PlantFlower(this);
  118. }
  119. else
  120. {
  121. Toast.Show(1.5f, Name + " " + Language.GetStr("Common", "Unlock"));
  122. }
  123. }
  124. );
  125. }
  126. }
  127. public class Flower : Regist, IPointerClickHandler
  128. {
  129. #region 变量
  130. #region MiniGame
  131. public OpType OpType
  132. {
  133. get { return OpType_; }
  134. set
  135. {
  136. OpType_ = value;
  137. if (OpType_ == OpType.Rip)
  138. {
  139. OperateIcon.sprite = RipSprite;
  140. }
  141. else if (OpType_ == OpType.Water)
  142. {
  143. OperateIcon.sprite = WaterSprite;
  144. }
  145. else if (OpType_ == OpType.Fertilize)
  146. {
  147. OperateIcon.sprite = FertilizeSprite;
  148. }
  149. }
  150. }
  151. public OpType OpType_;
  152. public SpriteRenderer FlowerIcon;
  153. public SpriteRenderer OperateBk;
  154. public SpriteRenderer OperateIcon;
  155. public SpriteRenderer OperateOutline;
  156. #endregion
  157. public bool Award
  158. {
  159. get { return Award_; }
  160. set
  161. {
  162. Award_ = value;
  163. if (Award_)
  164. {
  165. ShowAward();
  166. }
  167. else
  168. {
  169. GetAward();
  170. }
  171. }
  172. }
  173. public Sprite RipSprite
  174. {
  175. get
  176. {
  177. return ManaReso.LoadSprite("Rip", Folder.UI);
  178. }
  179. }
  180. public Sprite WaterSprite
  181. {
  182. get
  183. {
  184. return ManaReso.LoadSprite("Water", Folder.UI);
  185. }
  186. }
  187. public Sprite FertilizeSprite
  188. {
  189. get
  190. {
  191. return ManaReso.LoadSprite("Fertilize", Folder.UI);
  192. }
  193. }
  194. public FlowerInfo FlowerInfo
  195. {
  196. get { return FlowerInfo_; }
  197. set
  198. {
  199. FlowerInfo_ = value;
  200. ID = FlowerInfo.ID_;
  201. FlowerIcon.sprite = FlowerInfo.Icon;
  202. }
  203. }
  204. public bool Award_;
  205. private FlowerInfo FlowerInfo_;
  206. public int ID;
  207. public Slot Slot;
  208. public Animator ParticleAC;
  209. public Transform GoldBk;
  210. public Transform GoldIcon;
  211. public List<Transform> ElfList = new List<Transform>();
  212. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  213. public static string CoinFml;
  214. #endregion
  215. public override bool RegistImmed()
  216. {
  217. if (base.RegistImmed())
  218. {
  219. return true;
  220. }
  221. enabled = true;
  222. Auxiliary.CompileDic(transform, ChildDic);
  223. GoldBk = ChildDic["GoldBk"];
  224. GoldIcon = ChildDic["GoldIcon"];
  225. ParticleAC = ChildDic["FlashLight"].GetComponent<Animator>();
  226. FlowerIcon = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
  227. OperateBk = ChildDic["OperateBk"].GetComponent<SpriteRenderer>();
  228. OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
  229. OperateOutline = ChildDic["OperateOutline1"].GetComponent<SpriteRenderer>();
  230. GoldBk.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
  231. GoldIcon.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
  232. TweenRoot tween = FlowerIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad, false, true);
  233. tween.OnForwardFinish += () =>
  234. {
  235. FlowerIcon.TweenBacSr();
  236. };
  237. tween = OperateBk.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad, false, true);
  238. tween.OnForwardFinish += () =>
  239. {
  240. OperateBk.TweenBacSr();
  241. };
  242. tween = OperateBk.CreateTweenScale(OperateBk.transform.localScale + new Vector3(0.1f, 0.1f, 0.1f), 0.25f, false, true, Curve.EaseOutQuad);
  243. tween.OnBackwardFinish += () =>
  244. {
  245. if (OpType != OpType.Null)
  246. {
  247. OperateBk.SetActive(true);
  248. }
  249. };
  250. return false;
  251. }
  252. #region MiniGame
  253. public void GameOver()
  254. {
  255. OpType = OpType.Null;
  256. ChildDic["MiniGame"].SetActive(false);
  257. OperateBk.TweenBacScale();
  258. }
  259. public void GameBegin()
  260. {
  261. ChildDic["MiniGame"].SetActive(true);
  262. OperateBk.SetActive(false);
  263. }
  264. public void SetFirstOp()
  265. {
  266. OperateBk.TweenForScale();
  267. OperateIcon.SetAlpha(1);
  268. OperateOutline.SetAlpha(1);
  269. OperateIcon.SetActive(true);
  270. OperateOutline.SetActive(true);
  271. }
  272. public void SetThirdOp()
  273. {
  274. OperateIcon.SetAlpha(0.5f);
  275. OperateOutline.SetAlpha(0.5f);
  276. OperateIcon.SetActive(true);
  277. OperateOutline.SetActive(false);
  278. }
  279. public void SetSecondOp()
  280. {
  281. OperateIcon.SetAlpha(1);
  282. OperateOutline.SetAlpha(1);
  283. OperateIcon.SetActive(true);
  284. OperateOutline.SetActive(false);
  285. }
  286. public void CreateOp(int sequence)
  287. {
  288. float random = Random.Range(0f, 1f);
  289. OperateBk.SetActive(true);
  290. if (random <= 0.3333333f)
  291. {
  292. OpType = OpType.Rip;
  293. }
  294. else if (random <= 0.6666666f)
  295. {
  296. OpType = OpType.Water;
  297. }
  298. else
  299. {
  300. OpType = OpType.Fertilize;
  301. }
  302. if (sequence == 0)
  303. {
  304. SetFirstOp();
  305. }
  306. else if (sequence == 1)
  307. {
  308. SetSecondOp();
  309. }
  310. else
  311. {
  312. SetThirdOp();
  313. }
  314. }
  315. public void CreateOp(int sequence, OpType opType)
  316. {
  317. OpType = opType;
  318. OperateBk.SetActive(true);
  319. if (sequence == 0)
  320. {
  321. SetFirstOp();
  322. }
  323. else if (sequence == 1)
  324. {
  325. SetSecondOp();
  326. }
  327. else
  328. {
  329. SetThirdOp();
  330. }
  331. }
  332. public bool Operate(OpType opType)
  333. {
  334. if (opType == OpType.Rip)
  335. {
  336. ManaReso.Get("D_Rip2").TweenForScale();
  337. }
  338. else if (opType == OpType.Water)
  339. {
  340. ManaReso.Get("D_Water2").TweenForScale();
  341. }
  342. else if (opType == OpType.Fertilize)
  343. {
  344. ManaReso.Get("D_Fertilize2").TweenForScale();
  345. }
  346. if (opType != OpType)
  347. {
  348. OperateBk.TweenForSr();
  349. FlowerIcon.TweenForSr();
  350. OperateIcon.Shake(0.5f, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
  351. ManaAudio.PlayClip(Clip.ErrorClip);
  352. return false;
  353. }
  354. else
  355. {
  356. ManaReso.GetHudText("+15", Color.white, 90, ChildDic["ScorePosTra"], ManaReso.Get("D_MiniGame"), true);
  357. ManaMiniGame.Score += 15;
  358. PlayParticle();
  359. OpType = OpType.Null;
  360. OperateBk.TweenBacScale();
  361. OperateBk.SetActive(false);
  362. OperateIcon.SetActive(false);
  363. OperateOutline.SetActive(false);
  364. ManaAudio.PlayClip(Clip.BtnClip);
  365. return true;
  366. }
  367. }
  368. #endregion
  369. public void GetElf(ObjType obj, float xMin = -0.75f, float xMax = 0.75f, float yMin = 0, float yMax = 0.75f)
  370. {
  371. ElfList.Add(ManaReso.GetElf(this, new Vector4(xMin, xMax, yMin, yMax), obj));
  372. }
  373. public void Retrieve()
  374. {
  375. ChildDic["Flash"].SetActive(false);
  376. ChildDic["Particle System"].SetActive(false);
  377. ManaReso.Save(this);
  378. for (int i = 0; i < ElfList.Count; i++)
  379. {
  380. ManaReso.Save(ElfList[i]);
  381. }
  382. ElfList = new List<Transform>();
  383. Award_ = false;
  384. ResetAward();
  385. }
  386. public void PlayParticle()
  387. {
  388. ParticleAC.SetTrigger("Play");
  389. }
  390. public void GetAward()
  391. {
  392. ManaAudio.PlayClip(Clip.CurrentClip);
  393. PlayParticle();
  394. int coin;
  395. if (ManaVisit.InVisit)
  396. {
  397. int awardMin = Mathf.CeilToInt((float) Auxiliary.FmlParse(ManaVisit.AwardMinFml, "l", ManaCenter.Level.ToString()));
  398. int awardMax = Mathf.CeilToInt((float) Auxiliary.FmlParse(ManaVisit.AwardMaxFml, "l", ManaCenter.Level.ToString()));
  399. coin = Mathf.CeilToInt(Mathf.Lerp(awardMin, awardMax, Random.Range(0f, 1f)));
  400. ManaCenter.Coin += coin;
  401. }
  402. else
  403. {
  404. coin = Mathf.CeilToInt((float)Auxiliary.FmlParse(CoinFml, "l", Mathf.Clamp(ManaCenter.Level, 1, Mathf.Infinity).ToString()));
  405. ManaCenter.Coin += coin;
  406. ManaCenter.FlowerCoin++;
  407. }
  408. ManaReso.GetHudText("<(金币)>+" + coin, Color.white, 90, ChildDic["GoldPosTra"], ManaReso.Get("A_HudParent"), true);
  409. ResetAward();
  410. }
  411. public void ResetAward()
  412. {
  413. GoldBk.SetActive(false);
  414. GoldBk.GetTweenSr().Pause();
  415. GoldIcon.GetTweenSr().Pause();
  416. GoldBk.GetTweenSr().InOrigin = true;
  417. GoldIcon.GetTweenSr().InOrigin = true;
  418. }
  419. public void ShowAward()
  420. {
  421. GoldBk.SetY(transform.position.y + 2.5f);
  422. GoldBk.TweenReForSr();
  423. GoldIcon.TweenReForSr();
  424. GoldBk.MoveOffset2D
  425. (
  426. new Vector3(0, 0.5f, 0),
  427. 1f,
  428. true,
  429. Curve.EaseOutQuad
  430. );
  431. }
  432. public void OnPointerClick(PointerEventData eventData)
  433. {
  434. if (eventData.rawPointerPress.transform == transform)
  435. {
  436. if (ManaVisit.InVisit)
  437. {
  438. return;
  439. }
  440. ManaReso.Get("G_Flower").TweenForCG();
  441. ManaGarden.ShowFlowerCard(FlowerInfo);
  442. }
  443. else if (eventData.rawPointerPress.transform == GoldBk)
  444. {
  445. Award = false;
  446. }
  447. }
  448. }