Flower.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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.Atlas2); }
  85. }
  86. public int ID_;
  87. public bool Plant_;
  88. public bool Unlock_;
  89. public string Icon_;
  90. public bool Special;
  91. public int UnlockAmt;
  92. public Current UnlockCur;
  93. public Slot Slot;
  94. public Text Text;
  95. public Image Image;
  96. public Button Button;
  97. public UIPartical UIPartical;
  98. public Transform FlowerItem;
  99. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  100. #endregion
  101. public FlowerInfo(XmlAttributeCollection attribute)
  102. {
  103. FlowerItem = ManaReso.Get("FlowerItem", Folder.UI, false, ManaReso.Get("G_RegularGrid"), false, ObjType.FlowerItem);
  104. Auxiliary.CompileDic(FlowerItem, ChildDic);
  105. Text = ChildDic["Lab"].GetComponent<Text>();
  106. Image = ChildDic["Icon"].GetComponent<Image>();
  107. Button = ChildDic["FlowerItem"].GetComponent<Button>();
  108. UIPartical = ChildDic["UIParticle System"].GetComponent<UIPartical>();
  109. ID_ = int.Parse(attribute[0].Value);
  110. Icon_ = attribute[5].Value;
  111. UnlockCur = Auxiliary.CurrentParse(attribute[3].Value);
  112. UnlockAmt = Auxiliary.IntParse(attribute[4].Value, 0);
  113. Image.sprite = Icon;
  114. Image.Resize(true, 0.2f, 0.2f);
  115. Button.onClick.AddListener
  116. (
  117. () =>
  118. {
  119. if (Plant)
  120. {
  121. ManaAudio.PlayClip(Clip.BtnClip);
  122. ManaGarden.ShowRetrieveCard(this);
  123. }
  124. else if (Unlock)
  125. {
  126. ManaGarden.PlantFlower(this);
  127. }
  128. else
  129. {
  130. ManaGarden.ShowUnlockCard(this);
  131. }
  132. }
  133. );
  134. }
  135. }
  136. public class Flower : Regist, IPointerClickHandler
  137. {
  138. #region 变量
  139. #region MiniGame
  140. public OpType OpType
  141. {
  142. get { return OpType_; }
  143. set
  144. {
  145. OpType_ = value;
  146. if (OpType_ == OpType.Rip)
  147. {
  148. OperateIcon.sprite = RipSprite;
  149. }
  150. else if (OpType_ == OpType.Water)
  151. {
  152. OperateIcon.sprite = WaterSprite;
  153. }
  154. else if (OpType_ == OpType.Fertilize)
  155. {
  156. OperateIcon.sprite = FertilizeSprite;
  157. }
  158. }
  159. }
  160. public OpType OpType_;
  161. public SpriteRenderer FlowerIcon;
  162. public SpriteRenderer OperateBk;
  163. public SpriteRenderer OperateIcon;
  164. public SpriteRenderer OperateOutline;
  165. #endregion
  166. public bool Award
  167. {
  168. get { return Award_; }
  169. set
  170. {
  171. Award_ = value;
  172. if (Award_)
  173. {
  174. ShowAward();
  175. }
  176. else
  177. {
  178. GetAward();
  179. }
  180. }
  181. }
  182. public Sprite RipSprite
  183. {
  184. get
  185. {
  186. return ManaReso.LoadSprite("Rip", Folder.UI);
  187. }
  188. }
  189. public Sprite WaterSprite
  190. {
  191. get
  192. {
  193. return ManaReso.LoadSprite("Water", Folder.UI);
  194. }
  195. }
  196. public Sprite FertilizeSprite
  197. {
  198. get
  199. {
  200. return ManaReso.LoadSprite("Fertilize", Folder.UI);
  201. }
  202. }
  203. public FlowerInfo FlowerInfo
  204. {
  205. get { return FlowerInfo_; }
  206. set
  207. {
  208. FlowerInfo_ = value;
  209. ID = FlowerInfo.ID_;
  210. FlowerIcon.sprite = FlowerInfo.Icon;
  211. }
  212. }
  213. public bool Award_;
  214. private FlowerInfo FlowerInfo_;
  215. public int ID;
  216. public Slot Slot;
  217. public Animator FlashLightAC;
  218. public Transform GoldBk;
  219. public Transform GoldIcon;
  220. public MaterialUnit NewFlowerEffectMatUnit;
  221. protected ParticleSystem NewFlowerEffect;
  222. public List<Transform> ElfList = new List<Transform>();
  223. public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
  224. public static string CoinFml;
  225. #endregion
  226. public override bool RegistImmed()
  227. {
  228. if (base.RegistImmed())
  229. {
  230. return true;
  231. }
  232. enabled = true;
  233. Auxiliary.CompileDic(transform, ChildDic);
  234. GoldBk = ChildDic["GoldBk"];
  235. GoldIcon = ChildDic["GoldIcon"];
  236. FlashLightAC = ChildDic["FlashLight"].GetComponent<Animator>();
  237. FlowerIcon = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
  238. OperateBk = ChildDic["OperateBk"].GetComponent<SpriteRenderer>();
  239. OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
  240. OperateOutline = ChildDic["OperateOutline1"].GetComponent<SpriteRenderer>();
  241. NewFlowerEffect = ChildDic["NewFlowerEffect"].GetComponent<ParticleSystem>();
  242. GoldBk.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
  243. GoldIcon.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
  244. #region 新花粒子特效
  245. Renderer renderer = NewFlowerEffect.GetComponent<Renderer>();
  246. Material material = new Material(renderer.material);
  247. renderer.material = material;
  248. NewFlowerEffectMatUnit = new MaterialUnit(material, NewFlowerEffect.transform, new List<string>() { "_Alpha" });
  249. NewFlowerEffectMatUnit.CreateTweenMatFloat(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  250. #endregion
  251. TweenRoot tween = FlowerIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad, false, true);
  252. tween.OnForwardFinish += () =>
  253. {
  254. FlowerIcon.TweenBacSr();
  255. };
  256. tween = OperateBk.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad, false, true);
  257. tween.OnForwardFinish += () =>
  258. {
  259. OperateBk.TweenBacSr();
  260. };
  261. tween = OperateBk.CreateTweenScale(OperateBk.transform.localScale + new Vector3(0.1f, 0.1f, 0.1f), 0.25f, false, true, Curve.EaseOutQuad);
  262. tween.OnBackwardFinish += () =>
  263. {
  264. if (OpType != OpType.Null)
  265. {
  266. OperateBk.SetActive(true);
  267. }
  268. };
  269. return false;
  270. }
  271. #region MiniGame
  272. public void GameOver()
  273. {
  274. OpType = OpType.Null;
  275. ChildDic["MiniGame"].SetActive(false);
  276. OperateBk.TweenBacScale();
  277. }
  278. public void GameBegin()
  279. {
  280. ChildDic["MiniGame"].SetActive(true);
  281. OperateBk.SetActive(false);
  282. }
  283. public void SetFirstOp()
  284. {
  285. OperateBk.TweenForScale();
  286. OperateIcon.SetAlpha(1);
  287. OperateOutline.SetAlpha(1);
  288. OperateIcon.SetActive(true);
  289. OperateOutline.SetActive(true);
  290. }
  291. public void SetThirdOp()
  292. {
  293. OperateIcon.SetAlpha(0.5f);
  294. OperateOutline.SetAlpha(0.5f);
  295. OperateIcon.SetActive(true);
  296. OperateOutline.SetActive(false);
  297. }
  298. public void SetSecondOp()
  299. {
  300. OperateIcon.SetAlpha(1);
  301. OperateOutline.SetAlpha(1);
  302. OperateIcon.SetActive(true);
  303. OperateOutline.SetActive(false);
  304. }
  305. public void CreateOp(int sequence)
  306. {
  307. float random = Random.Range(0f, 1f);
  308. OperateBk.SetActive(true);
  309. if (random <= 0.3333333f)
  310. {
  311. OpType = OpType.Rip;
  312. }
  313. else if (random <= 0.6666666f)
  314. {
  315. OpType = OpType.Water;
  316. }
  317. else
  318. {
  319. OpType = OpType.Fertilize;
  320. }
  321. if (sequence == 0)
  322. {
  323. SetFirstOp();
  324. }
  325. else if (sequence == 1)
  326. {
  327. SetSecondOp();
  328. }
  329. else
  330. {
  331. SetThirdOp();
  332. }
  333. }
  334. public void CreateOp(int sequence, OpType opType)
  335. {
  336. OpType = opType;
  337. OperateBk.SetActive(true);
  338. if (sequence == 0)
  339. {
  340. SetFirstOp();
  341. }
  342. else if (sequence == 1)
  343. {
  344. SetSecondOp();
  345. }
  346. else
  347. {
  348. SetThirdOp();
  349. }
  350. }
  351. public bool Operate(OpType opType)
  352. {
  353. if (opType == OpType.Rip)
  354. {
  355. ManaReso.Get("D_Rip2").TweenForScale();
  356. }
  357. else if (opType == OpType.Water)
  358. {
  359. ManaReso.Get("D_Water2").TweenForScale();
  360. }
  361. else if (opType == OpType.Fertilize)
  362. {
  363. ManaReso.Get("D_Fertilize2").TweenForScale();
  364. }
  365. if (opType != OpType)
  366. {
  367. OperateBk.TweenForSr();
  368. FlowerIcon.TweenForSr();
  369. OperateIcon.Shake(0.5f, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
  370. ManaAudio.PlayClip(Clip.ErrorClip);
  371. return false;
  372. }
  373. else
  374. {
  375. ManaReso.GetHudText("+15", Color.white, 90, ChildDic["ScorePosTra"], ManaReso.Get("D_HudParent"), true);
  376. ManaMiniGame.Score += 15;
  377. PlayFlashLight();
  378. OpType = OpType.Null;
  379. OperateBk.TweenBacScale();
  380. OperateBk.SetActive(false);
  381. OperateIcon.SetActive(false);
  382. OperateOutline.SetActive(false);
  383. ManaAudio.PlayClip(Clip.BtnClip);
  384. return true;
  385. }
  386. }
  387. #endregion
  388. public void GetElf(ElfType elfType, float xMin = -0.75f, float xMax = 0.75f, float yMin = 0, float yMax = 0.75f)
  389. {
  390. ElfList.Add(ManaReso.GetElf(this, new Vector4(xMin, xMax, yMin, yMax), elfType));
  391. }
  392. public void Retrieve()
  393. {
  394. ChildDic["Flash"].SetActive(false);
  395. ChildDic["Particle System"].SetActive(false);
  396. FlowerInfo.ChildDic["UIFlash"].SetActive(false);
  397. FlowerInfo.ChildDic["UIParticle System"].SetActive(false);
  398. StopNewFlowerEffec();
  399. ManaReso.Save(this);
  400. RetrieveElf();
  401. Award_ = false;
  402. ResetAward();
  403. }
  404. public void RetrieveElf()
  405. {
  406. for (int i = 0; i < ElfList.Count; i++)
  407. {
  408. ManaReso.Save(ElfList[i]);
  409. }
  410. ElfList = new List<Transform>();
  411. }
  412. public void PlayFlashLight()
  413. {
  414. FlashLightAC.SetTrigger("Play");
  415. }
  416. public void PlayNewFlowerEffec()
  417. {
  418. NewFlowerEffectMatUnit.TweenForMatFloat();
  419. }
  420. public void StopNewFlowerEffec()
  421. {
  422. NewFlowerEffectMatUnit.TweenBacMatFloat();
  423. }
  424. public void GetAward()
  425. {
  426. ManaAudio.PlayClip(Clip.CurrentClip);
  427. PlayFlashLight();
  428. int coin;
  429. if (ManaVisit.InVisit)
  430. {
  431. int awardMin = Mathf.CeilToInt((float) Auxiliary.FmlParse(ManaVisit.AwardMinFml, "l", ManaCenter.Level.ToString()));
  432. int awardMax = Mathf.CeilToInt((float) Auxiliary.FmlParse(ManaVisit.AwardMaxFml, "l", ManaCenter.Level.ToString()));
  433. coin = Mathf.CeilToInt(Mathf.Lerp(awardMin, awardMax, Random.Range(0f, 1f)));
  434. ManaCenter.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.ClickFlower);
  435. }
  436. else
  437. {
  438. coin = Mathf.CeilToInt((float)Auxiliary.FmlParse(CoinFml, "l", Mathf.Clamp(ManaCenter.Level, 1, Mathf.Infinity).ToString()));
  439. ManaCenter.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.ClickFlower);
  440. ManaCenter.FlowerCoin++;
  441. }
  442. ManaReso.GetHudText("<(金币)>+" + coin, Color.white, 90, ChildDic["GoldPosTra"], ManaReso.Get("A_HudParent"), true);
  443. ResetAward();
  444. }
  445. public void ResetAward()
  446. {
  447. GoldBk.SetActive(false);
  448. GoldBk.GetTweenSr().Pause();
  449. GoldIcon.GetTweenSr().Pause();
  450. GoldBk.GetTweenSr().InOrigin = true;
  451. GoldIcon.GetTweenSr().InOrigin = true;
  452. }
  453. public void ShowAward()
  454. {
  455. //if (Slot.Index%9 == 3 || Slot.Index%9 == 8)
  456. //{
  457. GoldBk.SetX(ChildDic["GoldBKPosLeft"].position.x);
  458. GoldBk.GetComponent<SpriteRenderer>().flipX = true;
  459. //}
  460. //else
  461. //{
  462. // GoldBk.SetX(ChildDic["GoldBKPosRight"].position.x);
  463. // GoldBk.GetComponent<SpriteRenderer>().flipX = false;
  464. //}
  465. GoldBk.SetY(transform.position.y + 2.5f);
  466. GoldBk.TweenReForSr();
  467. GoldIcon.TweenReForSr();
  468. GoldBk.MoveOffset2D
  469. (
  470. new Vector3(0, 0.5f, 0),
  471. 1f,
  472. true,
  473. Curve.EaseOutQuad
  474. );
  475. }
  476. public void OnPointerClick(PointerEventData eventData)
  477. {
  478. if (eventData.rawPointerPress.transform == transform)
  479. {
  480. if (ManaVisit.InVisit)
  481. {
  482. return;
  483. }
  484. ManaReso.Get("G_Flower").TweenForCG();
  485. ManaGarden.ShowRetrieveCard(FlowerInfo);
  486. }
  487. else if (eventData.rawPointerPress.transform == GoldBk)
  488. {
  489. Award = false;
  490. }
  491. }
  492. }