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; public class ManaGarden : Regist { #region 变量 public static int MyFlower { get { return _MyFlower; } set { _MyFlower = value; 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 TotalFlower { get { return _TotalFlower; } set { _TotalFlower = value; } } 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 _TotalFlower; private static int _TotalFlowerSpec; private static int _TotalFlowerRegu; public static int SeleId; public static Flower SeleFlower; public static Transform SelePosTra; public static List PlantList; public static List PosTraList; public static Dictionary FlowerInfoDic; #endregion private void Awake() { ManaReso.Get("Garden", Folder.Object, true, transform, true).AddScript(); #region 生成FlowerItem PlantList = new List(); FlowerInfoDic = new Dictionary(); List attributesList = Data.GetFlowerConfig(); for (int i = 0; i < attributesList.Count; i++) { FlowerInfo flowerInfo = new FlowerInfo(attributesList[i]); if (flowerInfo.Special) { TotalFlowerSpec++; } else { TotalFlowerRegu++; } FlowerInfoDic.Add(flowerInfo.Id, flowerInfo); } #endregion } public override void RegistValueA() { SeleId = 1; PosTraList = new List() { ManaReso.Get("FlowerTraA1"), ManaReso.Get("FlowerTraA2"), ManaReso.Get("FlowerTraA3"), ManaReso.Get("FlowerTraA4"), ManaReso.Get("FlowerTraA5"), ManaReso.Get("FlowerTraA6"), ManaReso.Get("FlowerTraA7"), ManaReso.Get("FlowerTraA8"), ManaReso.Get("FlowerTraA9"), ManaReso.Get("FlowerTraB1"), ManaReso.Get("FlowerTraB2"), ManaReso.Get("FlowerTraB3"), ManaReso.Get("FlowerTraB4"), ManaReso.Get("FlowerTraB5"), ManaReso.Get("FlowerTraB6"), ManaReso.Get("FlowerTraB7"), ManaReso.Get("FlowerTraB8"), ManaReso.Get("FlowerTraB9"), }; } public static void SetFlowerCard(int id) { SeleId = id; FlowerInfo flowerInfo = FlowerInfoDic[id]; ManaReso.SetText("H_Lab", flowerInfo.Name); Image image = ManaReso.Get("H_Icon2"); image.sprite = flowerInfo.Sprite; Vector2 newSize = flowerInfo.Sprite.rect.size; newSize.x *= 0.65f; newSize.y *= 0.65f; image.rectTransform.sizeDelta = newSize; } public static void RetriveFlower() { ManaReso.Save(SeleFlower); PlantList.Remove(SeleFlower); FlowerInfo flowerInfo = FlowerInfoDic[SeleFlower.Id]; flowerInfo.Plant = false; SeleFlower.ParTra.SetCollider(true); } public static void RetriveFlowerAll() { for (int i = 0; i < PlantList.Count; i++) { ManaReso.Save(PlantList[i]); PlantList[i].ParTra.SetCollider(true); PlantList.RemoveAt(i--); } foreach (var kv in FlowerInfoDic) { kv.Value.Plant = false; } } public static void PlantFlower() { FlowerInfo flowerInfo = FlowerInfoDic[SeleId]; if (flowerInfo.Plant) { ManaDebug.Log("已经种植过了"); } else { flowerInfo.Plant = true; Flower flower = ManaReso.GetFlower(SeleId, true, SelePosTra); PlantList.Add(flower); } } public static void PlantFlower(int id) { Transform posTra = null; for (int i = 0; i < PosTraList.Count; i++) { if (PosTraList[i].childCount == 0) { posTra = PosTraList[i]; break; } } if (posTra == null) { ManaDebug.Log("已经没有空地了"); } else { FlowerInfo flowerInfo = FlowerInfoDic[id]; if (flowerInfo.Plant) { ManaDebug.Log("已经种植过了"); } else { flowerInfo.Plant = true; Flower flower = ManaReso.GetFlower(id, true, posTra); PlantList.Add(flower); posTra.SetCollider(false); } } } public static void PlantFlower(int id, Transform posTra) { FlowerInfo flowerInfo = FlowerInfoDic[id]; flowerInfo.Plant = true; Flower flower = ManaReso.GetFlower(id, true, posTra); PlantList.Add(flower); posTra.SetCollider(false); } }