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 Config 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 static string FlowerIDRateFml; public static string FlowerAmtRateFml; 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(Manager.Level, 1, 9999).ToString()); Coin = (int)(Coin * (1 + Manager.SkillPlus) + BonusCoin); Coin = (int) Mathf.Clamp(Coin, 1, Mathf.Infinity); ResourceManager.Get(PrefabLabel.Da_CoinLab).text = Coin.ToString(); ResourceManager.Get(PrefabLabel.Da_CoinLab).Resize(true, false); ResourceManager.Get(PrefabLabel.Da_CoinGroup).enabled = true; ResourceManager.SetActive(PrefabLabel.Da_CoinLab, true); Manager.AddCoin(Coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.MiniGame); sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), TransferLabel.CoinSprite, Coin); #endregion #region Diamond float diamondRate = (float)Auxiliary.FmlParse(DiamondFml, "l", Mathf.Clamp(Manager.Level, 1, 1000).ToString()); if (Random.Range(0, 1f) <= diamondRate) { DiamondFlag = true; Diamond = (int)(Mathf.Lerp(DiamondMin, DiamondMax, Random.Range(0, 1f)) + BonusDiamond); ResourceManager.Get(PrefabLabel.Da_DiamondLab).text = Diamond.ToString(); ResourceManager.Get(PrefabLabel.Da_DiamondLab).Resize(true, false); ResourceManager.Get(PrefabLabel.Da_DiamondGroup).enabled = true; ResourceManager.SetActive(PrefabLabel.Da_DiamondLab, true); Manager.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.MiniGame); ResourceManager.SetActive(PrefabLabel.Da_Diamond, true); sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), TransferLabel.DiamondSprite, Diamond); } else { if (BonusDiamond > 0) { DiamondFlag = true; Diamond = BonusDiamond; ResourceManager.Get(PrefabLabel.Da_DiamondLab).text = Diamond.ToString(); ResourceManager.Get(PrefabLabel.Da_DiamondLab).Resize(true, false); ResourceManager.Get(PrefabLabel.Da_DiamondGroup).enabled = true; ResourceManager.SetActive(PrefabLabel.Da_DiamondLab, true); Manager.AddDiamond(Diamond, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.MiniGame); ResourceManager.SetActive(PrefabLabel.Da_Diamond, true); sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), TransferLabel.DiamondSprite, Diamond); } else { Diamond = 0; } } #endregion #region Flower if (TutorialManager.NewplayerTutorial) { FlowerFlag = true; FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[1]; ResourceManager.SetActive(PrefabLabel.Da_FlowerIcon, true); ResourceManager.Get(PrefabLabel.Da_FlowerIcon).sprite = flowerInfo.Icon; ResourceManager.Get(PrefabLabel.Da_FlowerIcon).Resize(true, 0.25f, 0.25f); ResourceManager.SetText(PrefabLabel.Da_FlowerLab, flowerInfo.Name); sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), TransferLabel.FlowerSprite, flowerInfo.Name); } else { if (!FlowerLock) { FlowerFlag = true; if (Random.Range(0, 1f) <= Odds[Rate]) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[FlowerID]; flowerInfo.Add(); ResourceManager.SetActive(PrefabLabel.Da_Flower, true); ResourceManager.Get(PrefabLabel.Da_FlowerIcon).sprite = flowerInfo.Icon; ResourceManager.Get(PrefabLabel.Da_FlowerIcon).Resize(true, 0.25f, 0.25f); ResourceManager.SetText(PrefabLabel.Da_FlowerLab, flowerInfo.Name); sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), TransferLabel.FlowerSprite, flowerInfo.Name); } else { ResourceManager.SetActive(PrefabLabel.Da_Flower, false); ResourceManager.SetText(PrefabLabel.Da_FlowerLab, Language.GetStr("UI", "Da_HigherScore")); } } } #endregion Info = sb.ToString(); BonusCoin = 0; BonusDiamond = 0; #endregion ResourceManager.SetActive(PrefabLabel.Da_Info, true); Auxiliary.Instance.DelayCall ( () => { ResourceManager.Get(PrefabLabel.Da_CoinLab).SetLayoutDirty(); ResourceManager.Get(PrefabLabel.Da_DiamondLab).SetLayoutDirty(); ResourceManager.Get(PrefabLabel.Da_CoinGroup).enabled = false; ResourceManager.Get(PrefabLabel.Da_DiamondGroup).enabled = false; InitializeAnim(); }, 2 ); } public void InitializeAnim() { #region 构造动画 #region Reset ResourceManager.Get(PrefabLabel.Da_Info).TweenForCG(); ResourceManager.SetText(PrefabLabel.Da_Tit, Language.GetStr("UI", "Da_Tit1")); ResourceManager.SetText(PrefabLabel.Da_CoinLab, "0"); ResourceManager.SetText(PrefabLabel.Da_DiamondLab, "0"); ResourceManager.SetActive(PrefabLabel.Da_Lab, false); ResourceManager.SetActive(PrefabLabel.Da_Quit, false); ResourceManager.SetActive(PrefabLabel.Da_Cancel, false); ResourceManager.SetActive(PrefabLabel.Da_CoinLab, false); ResourceManager.SetActive(PrefabLabel.Da_ScoreTit, false); ResourceManager.SetActive(PrefabLabel.Da_ScoreLab, false); ResourceManager.SetActive(PrefabLabel.Da_GetAward, false); ResourceManager.SetActive(PrefabLabel.Da_DiamondLab, false); ResourceManager.SetActive(PrefabLabel.Da_VGroup, true); ResourceManager.SetActive(PrefabLabel.Da_HGroup1, false); ResourceManager.SetActive(PrefabLabel.Da_FlowerGroup, false); ResourceManager.SetActive(PrefabLabel.Da_DiamondGroup, false); if (FlowerFlag) { ResourceManager.SetActive(PrefabLabel.Da_FlowerGroup, true); } if (DiamondFlag) { ResourceManager.SetActive(PrefabLabel.Da_DiamondGroup, true); } Auxiliary.Instance.DelayCall ( () => { ResourceManager.Get(PrefabLabel.Da_VGroup).enabled = false; ResourceManager.SetActive(PrefabLabel.Da_CoinGroup, false); ResourceManager.SetActive(PrefabLabel.Da_FlowerGroup, false); ResourceManager.SetActive(PrefabLabel.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); ResourceManager.Get(PrefabLabel.Da_CoinLab).CreateTweenNumber(0, Coin, time, false, true, Curve.EaseOutQuad); ResourceManager.Get(PrefabLabel.Da_ScoreLab).CreateTweenNumber(0, Score, timeScore, false, true, Curve.EaseOutQuad); ResourceManager.Get(PrefabLabel.Da_DiamondLab).CreateTweenNumber(0, Diamond, time, false, true, Curve.EaseOutQuad); #endregion #region 花 TweenRoot tween; if (FlowerFlag) { tween = ResourceManager.Get(PrefabLabel.Da_CoinLab).GetTweenNumber(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_FlowerGroup).TweenReForScale(); } ); } #endregion #region 按钮 if (FlowerFlag) { tween = ResourceManager.Get(PrefabLabel.Da_FlowerGroup).GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_GetAward).TweenReForCG(); } ); } else { tween = ResourceManager.Get(PrefabLabel.Da_CoinLab).GetTweenNumber(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_GetAward).TweenReForCG(); } ); } if (TutorialManager.NewplayerTutorial) { tween = ResourceManager.Get(PrefabLabel.Da_GetAward).GetTweenCG(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { Tutorial.HightScreen(ResourceManager.Get(PrefabLabel.Da_Arrow0), ResourceManager.Get(PrefabLabel.Da_Arrow1), ResourceManager.Get(PrefabLabel.Da_GetAward)); } ); } ResourceManager.AddButtonEventOnetime ( PrefabLabel.Da_GetAward, () => { ResourceManager.Get(PrefabLabel.Da_VGroup).GetComponent().enabled = true; } ); #endregion #region 得分 if (Rate == 0) { tween = ResourceManager.Get(PrefabLabel.Da_Star1).GetTweenScale(); } else if (Rate == 1) { tween = ResourceManager.Get(PrefabLabel.Da_Star2).GetTweenScale(); } else if (Rate == 2) { tween = ResourceManager.Get(PrefabLabel.Da_Star3).GetTweenScale(); } tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_ScoreTit).TweenReForFont(); } ); tween = ResourceManager.Get(PrefabLabel.Da_ScoreTit).GetTweenFont(); tween.InOrigin = true; tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_ScoreLab).TweenReForNumber(); } ); #endregion #region 五角星 tween = ResourceManager.Get(PrefabLabel.Da_Star3).GetTweenScale(); tween.InOrigin = true; tween = ResourceManager.Get(PrefabLabel.Da_Star2).GetTweenScale(); tween.InOrigin = true; tween = ResourceManager.Get(PrefabLabel.Da_Star1).GetTweenScale(); tween.InOrigin = true; tween = ResourceManager.Get(PrefabLabel.Da_Info).GetTweenCG(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_Star1).TweenReForScale(); ResourceManager.SetActive(PrefabLabel.Da_HGroup1, true); } ); if (Rate == 0) { ResourceManager.SetActive(PrefabLabel.Da_Star2, false); ResourceManager.SetActive(PrefabLabel.Da_Star3, false); } else if (Rate == 1) { ResourceManager.SetActive(PrefabLabel.Da_Star2, true); ResourceManager.SetActive(PrefabLabel.Da_Star3, false); tween = ResourceManager.Get(PrefabLabel.Da_Star1).GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_Star2).TweenReForScale(); } ); } else if (Rate == 2) { ResourceManager.SetActive(PrefabLabel.Da_Star2, true); ResourceManager.SetActive(PrefabLabel.Da_Star3, true); tween = ResourceManager.Get(PrefabLabel.Da_Star1).GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_Star2).TweenReForScale(); } ); tween = ResourceManager.Get(PrefabLabel.Da_Star2).GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_Star3).TweenReForScale(); } ); } #endregion #region 金币钻石 tween = ResourceManager.Get(PrefabLabel.Da_ScoreLab).GetTweenNumber(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_CoinGroup).TweenReForScale(); if (DiamondFlag) { ResourceManager.Get(PrefabLabel.Da_DiamondGroup).TweenReForScale(); } } ); tween = ResourceManager.Get(PrefabLabel.Da_CoinGroup).GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_CoinLab).TweenReForNumber(); } ); if (DiamondFlag) { tween = ResourceManager.Get(PrefabLabel.Da_DiamondGroup).GetTweenScale(); tween.AddEventOnetime ( EventType.ForwardFinish, () => { ResourceManager.Get(PrefabLabel.Da_DiamondLab).TweenReForNumber(); } ); } #endregion #endregion } public Award(XmlAttributeCollection attribute) { Flower.FlowerCoinFml = 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(','); GardenManager.MinStarTime = float.Parse(strings[0]); GardenManager.MaxStarTime = float.Parse(strings[1]); GardenManager.StarTimer = Mathf.Lerp(GardenManager.MinStarTime, GardenManager.MaxStarTime, Random.Range(0f, 1f)); CoinFml = attribute[1].Value; FlowerFml = attribute[4].Value; DiamondFml = attribute[3].Value; FlowerIDRateFml = attribute[12].Value; FlowerAmtRateFml = attribute[13].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 static int SelectAwardFlowerID(List flowerIDs) { for (int i = 0; i < flowerIDs.Count; i++) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[flowerIDs[i]]; float flowerIDRate = (float)Auxiliary.FmlParse(FlowerIDRateFml, "i", flowerIDs[i].ToString()); if (Random.Range(0f, 1f) <= flowerIDRate) { float flowerAmtRate = (float) Auxiliary.FmlParse(FlowerAmtRateFml, "a", flowerInfo.amount.ToString()); if (Random.Range(0f, 1f) <= flowerAmtRate) { return flowerIDs[i]; } } } return flowerIDs.Random(1)[0]; } } public class MiniGameManager : Regist { #region Config public static int Score { get { return Score_; } set { Score_ = value; ResourceManager.SetText(PrefabLabel.D_ScoreLab, ScoreLab + Score_); } } public static bool Game { get { return Game_; } set { Game_ = value; if (Game_) { ResourceManager.SetText(PrefabLabel.D_StatusLab, Language.GetStr("UI", "D_StatusLab1")); } else { ResourceManager.SetText(PrefabLabel.D_StatusLab, Language.GetStr("UI", "D_StatusLab0")); } } } public static bool Pause { get { return Pause_; } set { Pause_ = value; if (Game) { if (Pause_) { ResourceManager.SetText(PrefabLabel.D_StatusLab, Language.GetStr("UI", "D_StatusLab2")); } else { ResourceManager.SetText(PrefabLabel.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_) { ResourceManager.SetText(PrefabLabel.D_StatusLab, Language.GetStr("UI", "D_StatusLab3")); } else { ResourceManager.SetText(PrefabLabel.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 Grid; public static Transform Timer; public static Transform Begin; public static Transform PunchGameStatus; public static Transform MemoryGameStatus; public static Transform FindGameStatus; public static Transform PunchGameOperate; public static Transform MemoryGameOperate; public static Transform FindGameOperate; public static Transform FindGameCorrectBtn; public static int MaxFadeAmt = 6; public static List IndexList = new List(); public static List FindGameFlowerIDs = new List(); public static List DropList = new List(); public static List OperateList = 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 PunchGame; public static bool MemoryGame; public static bool FindGame; 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 MinMinigameCD = 180; public static float MaxMinigameCD = 300; public static float OpTime = 1.5f; public static float FadeTime = 2f; public static float GameTime = 45f; public static float PanaltyTime = 1f; private static float PrepareTime = 3; public static float NewOpTime; public static float NewFadeTime; #endregion private void Update() { if (Pause) { return; } if (Game) { PunchGameThread(); MemoryGameThread(); FindGameThread(); } if (Prepare) { PrepareThread(); } } private float OperateDecreaseRate = 0.03f; private void PunchGameThread() { if (!PunchGame) { return; } GameTimer += Time.deltaTime; if (GameTimer >= GameTime) { GameOver(); return; } if (Panalty) { PanaltyTimer -= Time.deltaTime; if (PanaltyTimer <= 0) { Panalty = false; } } if (IdleList.Count > 0) { OpTimer -= Time.deltaTime; if (OpTimer <= 0) { NewOpTime -= NewOpTime * OperateDecreaseRate; OpTimer = NewOpTime; CreateOperate(); } } BonusThread(); } private void MemoryGameThread() { if (!MemoryGame) { return; } GameTimer += Time.deltaTime; if (GameTimer >= GameTime) { GameOver(); return; } if (Panalty) { PanaltyTimer -= Time.deltaTime; if (PanaltyTimer <= 0) { Panalty = false; } } if (FadeList.Count < MaxFadeAmt) { FadeTimer -= Time.deltaTime; if (FadeTimer <= 0) { FadeTimer = NewFadeTime; Fade(); } } BonusThread(); } private void FindGameThread() { if (!FindGame) { return; } GameTimer += Time.deltaTime; if (GameTimer >= GameTime) { GameOver(); return; } if (Panalty) { PanaltyTimer -= Time.deltaTime; if (PanaltyTimer <= 0) { Panalty = false; } } BonusThread(); } private static int DropGoldMinTime = 3; private static int DropGoldMaxTime = 6; private void BonusThread() { GoldTimer -= Time.deltaTime; if (GoldTimer < 0) { GoldTimer = Random.Range(DropGoldMinTime, DropGoldMaxTime); DropList.Add(ResourceManager.GetDrop(ObjType.DropGold)); } if (DropDiamond) { DiamondTimer -= Time.deltaTime; if (DiamondTimer < 0) { DropDiamond = false; DropList.Add(ResourceManager.GetDrop(ObjType.DropDiamond)); } } } private void PrepareThread() { PrepareTimer -= Time.deltaTime; if (PrepareTimer <= 0) { Prepare = false; GameBegin(); } } public override void FirstInit() { Award = new Award(ConfigManager.GetAwardConfig()); MiniGameIndex = ConfigManager.GetPlayerInt("MiniGameIndex"); } public override void RegistReference() { Grid = ResourceManager.Get(PrefabLabel.D_Grid); Begin = ResourceManager.Get(PrefabLabel.D_Begin); Timer = ResourceManager.Get(PrefabLabel.D_Timer); PunchGameStatus = ResourceManager.Get(PrefabLabel.D_Status1); MemoryGameStatus = ResourceManager.Get(PrefabLabel.D_Status2); FindGameStatus = ResourceManager.Get(PrefabLabel.D_Status3); PunchGameOperate = ResourceManager.Get(PrefabLabel.D_Operate1); MemoryGameOperate = ResourceManager.Get(PrefabLabel.D_Operate2); FindGameOperate = ResourceManager.Get(PrefabLabel.D_Operate3); TimerLab = ResourceManager.Get(PrefabLabel.D_TimerLab); PrepareLab = ResourceManager.Get(PrefabLabel.D_PrepareLab); TimerBk = ResourceManager.Get(PrefabLabel.D_TimerIcon); } private static int FindScore = 40; public static void OperateFindGame(int id, int btnIndex) { if (!Game) { return; } if (Panalty) { return; } if (FindGameFlowerIDs[0] == id) { Flower flower = IdleList.Find(tempFlower => { return tempFlower.ID == id; }); ResourceManager.GetHudText($"+{FindScore}", Color.white, 90, flower.ChildDic["ScorePosTra"], ResourceManager.Get(PrefabLabel.D_HudParent), true); Score += FindScore; flower.PlayFlashLight(); AudioManager.PlayClip(Clip.BtnClip); FindGameRoundEnd(); } else { Panalty = true; PanaltyTimer = PanaltyTime; ResourceManager.Get("D_FlowerIcon" + btnIndex).TweenForGra(); ResourceManager.Get("D_FlowerBtn" + btnIndex).Shake(0.5f, 3, new Vector3(20f, 0, 0), Curve.EaseOutQuad); AudioManager.PlayClip(Clip.ErrorClip); } } private static int MemoryScore = 20; private static bool PlayingNewflowerEffect; public static void OperateMemoryGame(int index, int slotIndex) { if (Panalty || !FadeList.Valid()) { return; } if (IndexList.Count == 0) { return; } if (slotIndex == IndexList[0]) { int uiIndex = MemoryGameIndexMap(IndexList[0]); ResourceManager.Get("D_FlowerBtn" + uiIndex).material = Lib.GrayMat; ResourceManager.Get