123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- 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 : MonoBehaviour
- {
- #region 变量
- public static int MyFlowerSpec;
- public static int MyFlowerRegu;
- public static int TotalFlowerSpec;
- public static int TotalFlowerRegu;
- public static int SeleId;
- public static Flower SeleFlower;
- public static Transform SeleFlowerTra;
- public static List<Flower> PlantList;
- public static List<Transform> FlowerTraList;
- public static Dictionary<int, FlowerInfo> FlowerDic;
- #endregion
- private void Awake()
- {
- Initializer.RegistValue += RegistValue;
- PlantList = new List<Flower>();
- FlowerDic = new Dictionary<int, FlowerInfo>();
- ManaReso.Get("Garden", Folder.Object, true, transform, true).AddComponent<Garden>();
- #region 生成FlowerItem
- List<XmlAttributeCollection> attributesList = Data.GetFlowerConfig();
- for (int i = 0; i < attributesList.Count; i++)
- {
- FlowerInfo flowerInfo = new FlowerInfo(attributesList[i]);
- if (flowerInfo.Special)
- {
- TotalFlowerSpec++;
- }
- else
- {
- TotalFlowerRegu++;
- }
- FlowerDic.Add(flowerInfo.Id, flowerInfo);
- }
- #endregion
- #region 得到土堆
- FlowerTraList = new List<Transform>()
- {
- 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"),
- };
- #endregion
- }
- private static void RegistValue()
- {
- SeleId = 1;
- }
- public static void SetFlowerCard(int id)
- {
- SeleId = id;
- FlowerInfo flowerInfo = FlowerDic[id];
- ManaReso.SetText("H_Lab", flowerInfo.Name);
- Image image = ManaReso.Get<Image>("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 UpdateCollectStatus()
- {
- int myTotalFlower = MyFlowerSpec + MyFlowerRegu;
- ManaReso.SetText("F_FlowerLab", myTotalFlower.ToString());
- ManaReso.SetText("G_CollectLab1", string.Format("{0}/{1}", myTotalFlower, TotalFlowerRegu + TotalFlowerSpec));
- }
-
- public static void RetriveFlower()
- {
- ManaReso.Save(SeleFlower);
- PlantList.Remove(SeleFlower);
- FlowerInfo flowerInfo = FlowerDic[SeleFlower.Id];
- flowerInfo.Plant = false;
- SeleFlower.PosTra.SetCollider(true);
- }
- public static void RetriveFlowerAll()
- {
- for (int i = 0; i < PlantList.Count; i++)
- {
- ManaReso.Save(PlantList[i]);
-
- PlantList[i].PosTra.SetCollider(true);
- PlantList.RemoveAt(i--);
- }
- foreach (var kv in FlowerDic)
- {
- kv.Value.Plant = false;
- }
- }
- public static void PlaceFlower()
- {
- FlowerInfo flowerInfo = FlowerDic[SeleId];
- if (flowerInfo.Plant)
- {
- ManaMessage.Show("已经种植过了", 1);
- }
- else
- {
- flowerInfo.Plant = true;
- Flower flower = ManaReso.GetFlower(SeleId, true, SeleFlowerTra);
- PlantList.Add(flower);
- }
- } //FlowerCard种植
- public static void PlaceFlower(int id)
- {
- Transform tra = null;
- for (int i = 0; i < FlowerTraList.Count; i++)
- {
- if (FlowerTraList[i].childCount == 0)
- {
- tra = FlowerTraList[i];
- break;
- }
- }
- if (tra == null)
- {
- ManaMessage.Show("已经没有空地了", 1);
- }
- else
- {
- FlowerInfo flowerInfo = FlowerDic[id];
- if (flowerInfo.Plant)
- {
- ManaMessage.Show("已经种植过了", 1);
- }
- else
- {
- flowerInfo.Plant = true;
- Flower flower = ManaReso.GetFlower(id, true, tra);
- flower.Id = id;
- flower.PosTra = tra;
- PlantList.Add(flower);
- tra.SetCollider(false); //空地Collider
- }
- }
- }
- public static void PlaceFlower(int id, Transform tra)
- {
- FlowerInfo flowerInfo = FlowerDic[id];
- flowerInfo.Plant = true;
- Flower flower = ManaReso.GetFlower(id, true, tra);
- PlantList.Add(flower);
- } //读存档时调用
- }
|