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 static void Reload() { for (int i = 0; i < PageList.Count; i++) { ManaReso.Save(PageList[i]); } for (int i = 0; i < PlantList.Count; i++) { PlantList[i].Retrieve(); } for (int i = 0; i < SlotList.Count; i++) { SlotList[i].Lock = false; SlotList[i].Available = false; DestroyImmediate(SlotList[i]); } foreach (var kv in FlowerInfoDic) { kv.Value.Unlock = false; } Slot = 0; MyFlowerSpec = 0; MyFlowerRegu = 0; ElfList = new List(); SlotList = new List(); PageList = new List(); PlantList = new List(); CreatePage(); CreatePage(); Instance.RegistValueA(); } 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 ShowFlowerCard(FlowerInfo flowerInfo) { SeleInfo = flowerInfo; ManaReso.Get("H_FlowerCard").TweenForCG(); ManaReso.SetText("H_Lab", flowerInfo.Name); Image image = ManaReso.Get("H_Icon2"); image.sprite = flowerInfo.Icon; image.Resize(0.65f, 0.65f); } 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) { if (flowerInfo.Plant) { ManaAudio.PlayClip(Clip.BtnClip); ShowFlowerCard(flowerInfo); } else { 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); } } } }