ManaMiniGame.cs 38 KB

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