ManaMiniGame.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Serialization;
  4. using System;
  5. using System.Xml;
  6. using System.Text;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using Random = UnityEngine.Random;
  10. public class Award
  11. {
  12. #region 变量
  13. public static int BonusCoin;
  14. public static int BonusDiamond;
  15. public static string Info;
  16. public int Rate;
  17. public int Coin;
  18. public int Score;
  19. public int Diamond;
  20. public bool FlowerFlag;
  21. public bool DiamondFlag;
  22. #region 配置
  23. public static int FlowerID;
  24. public static bool FlowerLock;
  25. public int DiamondMin;
  26. public int DiamondMax;
  27. public string CoinFml;
  28. public string FlowerFml;
  29. public string DiamondFml;
  30. public List<float> Odds = new List<float>();
  31. public List<float> Standard = new List<float>();
  32. #endregion
  33. #endregion
  34. public void GetAward(int score)
  35. {
  36. #region 获得奖励
  37. #region Rate
  38. Score = (int)Mathf.Clamp(score, 1, Mathf.Infinity);
  39. if (Score < Standard[1])
  40. {
  41. Rate = 0;
  42. }
  43. else if (Score < Standard[2])
  44. {
  45. Rate = 1;
  46. }
  47. else
  48. {
  49. Rate = 2;
  50. }
  51. #endregion
  52. #region Reset
  53. FlowerFlag = false;
  54. DiamondFlag = false;
  55. #endregion
  56. StringBuilder sb = new StringBuilder();
  57. #region Coin
  58. Coin = (int)Auxiliary.FmlParse(CoinFml, "s", Score.ToString(), "l", Mathf.Clamp(ManaCenter.Level, 1, 9999).ToString());
  59. Coin = (int)(Coin * (1 + ManaCenter.SkillPlus) + BonusCoin);
  60. Coin = (int) Mathf.Clamp(Coin, 1, Mathf.Infinity);
  61. ManaReso.Get<Text>("Da_CoinLab").text = Coin.ToString();
  62. ManaReso.Get<Text>("Da_CoinLab").Resize(true, false);
  63. ManaReso.Get<ContentSizeFitter>("Da_CoinGroup").enabled = true;
  64. ManaReso.SetActive("Da_CoinLab", true);
  65. ManaCenter.Coin += Coin;
  66. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", Coin);
  67. #endregion
  68. #region Diamond
  69. float diamondRate = (float)Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaCenter.Level, 1, 1000).ToString());
  70. if (Random.Range(0, 1f) <= diamondRate)
  71. {
  72. DiamondFlag = true;
  73. Diamond = (int)(Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond);
  74. ManaReso.Get<Text>("Da_DiamondLab").text = Diamond.ToString();
  75. ManaReso.Get<Text>("Da_DiamondLab").Resize(true, false);
  76. ManaReso.Get<ContentSizeFitter>("Da_DiamondGroup").enabled = true;
  77. ManaReso.SetActive("Da_DiamondLab", true);
  78. ManaCenter.Diamond += Diamond;
  79. ManaReso.SetActive("Da_Diamond", true);
  80. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", Diamond);
  81. }
  82. else
  83. {
  84. if (BonusDiamond > 0)
  85. {
  86. DiamondFlag = true;
  87. Diamond = BonusDiamond;
  88. ManaReso.Get<Text>("Da_DiamondLab").text = Diamond.ToString();
  89. ManaReso.Get<Text>("Da_DiamondLab").Resize(true, false);
  90. ManaReso.Get<ContentSizeFitter>("Da_DiamondGroup").enabled = true;
  91. ManaReso.SetActive("Da_DiamondLab", true);
  92. ManaCenter.Diamond += Diamond;
  93. ManaReso.SetActive("Da_Diamond", true);
  94. sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", Diamond);
  95. }
  96. }
  97. #endregion
  98. #region Flower
  99. if (ManaTutorial.TutorialA)
  100. {
  101. FlowerFlag = true;
  102. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[1];
  103. ManaReso.SetActive("Da_FlowerIcon", true);
  104. ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
  105. ManaReso.Get<Image>("Da_FlowerIcon").Resize(true, 0.2f, 0.2f);
  106. ManaReso.SetText("Da_FlowerLab", flowerInfo.Name);
  107. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  108. }
  109. else
  110. {
  111. if (!FlowerLock)
  112. {
  113. FlowerFlag = true;
  114. if (Random.Range(0, 1f) <= Odds[Rate])
  115. {
  116. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerID];
  117. flowerInfo.Unlock = true;
  118. ManaReso.SetActive("Da_Flower", true);
  119. ManaReso.Get<Image>("Da_FlowerIcon").sprite = flowerInfo.Icon;
  120. ManaReso.Get<Image>("Da_FlowerIcon").Resize(true, 0.2f, 0.2f);
  121. ManaReso.SetText("Da_FlowerLab", flowerInfo.Name);
  122. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name);
  123. }
  124. else
  125. {
  126. ManaReso.SetActive("Da_Flower", false);
  127. ManaReso.SetText("Da_FlowerLab", Language.GetStr("UI", "Da_HigherScore"));
  128. }
  129. }
  130. }
  131. #endregion
  132. Info = sb.ToString();
  133. BonusCoin = 0;
  134. BonusDiamond = 0;
  135. #endregion
  136. ManaReso.Get("Da_Info").TweenForCG();
  137. //Auxiliary.Instance.DelayCall
  138. // (
  139. // () =>
  140. // {
  141. // Debug.LogError("");
  142. // },
  143. // 1
  144. // );
  145. Auxiliary.Instance.DelayCall
  146. (
  147. () =>
  148. {
  149. ManaReso.Get<Text>("Da_CoinLab").SetLayoutDirty();
  150. ManaReso.Get<Text>("Da_DiamondLab").SetLayoutDirty();
  151. ManaReso.Get<ContentSizeFitter>("Da_CoinGroup").enabled = false;
  152. ManaReso.Get<ContentSizeFitter>("Da_DiamondGroup").enabled = false;
  153. InitializeAnim();
  154. },
  155. 2
  156. );
  157. }
  158. public void InitializeAnim()
  159. {
  160. #region 构造动画
  161. #region Reset
  162. ManaReso.SetText("Da_Tit", Language.GetStr("UI", "Da_Tit1"));
  163. ManaReso.SetText("Da_CoinLab", "0");
  164. ManaReso.SetText("Da_DiamondLab", "0");
  165. ManaReso.SetActive("Da_Lab", false);
  166. ManaReso.SetActive("Da_Quit", false);
  167. ManaReso.SetActive("Da_Cancel", false);
  168. ManaReso.SetActive("Da_CoinLab", false);
  169. ManaReso.SetActive("Da_ScoreTit", false);
  170. ManaReso.SetActive("Da_ScoreLab", false);
  171. ManaReso.SetActive("Da_GetAward", false);
  172. ManaReso.SetActive("Da_DiamondLab", false);
  173. ManaReso.SetActive("Da_VGroup", true);
  174. ManaReso.SetActive("Da_HGroup1", false);
  175. ManaReso.SetActive("Da_FlowerGroup", false);
  176. ManaReso.SetActive("Da_DiamondGroup", false);
  177. if (FlowerFlag)
  178. {
  179. ManaReso.SetActive("Da_FlowerGroup", true);
  180. }
  181. if (DiamondFlag)
  182. {
  183. ManaReso.SetActive("Da_DiamondGroup", true);
  184. }
  185. Auxiliary.Instance.DelayCall
  186. (
  187. () =>
  188. {
  189. ManaReso.Get<VerticalLayoutGroup>("Da_VGroup").enabled = false;
  190. ManaReso.SetActive("Da_CoinGroup", false);
  191. ManaReso.SetActive("Da_FlowerGroup", false);
  192. ManaReso.SetActive("Da_DiamondGroup", false);
  193. },
  194. 1
  195. );
  196. float timeCoin = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Coin / 15f));
  197. float timeScore = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Score / 50f));
  198. float timeDiamond = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Diamond / 15f));
  199. float time = Mathf.Max(timeCoin, timeDiamond);
  200. ManaReso.Get("Da_CoinLab").CreateTweenNumber(0, Coin, time, false, true, Curve.EaseOutQuad);
  201. ManaReso.Get("Da_ScoreLab").CreateTweenNumber(0, Score, timeScore, false, true, Curve.EaseOutQuad);
  202. ManaReso.Get("Da_DiamondLab").CreateTweenNumber(0, Diamond, time, false, true, Curve.EaseOutQuad);
  203. #endregion
  204. #region 花
  205. TweenRoot tween;
  206. if (FlowerFlag)
  207. {
  208. tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
  209. tween.AddEventOnetime
  210. (
  211. EventType.ForwardFinish,
  212. () =>
  213. {
  214. ManaReso.Get("Da_FlowerGroup").TweenReForScale();
  215. }
  216. );
  217. }
  218. #endregion
  219. #region 按钮
  220. if (FlowerFlag)
  221. {
  222. tween = ManaReso.Get("Da_FlowerGroup").GetTweenScale();
  223. tween.AddEventOnetime
  224. (
  225. EventType.ForwardFinish,
  226. () =>
  227. {
  228. ManaReso.Get("Da_GetAward").TweenReForCG();
  229. }
  230. );
  231. }
  232. else
  233. {
  234. tween = ManaReso.Get("Da_CoinLab").GetTweenNumber();
  235. tween.AddEventOnetime
  236. (
  237. EventType.ForwardFinish,
  238. () =>
  239. {
  240. ManaReso.Get("Da_GetAward").TweenReForCG();
  241. }
  242. );
  243. }
  244. if (ManaTutorial.TutorialA)
  245. {
  246. tween = ManaReso.Get("Da_GetAward").GetTweenCG();
  247. tween.AddEventOnetime
  248. (
  249. EventType.ForwardFinish,
  250. () =>
  251. {
  252. Tutorial.HightScreen(ManaReso.Get("Da_Arrow0"), ManaReso.Get("Da_Arrow1"), ManaReso.Get("Da_GetAward"));
  253. }
  254. );
  255. }
  256. ManaReso.AddButtonEventOnetime
  257. (
  258. "Da_GetAward",
  259. () =>
  260. {
  261. ManaReso.Get("Da_VGroup").GetComponent<VerticalLayoutGroup>().enabled = true;
  262. }
  263. );
  264. #endregion
  265. #region 得分
  266. if (Rate == 0)
  267. {
  268. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  269. }
  270. else if (Rate == 1)
  271. {
  272. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  273. }
  274. else if (Rate == 2)
  275. {
  276. tween = ManaReso.Get("Da_Star3").GetTweenScale();
  277. }
  278. tween.AddEventOnetime
  279. (
  280. EventType.ForwardFinish,
  281. () =>
  282. {
  283. ManaReso.Get("Da_ScoreTit").TweenReForFont();
  284. }
  285. );
  286. tween = ManaReso.Get("Da_ScoreTit").GetTweenFont();
  287. tween.InOrigin = true;
  288. tween.AddEventOnetime
  289. (
  290. EventType.ForwardFinish,
  291. () =>
  292. {
  293. ManaReso.Get("Da_ScoreLab").TweenReForNumber();
  294. }
  295. );
  296. #endregion
  297. #region 五角星
  298. tween = ManaReso.Get("Da_Star3").GetTweenScale();
  299. tween.InOrigin = true;
  300. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  301. tween.InOrigin = true;
  302. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  303. tween.InOrigin = true;
  304. tween = ManaReso.Get("Da_Info").GetTweenCG();
  305. tween.AddEventOnetime
  306. (
  307. EventType.ForwardFinish,
  308. () =>
  309. {
  310. ManaReso.Get("Da_Star1").TweenReForScale();
  311. ManaReso.SetActive("Da_HGroup1", true);
  312. }
  313. );
  314. if (Rate == 0)
  315. {
  316. ManaReso.SetActive("Da_Star2", false);
  317. ManaReso.SetActive("Da_Star3", false);
  318. }
  319. else if (Rate == 1)
  320. {
  321. ManaReso.SetActive("Da_Star2", true);
  322. ManaReso.SetActive("Da_Star3", false);
  323. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  324. tween.AddEventOnetime
  325. (
  326. EventType.ForwardFinish,
  327. () =>
  328. {
  329. ManaReso.Get("Da_Star2").TweenReForScale();
  330. }
  331. );
  332. }
  333. else if (Rate == 2)
  334. {
  335. ManaReso.SetActive("Da_Star2", true);
  336. ManaReso.SetActive("Da_Star3", true);
  337. tween = ManaReso.Get("Da_Star1").GetTweenScale();
  338. tween.AddEventOnetime
  339. (
  340. EventType.ForwardFinish,
  341. () =>
  342. {
  343. ManaReso.Get("Da_Star2").TweenReForScale();
  344. }
  345. );
  346. tween = ManaReso.Get("Da_Star2").GetTweenScale();
  347. tween.AddEventOnetime
  348. (
  349. EventType.ForwardFinish,
  350. () =>
  351. {
  352. ManaReso.Get("Da_Star3").TweenReForScale();
  353. }
  354. );
  355. }
  356. #endregion
  357. #region 金币钻石
  358. tween = ManaReso.Get("Da_ScoreLab").GetTweenNumber();
  359. tween.AddEventOnetime
  360. (
  361. EventType.ForwardFinish,
  362. () =>
  363. {
  364. ManaReso.Get("Da_CoinGroup").TweenReForScale();
  365. if (DiamondFlag)
  366. {
  367. ManaReso.Get("Da_DiamondGroup").TweenReForScale();
  368. }
  369. }
  370. );
  371. tween = ManaReso.Get("Da_CoinGroup").GetTweenScale();
  372. tween.AddEventOnetime
  373. (
  374. EventType.ForwardFinish,
  375. () =>
  376. {
  377. ManaReso.Get("Da_CoinLab").TweenReForNumber();
  378. }
  379. );
  380. if (DiamondFlag)
  381. {
  382. tween = ManaReso.Get("Da_DiamondGroup").GetTweenScale();
  383. tween.AddEventOnetime
  384. (
  385. EventType.ForwardFinish,
  386. () =>
  387. {
  388. ManaReso.Get("Da_DiamondLab").TweenReForNumber();
  389. }
  390. );
  391. }
  392. #endregion
  393. #endregion
  394. }
  395. public Award(XmlAttributeCollection attribute)
  396. {
  397. Flower.CoinFml = attribute[8].Value;
  398. DropGold.CoinFml = attribute[7].Value;
  399. Star.CD = float.Parse(attribute[9].Value);
  400. Star.Time = float.Parse(attribute[11].Value);
  401. string[] strings = attribute[10].Value.Split(',');
  402. ManaGarden.MinStarTime = float.Parse(strings[0]);
  403. ManaGarden.MaxStarTime = float.Parse(strings[1]);
  404. ManaGarden.StarTimer = Mathf.Lerp(ManaGarden.MinStarTime, ManaGarden.MaxStarTime, Random.Range(0f, 1f));
  405. CoinFml = attribute[1].Value;
  406. FlowerFml = attribute[4].Value;
  407. DiamondFml = attribute[3].Value;
  408. strings = attribute[2].Value.Split(',');
  409. DiamondMin = int.Parse(strings[0]);
  410. DiamondMax = int.Parse(strings[1]);
  411. strings = attribute[5].Value.Split(',');
  412. Odds = new List<float>()
  413. {
  414. float.Parse(strings[0]),
  415. float.Parse(strings[1]),
  416. float.Parse(strings[2]),
  417. };
  418. strings = attribute[6].Value.Split(',');
  419. Standard = new List<float>()
  420. {
  421. float.Parse(strings[0]),
  422. float.Parse(strings[1]),
  423. float.Parse(strings[2]),
  424. };
  425. }
  426. }
  427. public class ManaMiniGame : Regist
  428. {
  429. #region 变量
  430. public static int Score
  431. {
  432. get { return Score_; }
  433. set
  434. {
  435. Score_ = value;
  436. ManaReso.SetText("D_ScoreLab", ScoreLab + Score_);
  437. }
  438. }
  439. public static bool Game
  440. {
  441. get { return Game_; }
  442. set
  443. {
  444. Game_ = value;
  445. if (Game_)
  446. {
  447. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  448. }
  449. else
  450. {
  451. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab0"));
  452. }
  453. }
  454. }
  455. public static bool Pause
  456. {
  457. get { return Pause_; }
  458. set
  459. {
  460. Pause_ = value;
  461. if (Game)
  462. {
  463. if (Pause_)
  464. {
  465. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab2"));
  466. }
  467. else
  468. {
  469. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  470. }
  471. }
  472. else if (Prepare)
  473. {
  474. if (Pause_)
  475. {
  476. PrepareLab.GetStreamScale().Pause();
  477. }
  478. else
  479. {
  480. PrepareLab.GetStreamScale().Resume();
  481. }
  482. }
  483. }
  484. }
  485. public static bool Panalty
  486. {
  487. get { return Panalty_; }
  488. set
  489. {
  490. Panalty_ = value;
  491. if (Game)
  492. {
  493. if (Panalty_)
  494. {
  495. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab3"));
  496. }
  497. else
  498. {
  499. ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1"));
  500. }
  501. }
  502. }
  503. }
  504. public static float GameTimer
  505. {
  506. get { return GameTimer_; }
  507. set
  508. {
  509. GameTimer_ = value;
  510. TimerLab.text = (GameTime-GameTimer_).ToString("0.0");
  511. TimerBk.fillAmount = GameTimer_/GameTime;
  512. TimerBk.material.SetFloat("_Fill", TimerBk.fillAmount);
  513. }
  514. }
  515. private static int Score_;
  516. private static bool Game_;
  517. private static bool Pause_;
  518. private static bool Panalty_;
  519. private static float GameTimer_;
  520. public static Text TimerLab;
  521. public static Text PrepareLab;
  522. public static Image TimerBk;
  523. public static Award Award;
  524. public static Transform D_Grid;
  525. public static Transform D_Timer;
  526. public static Transform D_Begin;
  527. public static Transform D_Status1;
  528. public static Transform D_Status2;
  529. public static Transform D_Operate1;
  530. public static Transform D_Operate2;
  531. public static List<int> IndexList = new List<int>();
  532. public static List<Drop> DropList = new List<Drop>();
  533. public static List<Flower> OpList = new List<Flower>();
  534. public static List<Flower> IdleList = new List<Flower>();
  535. public static List<Flower> FadeList = new List<Flower>();
  536. public static Dictionary<int, Flower> FlowerDic = new Dictionary<int, Flower>();
  537. public static int MiniGameIndex;
  538. public static string ScoreLab;
  539. public static bool GameA;
  540. public static bool GameB;
  541. public static bool Prepare;
  542. public static bool FlowerLock;
  543. public static bool TutorialLock = true;
  544. public static bool DropDiamond;
  545. public static float OpTimer;
  546. public static float FadeTimer;
  547. public static float GoldTimer;
  548. public static float PanaltyTimer;
  549. public static float PrepareTimer;
  550. public static float DiamondTimer;
  551. public static float OpTime = 1.5f;
  552. public static float FadeTime = 2f;
  553. public static float GameTime = 45f;
  554. public static float PanaltyTime = 1f;
  555. public static float NewOpTime;
  556. public static float NewFadeTime;
  557. #endregion
  558. private void FixedUpdate()
  559. {
  560. if (Pause)
  561. {
  562. return;
  563. }
  564. if (Game)
  565. {
  566. GameThreadA();
  567. GameThreadB();
  568. }
  569. if (Prepare)
  570. {
  571. PrepareThread();
  572. }
  573. }
  574. private void GameThreadA()
  575. {
  576. if (GameB)
  577. {
  578. return;
  579. }
  580. GameTimer += Time.fixedDeltaTime;
  581. if (GameTimer >= GameTime)
  582. {
  583. GameOver();
  584. return;
  585. }
  586. if (Panalty)
  587. {
  588. PanaltyTimer -= Time.fixedDeltaTime;
  589. if (PanaltyTimer <= 0)
  590. {
  591. Panalty = false;
  592. }
  593. }
  594. if (IdleList.Count > 0)
  595. {
  596. OpTimer -= Time.fixedDeltaTime;
  597. if (OpTimer <= 0)
  598. {
  599. NewOpTime -= NewOpTime * 0.03f;
  600. OpTimer = NewOpTime;
  601. CreateOperate();
  602. }
  603. }
  604. BonusThread();
  605. }
  606. private void GameThreadB()
  607. {
  608. if (GameA)
  609. {
  610. return;
  611. }
  612. GameTimer += Time.fixedDeltaTime;
  613. if (GameTimer >= GameTime)
  614. {
  615. GameOver();
  616. return;
  617. }
  618. if (Panalty)
  619. {
  620. PanaltyTimer -= Time.fixedDeltaTime;
  621. if (PanaltyTimer <= 0)
  622. {
  623. Panalty = false;
  624. }
  625. }
  626. if (FadeList.Count < 6)
  627. {
  628. FadeTimer -= Time.fixedDeltaTime;
  629. if (FadeTimer <= 0)
  630. {
  631. FadeTimer = NewFadeTime;
  632. Fade();
  633. }
  634. }
  635. BonusThread();
  636. }
  637. private void BonusThread()
  638. {
  639. GoldTimer -= Time.fixedDeltaTime;
  640. if (GoldTimer < 0)
  641. {
  642. GoldTimer = Random.Range(3f, 6f);
  643. DropList.Add(ManaReso.GetDrop(ObjType.DropGold));
  644. }
  645. if (DropDiamond)
  646. {
  647. DiamondTimer -= Time.fixedDeltaTime;
  648. if (DiamondTimer < 0)
  649. {
  650. DropDiamond = false;
  651. DropList.Add(ManaReso.GetDrop(ObjType.DropDiamond));
  652. }
  653. }
  654. }
  655. private void PrepareThread()
  656. {
  657. PrepareTimer -= Time.fixedDeltaTime;
  658. if (PrepareTimer <= 0)
  659. {
  660. Prepare = false;
  661. GameBegin();
  662. }
  663. }
  664. public override void RegistValueA()
  665. {
  666. Award = new Award(ManaData.GetAwardConfig());
  667. MiniGameIndex = ManaData.GetPlayerInt("MiniGameIndex");
  668. }
  669. public override void RegistReference()
  670. {
  671. D_Grid = ManaReso.Get("D_Grid");
  672. D_Begin = ManaReso.Get("D_Begin");
  673. D_Timer = ManaReso.Get("D_Timer");
  674. D_Status1 = ManaReso.Get("D_Status1");
  675. D_Status2 = ManaReso.Get("D_Status2");
  676. D_Operate1 = ManaReso.Get("D_Operate1");
  677. D_Operate2 = ManaReso.Get("D_Operate2");
  678. TimerLab = ManaReso.Get<Text>("D_TimerLab");
  679. PrepareLab = ManaReso.Get<Text>("D_PrepareLab");
  680. TimerBk = ManaReso.Get<Image>("D_TimerIcon");
  681. }
  682. public static void Operate(int index)
  683. {
  684. if (Panalty || !FadeList.Valid())
  685. {
  686. return;
  687. }
  688. if (IndexList.Count == 0)
  689. {
  690. return;
  691. }
  692. if (index == IndexList[0])
  693. {
  694. int uiIndex = IndexMap(IndexList[0]);
  695. ManaReso.Get<Image>("D_FlowerBtn" + uiIndex).material = Shortcut.GrayMat;
  696. ManaReso.Get<Button>("D_FlowerBtn" + uiIndex).interactable = false;
  697. ManaReso.Get<Image>("D_FlowerIcon" + uiIndex).material = Shortcut.GrayMat;
  698. ManaReso.SetActive("D_FlowerTick" + uiIndex, true);
  699. IndexList.RemoveAt(0);
  700. Flower flower = FlowerDic[index];
  701. ManaReso.GetHudText("+45", Color.white, 90, flower.ChildDic["ScorePosTra"], ManaReso.Get("D_MiniGame"), true);
  702. Score += 45;
  703. flower.PlayParticle();
  704. TweenRoot tween = flower.FlowerIcon.TweenBacSr();
  705. ManaAudio.PlayClip(Clip.BtnClip);
  706. if (IndexList.Count == 0)
  707. {
  708. tween.AddEventOnetime
  709. (
  710. EventType.BackwardFinish,
  711. () =>
  712. {
  713. RoundEnd();
  714. RoundReset();
  715. RoundBegin();
  716. }
  717. );
  718. }
  719. }
  720. else
  721. {
  722. Panalty = true;
  723. PanaltyTimer = PanaltyTime;
  724. ManaAudio.PlayClip(Clip.ErrorClip);
  725. }
  726. }
  727. public static void Operate(OpType opType)
  728. {
  729. if (Panalty || !OpList.Valid())
  730. {
  731. return;
  732. }
  733. if (OpList[0].Operate(opType))
  734. {
  735. IdleList.Add(OpList[0]);
  736. OpList.Remove(OpList[0]);
  737. if (OpList.Count >= 2)
  738. {
  739. OpList[0].SetFirstOp();
  740. OpList[1].SetSecondOp();
  741. }
  742. else if (OpList.Count >= 1)
  743. {
  744. OpList[0].SetFirstOp();
  745. }
  746. }
  747. else
  748. {
  749. Panalty = true;
  750. PanaltyTimer = PanaltyTime;
  751. }
  752. }
  753. public static void ResetOprerate()
  754. {
  755. ManaReso.Get<Image>("D_FlowerBtn1").material = null;
  756. ManaReso.Get<Image>("D_FlowerBtn2").material = null;
  757. ManaReso.Get<Image>("D_FlowerBtn3").material = null;
  758. ManaReso.Get<Image>("D_FlowerBtn4").material = null;
  759. ManaReso.Get<Image>("D_FlowerBtn5").material = null;
  760. ManaReso.Get<Image>("D_FlowerBtn6").material = null;
  761. ManaReso.Get<Button>("D_FlowerBtn1").interactable = true;
  762. ManaReso.Get<Button>("D_FlowerBtn2").interactable = true;
  763. ManaReso.Get<Button>("D_FlowerBtn3").interactable = true;
  764. ManaReso.Get<Button>("D_FlowerBtn4").interactable = true;
  765. ManaReso.Get<Button>("D_FlowerBtn5").interactable = true;
  766. ManaReso.Get<Button>("D_FlowerBtn6").interactable = true;
  767. ManaReso.Get<Image>("D_FlowerIcon1").material = null;
  768. ManaReso.Get<Image>("D_FlowerIcon2").material = null;
  769. ManaReso.Get<Image>("D_FlowerIcon3").material = null;
  770. ManaReso.Get<Image>("D_FlowerIcon4").material = null;
  771. ManaReso.Get<Image>("D_FlowerIcon5").material = null;
  772. ManaReso.Get<Image>("D_FlowerIcon6").material = null;
  773. ManaReso.SetActive("D_FlowerTick1", false);
  774. ManaReso.SetActive("D_FlowerTick2", false);
  775. ManaReso.SetActive("D_FlowerTick3", false);
  776. ManaReso.SetActive("D_FlowerTick4", false);
  777. ManaReso.SetActive("D_FlowerTick5", false);
  778. ManaReso.SetActive("D_FlowerTick6", false);
  779. }
  780. public static void CreateOperate()
  781. {
  782. ManaAudio.PlayClip(Clip.BubbleClip);
  783. if (ManaTutorial.TutorialA && TutorialLock)
  784. {
  785. Pause = true;
  786. TutorialLock = false;
  787. Flower flower = IdleList[4];
  788. flower.CreateOp(OpList.Count, OpType.Water);
  789. OpList.Add(flower);
  790. IdleList.Remove(flower);
  791. Tutorial.HightScreen(ManaReso.Get("D_WaterArrow0"), ManaReso.Get("D_WaterArrow1"), ManaReso.Get("D_Water1"));
  792. Tutorial.SetArea(OpList[0].OperateIcon.transform, 0.1f, 0.125f);
  793. ManaReso.AddButtonEventOnetime
  794. (
  795. "D_Water2",
  796. () =>
  797. {
  798. Pause = false;
  799. Tutorial.HightDisable();
  800. }
  801. );
  802. }
  803. else
  804. {
  805. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  806. flower.CreateOp(OpList.Count);
  807. OpList.Add(flower);
  808. IdleList.Remove(flower);
  809. }
  810. }
  811. public static void Fade()
  812. {
  813. for (int i = 0; i < IndexList.Count; i++)
  814. {
  815. Flower flower = FlowerDic[IndexList[i]];
  816. if (FadeList.UniqueAdd(flower))
  817. {
  818. IdleList.Remove(flower);
  819. flower.PlayParticle();
  820. flower.FlowerIcon.TweenForSr();
  821. if (FadeList.Count == 6)
  822. {
  823. RoundBegin();
  824. }
  825. break;
  826. }
  827. }
  828. }
  829. public static void InitializeMode()
  830. {
  831. GameA = false;
  832. GameB = false;
  833. D_Operate1.SetActive(false);
  834. D_Operate2.SetActive(false);
  835. if (ManaCenter.Level >= 18)
  836. {
  837. if (ManaTutorial.TutorialB)
  838. {
  839. GameB = true;
  840. }
  841. else
  842. {
  843. if (Random.Range(0f, 1f) <= 0.5f)
  844. {
  845. GameB = true;
  846. }
  847. else
  848. {
  849. GameA = true;
  850. }
  851. }
  852. }
  853. else
  854. {
  855. GameA = true;
  856. }
  857. }
  858. public static void InitializeAward()
  859. {
  860. float flowerRate = (float)Auxiliary.FmlParse(Award.FlowerFml, "l", ManaCenter.Level.ToString(), "f", ManaGarden.MyFlower.ToString());
  861. if (Random.Range(0, 1f) <= flowerRate)
  862. {
  863. if (ManaGarden.MyFlower < ManaGarden.TotalFlower)
  864. {
  865. foreach (var kv in ManaGarden.FlowerInfoDic)
  866. {
  867. if (kv.Value.Unlock == false)
  868. {
  869. Award.FlowerID = kv.Value.ID_;
  870. Award.FlowerLock = false;
  871. break;
  872. }
  873. }
  874. }
  875. else
  876. {
  877. Award.FlowerLock = true;
  878. }
  879. }
  880. else
  881. {
  882. Award.FlowerLock = true;
  883. }
  884. }
  885. public static void GameEnd()
  886. {
  887. PrepareLab.GetStreamScale().InOrigin = true;
  888. if (Game)
  889. {
  890. ManaCenter.MiniLock = false;
  891. ManaCenter.MiniTimer = Mathf.Lerp(180, 300, Random.Range(0, 1f));
  892. }
  893. if (ManaCenter.MiniTimer <= 0)
  894. {
  895. ManaReso.Get("C_MiniGame").TweenForCG();
  896. }
  897. Score = 0;
  898. Pause = false;
  899. Game = false;
  900. Panalty = false;
  901. Prepare = false;
  902. GameTimer = GameTime;
  903. for (int i = 0; i < OpList.Count; i++)
  904. {
  905. OpList[i].GameOver();
  906. }
  907. for (int i = 0; i < IdleList.Count; i++)
  908. {
  909. IdleList[i].GameOver();
  910. }
  911. for (int i = 0; i < DropList.Count; i++)
  912. {
  913. DropList[i].Retrieve();
  914. DropList.RemoveAt(i--);
  915. }
  916. }
  917. public static void GameOver()
  918. {
  919. ManaAudio.PlayClip(Clip.MiniEndClip);
  920. Award.GetAward(Score);
  921. ManaCenter.MiniGameAmt++;
  922. FlowerLock = false;
  923. GameEnd();
  924. }
  925. public static void GameEnter()
  926. {
  927. if (ManaTutorial.TutorialA)
  928. {
  929. Award.FlowerID = 1;
  930. Award.FlowerLock = true;
  931. InitializeMode();
  932. }
  933. else
  934. {
  935. if (!FlowerLock)
  936. {
  937. InitializeMode();
  938. InitializeAward();
  939. FlowerLock = true;
  940. }
  941. }
  942. if (ManaTutorial.TutorialB)
  943. {
  944. InitializeMode();
  945. }
  946. if (GameA)
  947. {
  948. GameEnterA();
  949. }
  950. if (GameB)
  951. {
  952. GameEnterB();
  953. }
  954. ScoreLab = Language.GetStr("UI", "D_ScoreLab");
  955. TimerBk.fillAmount = 0;
  956. TimerLab.text = GameTime.ToString("0");
  957. ManaReso.Get("C_MiniGame").TweenBacCG();
  958. }
  959. public static void GameEnterA()
  960. {
  961. D_Operate1.SetActive(true);
  962. D_Timer.SetParent(D_Status1);
  963. D_Grid.SetParent(D_Status1);
  964. D_Begin.SetParent(D_Operate1);
  965. PrepareLab.SetParent(ManaReso.Get("D_PrepareLayout1"));
  966. ManaReso.SetActive("D_Rip1", false);
  967. ManaReso.SetActive("D_Water1", false);
  968. ManaReso.SetActive("D_Fertilize1", false);
  969. ManaReso.SetActive("D_Begin", true);
  970. if (Award.FlowerLock)
  971. {
  972. for (int i = 1; i < 10; i++)
  973. {
  974. while (true)
  975. {
  976. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  977. if (flowerInfo.Unlock)
  978. {
  979. IdleList.Add(ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + i)));
  980. break;
  981. }
  982. }
  983. }
  984. }
  985. else
  986. {
  987. List<int> idList = new List<int>();
  988. idList = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9};
  989. int special = idList.Random(true);
  990. Flower flower = ManaReso.GetFlower(ManaGarden.FlowerInfoDic[Award.FlowerID], ManaReso.Get("SlotMini" + special));
  991. IdleList.Add(flower);
  992. for (int i = 0; i < idList.Count; i++)
  993. {
  994. while (true)
  995. {
  996. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  997. if (flowerInfo.Unlock)
  998. {
  999. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  1000. IdleList.Add(flower);
  1001. break;
  1002. }
  1003. }
  1004. }
  1005. }
  1006. }
  1007. public static void GameEnterB()
  1008. {
  1009. D_Operate2.SetActive(true);
  1010. D_Timer.SetParent(D_Status2);
  1011. D_Grid.SetParent(D_Status2);
  1012. D_Begin.SetParent(D_Operate2);
  1013. PrepareLab.SetParent(ManaReso.Get("D_PrepareLayout2"));
  1014. ResetOprerate();
  1015. ManaReso.Get("D_Mask").TweenBacGra();
  1016. ManaReso.SetActive("D_FlowerBtn1", false);
  1017. ManaReso.SetActive("D_FlowerBtn2", false);
  1018. ManaReso.SetActive("D_FlowerBtn3", false);
  1019. ManaReso.SetActive("D_FlowerBtn4", false);
  1020. ManaReso.SetActive("D_FlowerBtn5", false);
  1021. ManaReso.SetActive("D_FlowerBtn6", false);
  1022. ManaReso.SetActive("D_Begin", true);
  1023. List<int> idList = new List<int>() {1, 2, 4, 5, 7, 8};
  1024. FlowerDic = new Dictionary<int, Flower>();
  1025. Flower flower;
  1026. if (Award.FlowerLock)
  1027. {
  1028. for (int i = 0; i < idList.Count; i++)
  1029. {
  1030. while (true)
  1031. {
  1032. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  1033. if (flowerInfo.Unlock)
  1034. {
  1035. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  1036. IdleList.Add(flower);
  1037. FlowerDic.Add(idList[i], flower);
  1038. break;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. else
  1044. {
  1045. int special = idList.Random(true);
  1046. flower = ManaReso.GetFlower(ManaGarden.FlowerInfoDic[Award.FlowerID], ManaReso.Get("SlotMini" + special));
  1047. IdleList.Add(flower);
  1048. FlowerDic.Add(special, flower);
  1049. for (int i = 0; i < idList.Count; i++)
  1050. {
  1051. while (true)
  1052. {
  1053. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic.Random();
  1054. if (flowerInfo.Unlock)
  1055. {
  1056. flower = ManaReso.GetFlower(flowerInfo, ManaReso.Get("SlotMini" + idList[i]));
  1057. IdleList.Add(flower);
  1058. FlowerDic.Add(idList[i], flower);
  1059. break;
  1060. }
  1061. }
  1062. }
  1063. }
  1064. for (int i = 0; i < IdleList.Count; i++)
  1065. {
  1066. IdleList[i].FlowerIcon.CreateTweenSr(1, 0, 0.25f, true, false, Curve.EaseOutQuad, false, true);
  1067. }
  1068. }
  1069. public static void GameBegin()
  1070. {
  1071. Game = true;
  1072. MiniGameIndex++;
  1073. Score = 0;
  1074. OpTimer = OpTime;
  1075. FadeTimer = FadeTime;
  1076. GoldTimer = Random.Range(3f, 6f);
  1077. GameTimer = 0;
  1078. NewOpTime = OpTime;
  1079. NewFadeTime = FadeTime;
  1080. DiamondTimer = Random.Range(0f, GameTime - 5);
  1081. if (GameA)
  1082. {
  1083. for (int i = 0; i < IdleList.Count; i++)
  1084. {
  1085. IdleList[i].GameBegin();
  1086. }
  1087. }
  1088. if (GameB)
  1089. {
  1090. RoundReset();
  1091. }
  1092. if (Random.Range(5, 9) <= MiniGameIndex)
  1093. {
  1094. MiniGameIndex = 0;
  1095. DropDiamond = true;
  1096. }
  1097. else
  1098. {
  1099. if (Random.Range(0, 1f) <= 0.01f)
  1100. {
  1101. DropDiamond = true;
  1102. }
  1103. else
  1104. {
  1105. DropDiamond = false;
  1106. }
  1107. }
  1108. }
  1109. public static void GamePrepare()
  1110. {
  1111. Prepare = true;
  1112. PrepareTimer = 3;
  1113. ManaReso.Get("D_Begin").SetActive(false);
  1114. if (GameA)
  1115. {
  1116. ManaReso.Get("D_Rip1").SetActive(true);
  1117. ManaReso.Get("D_Water1").SetActive(true);
  1118. ManaReso.Get("D_Fertilize1").SetActive(true);
  1119. }
  1120. if (GameB)
  1121. {
  1122. ManaReso.Get("D_Mask").TweenForGra();
  1123. ManaReso.SetActive("D_FlowerBtn1", true);
  1124. ManaReso.SetActive("D_FlowerBtn2", true);
  1125. ManaReso.SetActive("D_FlowerBtn3", true);
  1126. ManaReso.SetActive("D_FlowerBtn4", true);
  1127. ManaReso.SetActive("D_FlowerBtn5", true);
  1128. ManaReso.SetActive("D_FlowerBtn6", true);
  1129. ManaReso.SetSprite("D_FlowerIcon1", FlowerDic[1].FlowerInfo.Icon).Resize(true, 1f, 1f);
  1130. ManaReso.SetSprite("D_FlowerIcon2", FlowerDic[2].FlowerInfo.Icon).Resize(true, 1f, 1f);
  1131. ManaReso.SetSprite("D_FlowerIcon3", FlowerDic[4].FlowerInfo.Icon).Resize(true, 1f, 1f);
  1132. ManaReso.SetSprite("D_FlowerIcon4", FlowerDic[5].FlowerInfo.Icon).Resize(true, 1f, 1f);
  1133. ManaReso.SetSprite("D_FlowerIcon5", FlowerDic[7].FlowerInfo.Icon).Resize(true, 1f, 1f);
  1134. ManaReso.SetSprite("D_FlowerIcon6", FlowerDic[8].FlowerInfo.Icon).Resize(true, 1f, 1f);
  1135. }
  1136. PrepareLab.StreamForScale();
  1137. }
  1138. public static void RoundEnd()
  1139. {
  1140. ManaReso.Get("D_Mask").TweenForGra();
  1141. }
  1142. public static void RoundReset()
  1143. {
  1144. for (int i = 0; i < FadeList.Count; i++)
  1145. {
  1146. IdleList.Add(FadeList[i]);
  1147. }
  1148. NewFadeTime -= NewFadeTime * 0.3f;
  1149. FadeTimer = NewFadeTime;
  1150. FadeList = new List<Flower>();
  1151. IndexList = new List<int>();
  1152. List<int> randomList = new List<int>() { 1, 2, 4, 5, 7, 8 };
  1153. for (int i = 0; i < randomList.Count; i++)
  1154. {
  1155. IndexList.Add(randomList.Random(true));
  1156. i--;
  1157. }
  1158. ResetOprerate();
  1159. }
  1160. public static void RoundBegin()
  1161. {
  1162. ManaReso.Get("D_Mask").TweenBacGra();
  1163. if (ManaTutorial.TutorialB)
  1164. {
  1165. ManaTutorial.EnterB1();
  1166. }
  1167. }
  1168. public static int IndexMap(int slotIndex)
  1169. {
  1170. if (slotIndex == 1)
  1171. {
  1172. return 1;
  1173. }
  1174. else if (slotIndex == 2)
  1175. {
  1176. return 2;
  1177. }
  1178. else if (slotIndex == 4)
  1179. {
  1180. return 3;
  1181. }
  1182. else if (slotIndex == 5)
  1183. {
  1184. return 4;
  1185. }
  1186. else if (slotIndex == 7)
  1187. {
  1188. return 5;
  1189. }
  1190. else if (slotIndex == 8)
  1191. {
  1192. return 6;
  1193. }
  1194. else
  1195. {
  1196. throw new Exception();
  1197. }
  1198. }
  1199. public void OnApplicationPause(bool pause)
  1200. {
  1201. if (!pause)
  1202. {
  1203. if (!ManaTutorial.TutorialA)
  1204. {
  1205. if (Game || Prepare)
  1206. {
  1207. ManaReso.Get<Button>("D_Quit").onClick.Invoke();
  1208. }
  1209. }
  1210. }
  1211. }
  1212. }
  1213. #region DebugList
  1214. //结束界面的图标能否重复显示
  1215. #endregion