123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 |
- 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<Slot> SlotList = new List<Slot>();
- public static List<Slot> PlantList = new List<Slot>();
- public static List<Star> StarList = new List<Star>();
- public static List<ObjType> ElfList = new List<ObjType>();
- public static List<Transform> PageList = new List<Transform>();
- public static Dictionary<int, FlowerInfo> FlowerInfoDic = new Dictionary<int, FlowerInfo>();
- #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<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().Award = true;
- }
- }
- }
- }
- public override void Instantiate()
- {
- ManaReso.Get("Garden", Folder.Discard, true, transform, true, ObjType.Garden).AddScript<Garden>();
- CreatePage();
- CreatePage();
- #region 生成FlowerItem
- List<XmlAttributeCollection> 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<int> flowerList = ManaData.GetFlowerList();
- for (int i = 0; i < flowerList.Count; i++)
- {
- FlowerInfoDic[flowerList[i]].Unlock = true;
- }
- List<KV<int, int>> 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<Slot>();
-
- if (slot == null)
- {
- slot = tra.GetChild(i).AddScript<Slot>();
- }
- 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<Image>("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<Image>("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<Image>("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<Image>("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<Image>("H_Btn").material = null;
- ManaReso.SetButtonEvent
- (
- "H_Btn",
- () =>
- {
- ManaCenter.Pay
- (
- "",
- flowerInfo.UnlockAmt,
- flowerInfo.UnlockCur,
- () =>
- {
- flowerInfo.Unlock = true;
- Material material = new Material(ManaReso.Get<Image>("H_Icon2").material);
- MaterialUnit materialUnit = new MaterialUnit
- (
- material,
- ManaReso.Get("H_Icon2"),
- new List<string>()
- {
- "_GrayLerp",
- }
- );
- TweenMatFloat tweenMatFloat = materialUnit.CreateTweenMatFloat(1, 0, 1, true, true, Curve.EaseOutQuad, false);
- tweenMatFloat.OnForwardStart = () =>
- {
- materialUnit.Transform.GetComponent<Image>().material = materialUnit.Material;
- };
- tweenMatFloat.OnForwardFinish = () =>
- {
- ManaReso.Get<Image>("H_Icon2").material = null;
- };
- materialUnit.TweenForMatFloat();
- ManaAudio.PlayClip(Clip.CurrentClip);
- ManaReso.Get("H_Icon1").FindChild("UIFlashLight/UIParticle System").GetComponent<UIPartical>().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
|