using UnityEngine; using UnityEngine.UI; using UnityEngine.Serialization; using System; using System.Xml; using System.Text; using System.Collections; using System.Collections.Generic; using Random = UnityEngine.Random; public class Award { #region 变量 public static int BonusCoin; public static int BonusDiamond; public static string Info; public int Rate; public int Coin; public int Score; public int Diamond; public bool FlowerFlag; public bool DiamondFlag; #region 配置 public static int FlowerID; public static bool FlowerLock; public int DiamondMin; public int DiamondMax; public string CoinFml; public string FlowerFml; public string DiamondFml; public List Odds = new List(); public List Standard = new List(); #endregion #endregion public void GetAward(int score) { #region 获得奖励 #region Rate Score = (int)Mathf.Clamp(score, 1, Mathf.Infinity); if (Score < Standard[1]) { Rate = 0; } else if (Score < Standard[2]) { Rate = 1; } else { Rate = 2; } #endregion #region Reset FlowerFlag = false; DiamondFlag = false; #endregion StringBuilder sb = new StringBuilder(); #region Coin Coin = (int)Auxiliary.FmlParse(CoinFml, "s", Score.ToString(), "l", Mathf.Clamp(ManaCenter.Level, 1, 9999).ToString()); Coin = (int)(Coin * (1 + ManaCenter.SkillPlus) + BonusCoin); Coin = (int) Mathf.Clamp(Coin, 1, Mathf.Infinity); ManaReso.Get("Da_CoinLab").text = Coin.ToString(); ManaReso.Get("Da_CoinLab").Resize(true, false); ManaReso.Get("Da_CoinGroup").enabled = true; ManaReso.SetActive("Da_CoinLab", true); ManaCenter.AddCoin(Coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.MiniGame); sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", Coin); #endregion #region Diamond float diamondRate = (float)Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(ManaCenter.Level, 1, 1000).ToString()); if (Random.Range(0, 1f) <= diamondRate) { DiamondFlag = true; Diamond = (int)(Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond); ManaReso.Get("Da_DiamondLab").text = Diamond.ToString(); ManaReso.Get("Da_DiamondLab").Resize(true, false); ManaReso.Get("Da_DiamondGroup").enabled = true; ManaReso.SetActive("Da_DiamondLab", true); ManaCenter.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.MiniGame); ManaReso.SetActive("Da_Diamond", true); sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", Diamond); } else { if (BonusDiamond > 0) { DiamondFlag = true; Diamond = BonusDiamond; ManaReso.Get("Da_DiamondLab").text = Diamond.ToString(); ManaReso.Get("Da_DiamondLab").Resize(true, false); ManaReso.Get("Da_DiamondGroup").enabled = true; ManaReso.SetActive("Da_DiamondLab", true); ManaCenter.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.MiniGame); ManaReso.SetActive("Da_Diamond", true); sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", Diamond); } else { Diamond = 0; } } #endregion #region Flower if (ManaTutorial.TutorialA) { FlowerFlag = true; FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[1]; ManaReso.SetActive("Da_FlowerIcon", true); ManaReso.Get("Da_FlowerIcon").sprite = flowerInfo.Icon; ManaReso.Get("Da_FlowerIcon").Resize(true, 0.2f, 0.2f); ManaReso.SetText("Da_FlowerLab", flowerInfo.Name); sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name); } else { if (!FlowerLock) { FlowerFlag = true; if (Random.Range(0, 1f) <= Odds[Rate]) { FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerID]; flowerInfo.Unlock = true; ManaReso.SetActive("Da_Flower", true); ManaReso.Get("Da_FlowerIcon").sprite = flowerInfo.Icon; ManaReso.Get("Da_FlowerIcon").Resize(true, 0.2f, 0.2f); ManaReso.SetText("Da_FlowerLab", flowerInfo.Name); sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name); } else { ManaReso.SetActive("Da_Flower", false); ManaReso.SetText("Da_FlowerLab", Language.GetStr("UI", "Da_HigherScore")); } } } #endregion Info = sb.ToString(); BonusCoin = 0; BonusDiamond = 0; #endregion ManaReso.SetActive("Da_Info", true); Auxiliary.Instance.DelayCall ( () => { ManaReso.Get("Da_CoinLab").SetLayoutDirty(); ManaReso.Get("Da_DiamondLab").SetLayoutDirty(); ManaReso.Get("Da_CoinGroup").enabled = false; ManaReso.Get("Da_DiamondGroup").enabled = false; InitializeAnim(); }, 2 ); } public void InitializeAnim() { #region 构造动画 #region Reset ManaReso.Get("Da_Info").TweenForCG(); ManaReso.SetText("Da_Tit", Language.GetStr("UI", "Da_Tit1")); ManaReso.SetText("Da_CoinLab", "0"); ManaReso.SetText("Da_DiamondLab", "0"); ManaReso.SetActive("Da_Lab", false); ManaReso.SetActive("Da_Quit", false); ManaReso.SetActive("Da_Cancel", false); ManaReso.SetActive("Da_CoinLab", false); ManaReso.SetActive("Da_ScoreTit", false); ManaReso.SetActive("Da_ScoreLab", false); ManaReso.SetActive("Da_GetAward", false); ManaReso.SetActive("Da_DiamondLab", false); ManaReso.SetActive("Da_VGroup", true); ManaReso.SetActive("Da_HGroup1", false); ManaReso.SetActive("Da_FlowerGroup", false); ManaReso.SetActive("Da_DiamondGroup", false); if (FlowerFlag) { ManaReso.SetActive("Da_FlowerGroup", true); } if (DiamondFlag) { ManaReso.SetActive("Da_DiamondGroup", true); } Auxiliary.Instance.DelayCall ( () => { ManaReso.Get("Da_VGroup").enabled = false; ManaReso.SetActive("Da_CoinGroup", false); ManaReso.SetActive("Da_FlowerGroup", false); ManaReso.SetActive("Da_DiamondGroup", false); }, 1 ); float timeCoin = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Coin / 15f)); float timeScore = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Score / 50f)); float timeDiamond = Mathf.Lerp(0, 1.5f, Mathf.Clamp01(Diamond / 15f)); float time = Mathf.Max(timeCoin, timeDiamond); ManaReso.Get("Da_CoinLab").CreateTweenNumber(0, Coin, time, false, true, Curve.EaseOutQuad); ManaReso.Get("Da_ScoreLab").CreateTweenNumber(0, Score, timeScore, false, true, Curve.EaseOutQuad); ManaReso.Get("Da_DiamondLab").CreateTweenNumber(0, Diamond, time, false, true, Curve.EaseOutQuad); #endregion #region 花 TweenRoot tween; if (FlowerFlag) { tween = ManaReso.Get("Da_CoinLab").GetTweenNumber(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_FlowerGroup").TweenReForScale(); } ); } #endregion #region 按钮 if (FlowerFlag) { tween = ManaReso.Get("Da_FlowerGroup").GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_GetAward").TweenReForCG(); } ); } else { tween = ManaReso.Get("Da_CoinLab").GetTweenNumber(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_GetAward").TweenReForCG(); } ); } if (ManaTutorial.TutorialA) { tween = ManaReso.Get("Da_GetAward").GetTweenCG(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { Tutorial.HightScreen(ManaReso.Get("Da_Arrow0"), ManaReso.Get("Da_Arrow1"), ManaReso.Get("Da_GetAward")); } ); } ManaReso.AddButtonEventOnetime ( "Da_GetAward", () => { ManaReso.Get("Da_VGroup").GetComponent().enabled = true; } ); #endregion #region 得分 if (Rate == 0) { tween = ManaReso.Get("Da_Star1").GetTweenScale(); } else if (Rate == 1) { tween = ManaReso.Get("Da_Star2").GetTweenScale(); } else if (Rate == 2) { tween = ManaReso.Get("Da_Star3").GetTweenScale(); } tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_ScoreTit").TweenReForFont(); } ); tween = ManaReso.Get("Da_ScoreTit").GetTweenFont(); tween.InOrigin = true; tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_ScoreLab").TweenReForNumber(); } ); #endregion #region 五角星 tween = ManaReso.Get("Da_Star3").GetTweenScale(); tween.InOrigin = true; tween = ManaReso.Get("Da_Star2").GetTweenScale(); tween.InOrigin = true; tween = ManaReso.Get("Da_Star1").GetTweenScale(); tween.InOrigin = true; tween = ManaReso.Get("Da_Info").GetTweenCG(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_Star1").TweenReForScale(); ManaReso.SetActive("Da_HGroup1", true); } ); if (Rate == 0) { ManaReso.SetActive("Da_Star2", false); ManaReso.SetActive("Da_Star3", false); } else if (Rate == 1) { ManaReso.SetActive("Da_Star2", true); ManaReso.SetActive("Da_Star3", false); tween = ManaReso.Get("Da_Star1").GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_Star2").TweenReForScale(); } ); } else if (Rate == 2) { ManaReso.SetActive("Da_Star2", true); ManaReso.SetActive("Da_Star3", true); tween = ManaReso.Get("Da_Star1").GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_Star2").TweenReForScale(); } ); tween = ManaReso.Get("Da_Star2").GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_Star3").TweenReForScale(); } ); } #endregion #region 金币钻石 tween = ManaReso.Get("Da_ScoreLab").GetTweenNumber(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_CoinGroup").TweenReForScale(); if (DiamondFlag) { ManaReso.Get("Da_DiamondGroup").TweenReForScale(); } } ); tween = ManaReso.Get("Da_CoinGroup").GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_CoinLab").TweenReForNumber(); } ); if (DiamondFlag) { tween = ManaReso.Get("Da_DiamondGroup").GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.Get("Da_DiamondLab").TweenReForNumber(); } ); } #endregion #endregion } public Award(XmlAttributeCollection attribute) { Flower.CoinFml = attribute[8].Value; DropGold.CoinFml = attribute[7].Value; Star.CD = float.Parse(attribute[9].Value); Star.Time = float.Parse(attribute[11].Value); string[] strings = attribute[10].Value.Split(','); ManaGarden.MinStarTime = float.Parse(strings[0]); ManaGarden.MaxStarTime = float.Parse(strings[1]); ManaGarden.StarTimer = Mathf.Lerp(ManaGarden.MinStarTime, ManaGarden.MaxStarTime, Random.Range(0f, 1f)); CoinFml = attribute[1].Value; FlowerFml = attribute[4].Value; DiamondFml = attribute[3].Value; strings = attribute[2].Value.Split(','); DiamondMin = int.Parse(strings[0]); DiamondMax = int.Parse(strings[1]); strings = attribute[5].Value.Split(','); Odds = new List() { float.Parse(strings[0]), float.Parse(strings[1]), float.Parse(strings[2]), }; strings = attribute[6].Value.Split(','); Standard = new List() { float.Parse(strings[0]), float.Parse(strings[1]), float.Parse(strings[2]), }; } } public class ManaMiniGame : Regist { #region 变量 public static int Score { get { return Score_; } set { Score_ = value; ManaReso.SetText("D_ScoreLab", ScoreLab + Score_); } } public static bool Game { get { return Game_; } set { Game_ = value; if (Game_) { ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1")); } else { ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab0")); } } } public static bool Pause { get { return Pause_; } set { Pause_ = value; if (Game) { if (Pause_) { ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab2")); } else { ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1")); } } else if (Prepare) { if (Pause_) { PrepareLab.GetStreamScale().Pause(); } else { PrepareLab.GetStreamScale().Resume(); } } } } public static bool Panalty { get { return Panalty_; } set { Panalty_ = value; if (Game) { if (Panalty_) { ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab3")); } else { ManaReso.SetText("D_StatusLab", Language.GetStr("UI", "D_StatusLab1")); } } } } public static float GameTimer { get { return GameTimer_; } set { GameTimer_ = value; TimerLab.text = (GameTime-GameTimer_).ToString("0.0"); TimerBk.fillAmount = GameTimer_/GameTime; TimerBk.material.SetFloat("_Fill", TimerBk.fillAmount); } } private static int Score_; private static bool Game_; private static bool Pause_; private static bool Panalty_; private static float GameTimer_; public static Text TimerLab; public static Text PrepareLab; public static Image TimerBk; public static Award Award; public static Transform D_Grid; public static Transform D_Timer; public static Transform D_Begin; public static Transform D_Status1; public static Transform D_Status2; public static Transform D_Status3; public static Transform D_Operate1; public static Transform D_Operate2; public static Transform D_Operate3; public static Transform CorrectBtnC; public static List IndexList = new List(); public static List FlowerIDListC = new List(); public static List DropList = new List(); public static List OpList = new List(); public static List IdleList = new List(); public static List FadeList = new List(); public static Dictionary FlowerDic = new Dictionary(); public static int MiniGameIndex; public static string ScoreLab; public static bool GameA; public static bool GameB; public static bool GameC; public static bool Prepare; public static bool FlowerLock; public static bool TutorialLock = true; public static bool DropDiamond; public static float OpTimer; public static float FadeTimer; public static float GoldTimer; public static float PanaltyTimer; public static float PrepareTimer; public static float DiamondTimer; public static float OpTime = 1.5f; public static float FadeTime = 2f; public static float GameTime = 45f; public static float PanaltyTime = 1f; public static float NewOpTime; public static float NewFadeTime; #endregion private void FixedUpdate() { if (Pause) { return; } if (Game) { GameThreadA(); GameThreadB(); GameThreadC(); } if (Prepare) { PrepareThread(); } } private void GameThreadA() { if (!GameA) { return; } GameTimer += Time.fixedDeltaTime; if (GameTimer >= GameTime) { GameOver(); return; } if (Panalty) { PanaltyTimer -= Time.fixedDeltaTime; if (PanaltyTimer <= 0) { Panalty = false; } } if (IdleList.Count > 0) { OpTimer -= Time.fixedDeltaTime; if (OpTimer <= 0) { NewOpTime -= NewOpTime * 0.03f; OpTimer = NewOpTime; CreateOperate(); } } BonusThread(); } private void GameThreadB() { if (!GameB) { return; } GameTimer += Time.fixedDeltaTime; if (GameTimer >= GameTime) { GameOver(); return; } if (Panalty) { PanaltyTimer -= Time.fixedDeltaTime; if (PanaltyTimer <= 0) { Panalty = false; } } if (FadeList.Count < 6) { FadeTimer -= Time.fixedDeltaTime; if (FadeTimer <= 0) { FadeTimer = NewFadeTime; Fade(); } } BonusThread(); } private void GameThreadC() { if (!GameC) { return; } GameTimer += Time.fixedDeltaTime; if (GameTimer >= GameTime) { GameOver(); return; } if (Panalty) { PanaltyTimer -= Time.fixedDeltaTime; if (PanaltyTimer <= 0) { Panalty = false; } } BonusThread(); } private void BonusThread() { GoldTimer -= Time.fixedDeltaTime; if (GoldTimer < 0) { GoldTimer = Random.Range(3f, 6f); DropList.Add(ManaReso.GetDrop(ObjType.DropGold)); } if (DropDiamond) { DiamondTimer -= Time.fixedDeltaTime; if (DiamondTimer < 0) { DropDiamond = false; DropList.Add(ManaReso.GetDrop(ObjType.DropDiamond)); } } } private void PrepareThread() { PrepareTimer -= Time.fixedDeltaTime; if (PrepareTimer <= 0) { Prepare = false; GameBegin(); } } public override void RegistValueA() { Award = new Award(ManaData.GetAwardConfig()); MiniGameIndex = ManaData.GetPlayerInt("MiniGameIndex"); } public override void RegistReference() { D_Grid = ManaReso.Get("D_Grid"); D_Begin = ManaReso.Get("D_Begin"); D_Timer = ManaReso.Get("D_Timer"); D_Status1 = ManaReso.Get("D_Status1"); D_Status2 = ManaReso.Get("D_Status2"); D_Status3 = ManaReso.Get("D_Status3"); D_Operate1 = ManaReso.Get("D_Operate1"); D_Operate2 = ManaReso.Get("D_Operate2"); D_Operate3 = ManaReso.Get("D_Operate3"); TimerLab = ManaReso.Get("D_TimerLab"); PrepareLab = ManaReso.Get("D_PrepareLab"); TimerBk = ManaReso.Get("D_TimerIcon"); } public static void OperateC(int id, int btnIndex) { if (!Game) { return; } if (Panalty) { return; } if (FlowerIDListC[0] == id) { Flower flower = IdleList.Find(tempFlower => { return tempFlower.ID == id; }); ManaReso.GetHudText("+50", Color.white, 90, flower.ChildDic["ScorePosTra"], ManaReso.Get("D_HudParent"), true); Score += 50; flower.PlayFlashLight(); ManaAudio.PlayClip(Clip.BtnClip); RoundEndC(); } else { Panalty = true; PanaltyTimer = PanaltyTime; ManaReso.Get("D_FlowerIcon" + btnIndex).TweenForGra(); ManaReso.Get("D_FlowerBtn" + btnIndex).Shake(0.5f, 3, new Vector3(20f, 0, 0), Curve.EaseOutQuad); ManaAudio.PlayClip(Clip.ErrorClip); } } public static void OperateB(int index, int slotIndex) { if (Panalty || !FadeList.Valid()) { return; } if (IndexList.Count == 0) { return; } if (slotIndex == IndexList[0]) { int uiIndex = IndexMap(IndexList[0]); ManaReso.Get("D_FlowerBtn" + uiIndex).material = Lib.GrayMat; ManaReso.Get