123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- 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 enum ElfType
- {
- Bee_Red,
- Bee_Blue,
- Bee_White,
- Bee_Purple,
- Bee_Yellow,
- Beetle_Red,
- Beetle_Blue,
- Beetle_White,
- Beetle_Purple,
- Beetle_Yellow,
- Butterfly_Red,
- Butterfly_Blue,
- Butterfly_White,
- Butterfly_Purple,
- Butterfly_Yellow,
- Dragonfly_Red,
- Dragonfly_Blue,
- Dragonfly_White,
- Dragonfly_Purple,
- Dragonfly_Yellow,
- }
- public class GardenManager : Regist
- {
- #region Config
- public static int Slot
- {
- get { return Slot_; }
- set
- {
- Slot_ = value;
- ResourceManager.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;
- AchieveManager.UpdateStatus(AchieveType.FlowerAmt, MyFlower_);
- ResourceManager.SetText("F_FlowerLab", string.Format("{0}", MyFlower));
- ResourceManager.SetText("G_CollectLab1", string.Format("{0}/{1}", MyFlower, TotalFlower));
- if (MyFlower_ >= TutorialManager.MinFlowerForFindGame && Manager.Level >= TutorialManager.FindMinigameTutorialLevel)
- {
- if (TutorialManager.findMinigameTutorial)
- {
- TutorialManager.PlayFindGame();
- }
- }
- }
- }
- 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_;
- public static int DefaultSlot = 1;
- private static int MyFlower_;
- private static int MyFlowerSpec_;
- private static int MyFlowerRegu_;
- private static int TotalFlowerSpec_;
- private static int TotalFlowerRegu_;
- public static int FirstUnlockFlowerID
- {
- get
- {
- foreach (var kv in FlowerInfoDic)
- {
- if (!kv.Value.Unlock)
- {
- return kv.Key;
- }
- }
- return -1;
- }
- }
- public static List<int> UnlockedFlowerIDList
- {
- get
- {
- List<int> unlockedFlowerIDList = new List<int>();
- foreach (var kv in FlowerInfoDic)
- {
- if (kv.Value.Unlock)
- {
- unlockedFlowerIDList.Add(kv.Key);
- }
- }
- return unlockedFlowerIDList;
- }
- }
- public static int TotalFlower;
- public static bool MiniLock = true;
- public static float ElfTimer;
- public static float StarTimer;
- public static float AwardTimer;
- public static Button RetrieveButton;
- public static Text RetrieveButtonLab;
- public static Button PurchaseButton;
- public static Text PurchaseButtonLab;
- public static FlowerInfo SeleInfo;
- public static GardenManager Instance;
- public static List<Slot> SlotList = new List<Slot>();
- public static List<Slot> PlantList = new List<Slot>();
- public static List<Star> StarList = new List<Star>();
- public static List<ElfType> ElfList = new List<ElfType>();
- public static List<Transform> PageList = new List<Transform>();
- public static Dictionary<int, FlowerInfo> FlowerInfoDic = new Dictionary<int, FlowerInfo>();
- public static TweenMatFloat FlowerCardMatTween;
- #endregion
- public void Update()
- {
- if (TutorialManager.NewplayerTutorial || Player.InDressRoom || SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
- {
- return;
- }
- ElfThread();
- StarThread();
- AwardThread();
- }
- public static float MinElfTime = 5;
- public static float MaxElfTime = 30;
- public void ElfThread()
- {
- if (!MiniLock)
- {
- return;
- }
- ElfTimer -= Time.deltaTime;
- if (ElfTimer < 0)
- {
- ElfTimer = Random.Range(MinElfTime, MaxElfTime);
- if (ElfList.Count > 0 && PlantList.Count > 0)
- {
- PlantList.Random()[0].Flower.GetElf(ElfList.Random()[0]);
- }
- }
- }
- public static float MinStarTime;
- public static float MaxStarTime;
- public void StarThread()
- {
- if (MiniLock && !Manager.MiniLock && !VisitManager.InVisit)
- {
- StarTimer -= Time.deltaTime;
- if (StarTimer < 0)
- {
- StarTimer = Mathf.Lerp(MinStarTime, MaxStarTime, Random.Range(0f, 1f));
- StarList.Add(ResourceManager.GetStar());
- }
- }
- }
- public static float MinAwardTime = 5;
- public static float MaxAwardTime = 15;
- public void AwardThread()
- {
- if (MiniLock)
- {
- AwardTimer -= Time.deltaTime;
- if (AwardTimer <= 0)
- {
- AwardTimer = Random.Range(MinAwardTime, MaxAwardTime);
- List<Flower> spareList = new List<Flower>();
- 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()[0].Award = true;
- }
- }
- }
- }
- public override void InstantiatePrefabs()
- {
- ResourceManager.Get(ResourceLabel.Garden, Folder.Scene, true, transform, true, ObjType.Garden).AddScript<Garden>();
- for (int i = 0; i < DefaultPage; i++)
- {
- CreatePage();
- }
- #region 生成FlowerItem
- List<XmlAttributeCollection> attributeList = ConfigManager.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 FirstInit()
- {
- Instance = this;
- ElfTimer = Random.Range(MinElfTime, MaxElfTime);
- AwardTimer = Random.Range(MinAwardTime, MaxAwardTime);
- UnlockSlot();
- for (int i = 0; i < ConfigManager.GetPlayerInt(PlayerConfigLabel.ExtraSlot); i++)
- {
- UnlockSlot();
- }
- #region 读花朵存档
- List<int> flowerIDList = ConfigManager.GetFlowerList();
- for (int i = 0; i < flowerIDList.Count; i++)
- {
- FlowerInfoDic[flowerIDList[i]].Unlock = true;
- }
- List<int> flowerAmountList = ConfigManager.GetIntList(' ', PlayerConfigLabel.FlowerAmtList, null);
- for (int i = 0; i < flowerAmountList.Count; i++)
- {
- FlowerInfoDic[flowerIDList[i]].Amount = flowerAmountList[i];
- }
- List<KV<int, int>> plantList = ConfigManager.GetPlantList();
- for (int i = 0; i < plantList.Count; i++)
- {
- PlantFlower(plantList[i].Key, plantList[i].Value);
- }
- #endregion
- }
- public override void RegistReference()
- {
- RetrieveButton = ResourceManager.Get<Button>("H_Btn");
- RetrieveButtonLab = ResourceManager.Get<Text>("H_BtnLab");
- PurchaseButton = ResourceManager.Get<Button>("H_Btn1");
- PurchaseButtonLab = ResourceManager.Get<Text>("H_BtnLab1");
- }
- public static int DefaultPage = 2;
- public static int CriticalSlotAmt = 7;
- public static int TotalSlotAmtInOnePage = 9;
- 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% TotalSlotAmtInOnePage == CriticalSlotAmt)
- {
- if (Slot/ TotalSlotAmtInOnePage + DefaultPage >= Page)
- {
- CreatePage();
- }
- }
- return;
- }
- }
- }
- private static float PageXOffset = 18.9f;
- public static void CreatePage()
- {
- Transform tra = ResourceManager.Get(ResourceLabel.Page, Folder.Scene, false, ResourceManager.Get("GardenPage"), false, ObjType.Page);
- float offset = Page*PageXOffset;
- tra.SetLX(offset);
- Vector3 pos = ResourceManager.Get("GardenPage").position;
- pos.x = -offset;
-
- Garden.PagePos.Add(pos);
- for (int i = 0; i < TotalSlotAmtInOnePage; i++)
- {
- Slot slot = tra.GetChild(i).GetComponent<Slot>();
-
- if (slot == null)
- {
- slot = tra.GetChild(i).AddScript<Slot>();
- }
- slot.Index = SlotList.Count;
- SlotList.Add(slot);
- }
- PageList.Add(tra);
- }
- public static void ShowPlantCard(FlowerInfo flowerInfo, Slot seleSlot = null)
- {
- ShowFlowerCard(flowerInfo, null, seleSlot);
- RetrieveButton.SetActive(false);
- PurchaseButton.SetActive(true);
- }
- public static void ShowRetrieveCard(FlowerInfo flowerInfo, Slot seleSlot = null)
- {
- ShowFlowerCard(flowerInfo, null, seleSlot);
- RetrieveButton.SetActive(true);
- PurchaseButton.SetActive(true);
- }
- public static void ShowUnlockCard(FlowerInfo flowerInfo, Slot seleSlot = null)
- {
- ShowFlowerCard(flowerInfo, Lib.GrayMat, seleSlot);
- RetrieveButton.SetActive(false);
- PurchaseButton.SetActive(true);
- }
- private static void ShowFlowerCard(FlowerInfo flowerInfo, Material material, Slot seleSlot)
- {
- SetRetrieveBtn(RetrieveButton, RetrieveButtonLab, seleSlot);
- SetPurchaseBtn(flowerInfo, PurchaseButton, PurchaseButtonLab);
- SeleInfo = flowerInfo;
- ResourceManager.Get("H_FlowerCard").TweenForCG();
- ResourceManager.SetText("H_Lab", flowerInfo.Name);
- SetPlantStatus(flowerInfo);
- Image image = ResourceManager.Get<Image>("H_Icon2");
- image.material = material;
- image.sprite = flowerInfo.Icon;
- image.Resize(true, 0.6125f, 0.6125f);
- }
- private static void SetRetrieveBtn(Button button, Text buttonLab, Slot seleSlot = null)
- {
- RetrieveButton = button;
- buttonLab.text = Language.GetStr("UI", "H_BtnLab1");
- button.image.material = null;
- button.onClick.RemoveAllListeners();
- button.onClick.AddListener
- (
- () =>
- {
- AudioManager.PlayClip(Clip.BtnClip);
- RetriveFlower(seleSlot);
- }
- );
- }
- private static void SetPurchaseBtn(FlowerInfo flowerInfo, Button button, Text buttonLab)
- {
- if (flowerInfo.UnlockCur == Current.Free)
- {
- buttonLab.text = Language.GetStr("UI", "H_BtnLab2");
- button.image.material = Lib.GrayMat;
- button.onClick.RemoveAllListeners();
- button.onClick.AddListener
- (
- () =>
- {
- Bubble.Show(null, Language.GetStr("UI", "H_BtnLab3"));
- }
- );
- }
- else
- {
- buttonLab.text = Auxiliary.ImageParse(flowerInfo.UnlockCur) + flowerInfo.UnlockAmt;
- button.image.material = null;
- button.onClick.RemoveAllListeners();
- button.onClick.AddListener
- (
- () =>
- {
- Manager.Pay
- (
- "",
- flowerInfo.UnlockAmt,
- flowerInfo.UnlockCur,
- () =>
- {
- flowerInfo.Add();
- SetPlantStatus(flowerInfo);
- HttpManager.Save();
- PlayFlowerCardMatTween();
- AudioManager.PlayClip(Clip.CurrentClip);
- ResourceManager.Get("H_Icon1").FindChild($"{PrefabLabel.H_UIFlashLight}/{PrefabLabel.H_UIParticleSystem}").GetComponent<UIPartical>().Begin();
- },
- StaticsManager.ItemID.解锁花朵,
- StaticsManager.ConsumeModule.Shop,
- true,
- false,
- () =>
- {
- ResourceManager.Get("H_FlowerCard").TweenBacCG();
- TweenCG tweenCg = ResourceManager.Get("G_Flower").TweenBacCG();
- tweenCg.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- ResourceManager.Get("F_Manage0").TweenForVec();
- }
- );
- }
- );
- }
- );
- }
- }
- private static void SetPlantStatus(FlowerInfo flowerInfo)
- {
- if (flowerInfo.RemainAmount == 0)
- {
- ResourceManager.Get<Button>("H_Icon2").interactable = false;
- ResourceManager.SetActive("H_AmtLab", false);
- ResourceManager.SetActive("H_Desc", false);
- ResourceManager.SetActive("H_Rotate", false);
- }
- else
- {
- ResourceManager.SetActive("H_Desc", true);
- ResourceManager.Get<Button>("H_Icon2").interactable = true;
- ResourceManager.SetActive("H_AmtLab", true);
- ResourceManager.SetText("H_AmtLab", "x" + flowerInfo.RemainAmount);
- ResourceManager.SetActive("H_Rotate", true);
- }
- }
- private static void SetRetrieveStatus(FlowerInfo flowerInfo, Button button)
- {
- if (flowerInfo.PlantAmt == 0)
- button.SetActive(false);
- else
- button.SetActive(true);
- }
- private static void PlayFlowerCardMatTween()
- {
- if (ResourceManager.Get<Image>("H_Icon2").material != Lib.GrayMat)
- {
- return;
- }
- Material material = new Material(ResourceManager.Get<Image>("H_Icon2").material);
- MaterialUnit materialUnit = new MaterialUnit
- (
- material,
- ResourceManager.Get("H_Icon2"),
- new List<string>()
- {
- "_GrayLerp",
- }
- );
- FlowerCardMatTween = materialUnit.CreateTweenMatFloat(1, 0, 1, true, true, Curve.EaseOutQuad, false);
- FlowerCardMatTween.OnForwardStart = () =>
- {
- materialUnit.Transform.GetComponent<Image>().material = materialUnit.Material;
- };
- FlowerCardMatTween.OnForwardFinish = () =>
- {
- ResourceManager.Get<Image>("H_Icon2").material = null;
- };
- materialUnit.TweenForMatFloat();
- }
- public static void RetriveFlower(Slot seleSlot = null)
- {
- if (seleSlot != null && seleSlot.Flower == null)
- seleSlot = null;
- if (seleSlot == null)
- {
- foreach (var slot in PlantList)
- {
- if (slot.Flower.FlowerInfo == SeleInfo)
- {
- seleSlot = slot;
- break;
- }
- }
- }
- seleSlot.Retrieve();
- SetPlantStatus(seleSlot.FlowerInfo);
- SetRetrieveStatus(seleSlot.FlowerInfo, RetrieveButton);
- }
- 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);
- SetPlantStatus(flowerInfo);
- SetRetrieveStatus(flowerInfo, RetrieveButton);
- AudioManager.PlayClip(Clip.FlowerClip);
- }
- }
- public static void RetrieveAllElf()
- {
- for (int i = 0; i < PlantList.Count; i++)
- {
- PlantList[i].Flower.RetrieveElf();
- }
- }
- public static void RetrieveAllStar()
- {
- for (int i = 0; i < StarList.Count; i++)
- {
- ResourceManager.Save(StarList[i]);
- }
- }
- }
|