using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using UnityEngine.EventSystems; using System; using System.Xml; using System.Linq; using System.Collections; using System.Collections.Generic; using Random = UnityEngine.Random; public class ManaGarden : Regist { #region 变量 public static int Slot { get { return Slot_; } set { Slot_ = value; ManaReso.SetText("G_CollectLab2", string.Format("{0}/{1}", Slot_, Page * 9)); } } public static int Page { get { return PageList.Count; } } public static int MyFlower { get { return MyFlower_; } set { MyFlower_ = value; ManaAchieve.UpdateStatus(AchieveType.FlowerAmt, MyFlower_); ManaReso.SetText("F_FlowerLab", string.Format("{0}", MyFlower)); ManaReso.SetText("G_CollectLab1", string.Format("{0}/{1}", MyFlower, TotalFlower)); } } public static int MyFlowerSpec { get { return MyFlowerSpec_; } set { MyFlowerSpec_ = value; MyFlower = MyFlowerSpec_ + MyFlowerRegu_; } } public static int MyFlowerRegu { get { return MyFlowerRegu_; } set { MyFlowerRegu_ = value; MyFlower = MyFlowerSpec_ + MyFlowerRegu_; } } public static int TotalFlowerSpec { get { return TotalFlowerSpec_; } set { TotalFlowerSpec_ = value; TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_; } } public static int TotalFlowerRegu { get { return TotalFlowerRegu_; } set { TotalFlowerRegu_ = value; TotalFlower = TotalFlowerSpec_ + TotalFlowerRegu_; } } public static int Slot_; private static int MyFlower_; private static int MyFlowerSpec_; private static int MyFlowerRegu_; private static int TotalFlowerSpec_; private static int TotalFlowerRegu_; public static int TotalFlower; public static bool MiniLock = true; public static float MinStarTime; public static float MaxStarTime; public static float ElfTimer; public static float StarTimer; public static float AwardTimer; public static FlowerInfo SeleInfo; public static ManaGarden Instance; public static List SlotList = new List(); public static List PlantList = new List(); public static List StarList = new List(); public static List ElfList = new List(); public static List PageList = new List(); public static Dictionary FlowerInfoDic = new Dictionary(); #endregion public void FixedUpdate() { if (ManaTutorial.TutorialA) { return; } ElfThread(); StarThread(); AwardThread(); } public void ElfThread() { ElfTimer -= Time.fixedDeltaTime; if (ElfTimer < 0) { ElfTimer = Random.Range(5f, 30f); if (ElfList.Count > 0 && PlantList.Count > 0) { PlantList.Random().Flower.GetElf(ElfList.Random()); } } } public void StarThread() { if (MiniLock && !ManaCenter.MiniLock && !ManaVisit.InVisit) { StarTimer -= Time.fixedDeltaTime; if (StarTimer < 0) { StarTimer = Mathf.Lerp(MinStarTime, MaxStarTime, Random.Range(0f, 1f)); StarList.Add(ManaReso.GetStar()); } } } public void AwardThread() { if (MiniLock) { AwardTimer -= Time.fixedDeltaTime; if (AwardTimer <= 0) { AwardTimer = Random.Range(5f, 15); List spareList = new List(); for (int i = 0; i < PlantList.Count; i++) { if (PlantList[i].Flower.Award == false) { spareList.Add(PlantList[i].Flower); } } if (spareList.Count > 0) { spareList.Random().Award = true; } } } } public override void Instantiate() { ManaReso.Get("Garden", Folder.Discard, true, transform, true, ObjType.Garden).AddScript(); CreatePage(); CreatePage(); #region 生成FlowerItem List attributeList = ManaData.GetFlowerConfig(); for (int i = 0; i < attributeList.Count; i++) { FlowerInfo flowerInfo = new FlowerInfo(attributeList[i]); if (flowerInfo.Special) { TotalFlowerSpec++; } else { TotalFlowerRegu++; } FlowerInfoDic.Add(flowerInfo.ID_, flowerInfo); } #endregion } public override void RegistValueA() { Instance = this; ElfTimer = Random.Range(5f, 30f); AwardTimer = Random.Range(5f, 15f); UnlockSlot(); #region 读花朵存档 List flowerList = ManaData.GetFlowerList(); for (int i = 0; i < flowerList.Count; i++) { FlowerInfoDic[flowerList[i]].Unlock = true; } List> plantList = ManaData.GetPlantList(); for (int i = 0; i < plantList.Count; i++) { PlantFlower(plantList[i].Key, plantList[i].Value); } #endregion } public static void LockSlot() { for (int i = 0; i < SlotList.Count; i++) { if (SlotList[i].Lock) { Slot--; SlotList[i].Lock = false; SlotList[i].Available = false; return; } } throw new Exception(); } public static void UnlockSlot() { for (int i = 0; i < SlotList.Count; i++) { if (SlotList[i].Lock == false) { Slot++; SlotList[i].Lock = true; SlotList[i].Available = true; if (Slot%9 == 7) { if (Slot/9 + 2 >= Page) { CreatePage(); } } return; } } } public static void CreatePage() { Transform tra = ManaReso.Get("Page", Folder.Scene, false, ManaReso.Get("GardenPage"), false, ObjType.Page); float offset = Page*19.2f; tra.SetLX(offset); Vector3 pos = ManaReso.Get("GardenPage").position; pos.x = -offset; Garden.PagePos.Add(pos); for (int i = 0; i < 9; i++) { Slot slot = tra.GetChild(i).GetComponent(); if (slot == null) { slot = tra.GetChild(i).AddScript(); } slot.Index = SlotList.Count; SlotList.Add(slot); } PageList.Add(tra); } public static void ShowRetrieveCard(FlowerInfo flowerInfo) { SeleInfo = flowerInfo; ManaReso.Get("H_FlowerCard").TweenForCG(); ManaReso.SetText("H_Lab", flowerInfo.Name); Image image = ManaReso.Get("H_Icon2"); image.material = null; image.sprite = flowerInfo.Icon; image.Resize(true, 0.75f, 0.75f); ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab1")); ManaReso.Get("H_Btn").material = null; ManaReso.SetButtonEvent ( "H_Btn", () => { ManaAudio.PlayClip(Clip.BtnClip); ManaReso.Get("H_FlowerCard").TweenBacCG(); RetriveFlower(); } ); } public static void ShowUnlockCard(FlowerInfo flowerInfo) { SeleInfo = flowerInfo; ManaReso.Get("H_FlowerCard").TweenForCG(); ManaReso.SetText("H_Lab", flowerInfo.Name); Image image = ManaReso.Get("H_Icon2"); image.material = Shortcut.GrayMat; image.sprite = flowerInfo.Icon; image.Resize(true, 0.75f, 0.75f); if (flowerInfo.UnlockCur == Current.Free) { ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab2")); ManaReso.Get("H_Btn").material = Shortcut.GrayMat; ManaReso.SetButtonEvent ( "H_Btn", () => { Bubble.Show(null, Language.GetStr("UI", "H_BtnLab3")); } ); } else { ManaReso.SetText("H_BtnLab", Auxiliary.ImageParse(flowerInfo.UnlockCur) + flowerInfo.UnlockAmt); ManaReso.Get("H_Btn").material = null; ManaReso.SetButtonEvent ( "H_Btn", () => { ManaCenter.Pay ( "", flowerInfo.UnlockAmt, flowerInfo.UnlockCur, () => { flowerInfo.Unlock = true; Material material = new Material(ManaReso.Get("H_Icon2").material); MaterialUnit materialUnit = new MaterialUnit ( material, ManaReso.Get("H_Icon2"), new List() { "_GrayLerp", } ); TweenMatFloat tweenMatFloat = materialUnit.CreateTweenMatFloat(1, 0, 1, true, true, Curve.EaseOutQuad, false); tweenMatFloat.OnForwardStart = () => { materialUnit.Transform.GetComponent().material = materialUnit.Material; }; tweenMatFloat.OnForwardFinish = () => { ManaReso.Get("H_Icon2").material = null; }; materialUnit.TweenForMatFloat(); ManaAudio.PlayClip(Clip.CurrentClip); ManaReso.Get("H_Icon1").FindChild("UIFlashLight/UIParticle System").GetComponent().Begin(); ManaReso.SetText("H_BtnLab", Language.GetStr("UI", "H_BtnLab4")); ManaReso.SetButtonEvent ( "H_Btn", () => { PlantFlower(flowerInfo); ManaReso.Get("H_FlowerCard").TweenBacCG(); } ); }, true, false, () => { ManaReso.Get("H_FlowerCard").TweenBacCG(); TweenCG tweenCg = ManaReso.Get("G_Flower").TweenBacCG(); tweenCg.AddEventOnetime ( EventType.BackwardFinish, () => { ManaReso.Get("F_Manage0").TweenForVec(); } ); } ); } ); } } public static void RetriveFlower() { SeleInfo.Slot.Retrieve(); } public static void RetriveFlowerAll() { for (int i = 0; i < PlantList.Count; i++) { PlantList[i--].Retrieve(); } } public static void PlantFlower(int id, int index) { Slot slot = SlotList[index]; FlowerInfo flowerInfo = FlowerInfoDic[id]; slot.Plant(flowerInfo, false); } public static void PlantFlower(FlowerInfo flowerInfo) { Slot slot = null; for (int i = 0; i < SlotList.Count; i++) { if (SlotList[i].Available) { slot = SlotList[i]; break; } } if (slot == null) { Bubble.Show(null, Language.GetStr("Common", "NoValidSlot")); } else { slot.Plant(flowerInfo, true); ManaAudio.PlayClip(Clip.FlowerClip); } } } #region 已测试内容 //一共有3种花卡 回收卡 不能解锁卡 可以解锁卡 //各种卡之间转换时的按钮变化(事件和Text) #endregion