123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- 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 struct KV<T1,T2>
- {
- public T1 Key;
- public T2 Value;
- public KV(T1 key, T2 value)
- {
- Key = key;
- Value = value;
- }
- }
- public class ManaGarden : Regist
- {
- #region 变量
- 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_;
- }
- }
- 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 AwardValid = true;
- public static float AnimTimer;
- public static float AwardTimer;
- public static FlowerInfo SeleInfo;
- public static List<Slot> SlotList = new List<Slot>();
- public static List<Slot> PlantList = new List<Slot>();
- public static List<ObjType> ElfList = new List<ObjType>();
- public static Dictionary<int, FlowerInfo> FlowerInfoDic = new Dictionary<int, FlowerInfo>();
- #endregion
- public override void Instantiate()
- {
- ManaReso.Get("Garden", Folder.Scene, true, transform, true).AddScript<Garden>();
- #region 生成FlowerItem
- List<XmlAttributeCollection> attributeList = Data.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()
- {
- AnimTimer = Random.Range(0f, 30f);
- AwardTimer = Random.Range(20f, 60f);
- SlotList = new List<Slot>()
- {
- ManaReso.Get("SlotA1").AddScript<Slot>(),
- ManaReso.Get("SlotA2").AddScript<Slot>(),
- ManaReso.Get("SlotA3").AddScript<Slot>(),
- ManaReso.Get("SlotA4").AddScript<Slot>(),
- ManaReso.Get("SlotA5").AddScript<Slot>(),
- ManaReso.Get("SlotA6").AddScript<Slot>(),
- ManaReso.Get("SlotA7").AddScript<Slot>(),
- ManaReso.Get("SlotA8").AddScript<Slot>(),
- ManaReso.Get("SlotA9").AddScript<Slot>(),
- ManaReso.Get("SlotB1").AddScript<Slot>(),
- ManaReso.Get("SlotB2").AddScript<Slot>(),
- ManaReso.Get("SlotB3").AddScript<Slot>(),
- ManaReso.Get("SlotB4").AddScript<Slot>(),
- ManaReso.Get("SlotB5").AddScript<Slot>(),
- ManaReso.Get("SlotB6").AddScript<Slot>(),
- ManaReso.Get("SlotB7").AddScript<Slot>(),
- ManaReso.Get("SlotB8").AddScript<Slot>(),
- ManaReso.Get("SlotB9").AddScript<Slot>(),
- };
- #region 读花朵存档
- List<int> flowerList = Data.GetFlowerList();
- for (int i = 0; i < flowerList.Count; i++)
- {
- FlowerInfoDic[flowerList[i]].Unlock = true;
- }
- List<KV<int, string>> plantList = Data.GetPlantList();
- for (int i = 0; i < plantList.Count; i++)
- {
- PlantFlower(plantList[i].Key, plantList[i].Value);
- }
- #endregion
- }
- public void FixedUpdate()
- {
- if (ManaTutorial.TutorialA)
- {
- return;
- }
- ElfThread();
- AwardThread();
- }
- public void ElfThread()
- {
- AnimTimer -= Time.fixedDeltaTime;
-
- if (AnimTimer < 0)
- {
- AnimTimer = Random.Range(0f, 30f);
-
- if (ElfList.Count > 0 && PlantList.Count > 0)
- {
- PlantList.Random().Flower.PlayAnim(ElfList.Random());
- }
- }
- }
- public void AwardThread()
- {
- if (AwardValid)
- {
- AwardTimer -= Time.fixedDeltaTime;
- if (AwardTimer <= 0)
- {
- AwardTimer = Random.Range(20, 60);
- 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 static void UnlockSlot()
- {
- for (int i = 0; i < SlotList.Count; i++)
- {
- if (SlotList[i].Valid == false)
- {
- ManaData.Slot++;
- SlotList[i].Valid = true;
- SlotList[i].Available = true;
- return;
- }
- }
- ManaDebug.Log("所有土地已解锁");
- }
- public static void ShowFlowerCard(FlowerInfo flowerInfo)
- {
- SeleInfo = flowerInfo;
- ManaReso.Get("H_FlowerCard").TweenForCG();
- ManaLan.Add(ManaReso.Get<Text>("H_Lab"), new LanStr("FlowerName", flowerInfo.ID));
- Image image = ManaReso.Get<Image>("H_Icon2");
- image.sprite = flowerInfo.Icon;
- Vector2 newSize = flowerInfo.Icon.rect.size;
- newSize.x *= 0.65f;
- newSize.y *= 0.65f;
- image.rectTransform.sizeDelta = newSize;
- }
- 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(FlowerInfo flowerInfo)
- {
- if (flowerInfo.Plant)
- {
- 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)
- {
- ManaDebug.Log("已经没有空地了");
- }
- else
- {
- slot.Plant(flowerInfo, true);
- }
- }
- }
- public static void PlantFlower(int id, string slotName)
- {
- Slot slot = ManaReso.Get<Slot>(slotName);
- FlowerInfo flowerInfo = FlowerInfoDic[id];
- slot.Plant(flowerInfo, false);
- }
- }
|