123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- using System;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- public class ManaGarden : MonoBehaviour
- {
- #region 变量
- public static Flower SelFlower;
- public static Transform SelFlowerTra;
- public static List<Sprite> FlowerIconList;
- public static List<Flower> PlantFlowerList;
- public static List<Transform> FlowerTraList;
- public static Dictionary<ObjType, Text> FlowerItemDic;
- #endregion
- private void Awake()
- {
- ManaReso.Get("Garden", Folder.Object, transform).AddComponent<Garden>();
- }
- public static void UpdateCollectSta()
- {
- ManaReso.SetText("G_Lab", ((FlowerItemDic.Count * 100) / 25f).ToString("0") + '%');
- ManaReso.SetText("G_IconLab", FlowerItemDic.Count + "/35");
- ManaReso.SetText("G_CollectLab", FlowerItemDic.Count + "/25");
- ManaReso.Get<Image>("G_CollectBk2").fillAmount = FlowerItemDic.Count / 25f;
- }
- public static void ShowFlowerCard(Flower flower = null)
- {
- ManaReso.Get("H_FlowerCard").Forward(TweenType.Alpha);
- if (flower != null)
- {
- SelFlower = flower;
- ManaReso.SetActive("H_Prev", false);
- ManaReso.SetActive("H_Next", false);
- ManaReso.SetActive("H_Place", false);
- ManaReso.SetActive("H_Retrieve", true);
- UpdateFlowerIcon(SelFlower.Sprite);
- }
- else
- {
- ManaReso.SetActive("H_Prev", true);
- ManaReso.SetActive("H_Next", true);
- ManaReso.SetActive("H_Place", true);
- ManaReso.SetActive("H_Retrieve", false);
- }
- }
- public static void UpdateFlowerIcon(Sprite sprite)
- {
- ManaReso.SetSprite("H_Icon", sprite);
- string spriteName = sprite.name;
- if (spriteName == "Flower0")
- {
- ManaReso.SetText("H_Lab", "波斯菊");
- }
- else if (spriteName == "Flower1")
- {
- ManaReso.SetText("H_Lab", "牵牛花");
- }
- else if (spriteName == "Flower2")
- {
- ManaReso.SetText("H_Lab", "蒲公英");
- }
- else if (spriteName == "Flower3")
- {
- ManaReso.SetText("H_Lab", "向日葵");
- }
- else if (spriteName == "Flower4")
- {
- ManaReso.SetText("H_Lab", "马蹄莲");
- }
- else if (spriteName == "Flower5")
- {
- ManaReso.SetText("H_Lab", "康乃馨");
- }
- else if (spriteName == "Flower6")
- {
- ManaReso.SetText("H_Lab", "郁金香");
- }
- else if (spriteName == "Flower7")
- {
- ManaReso.SetText("H_Lab", "三色堇");
- }
- else if (spriteName == "Flower8")
- {
- ManaReso.SetText("H_Lab", "铃兰");
- }
- else if (spriteName == "Flower9")
- {
- ManaReso.SetText("H_Lab", "三叶草");
- }
- else if (spriteName == "Flower10")
- {
- ManaReso.SetText("H_Lab", "粉色小花");
- }
- else if (spriteName == "Flower11")
- {
- ManaReso.SetText("H_Lab", "紫色小花");
- }
- else
- {
- throw new Exception();
- }
- }
- public static void SaveFlower()
- {
- ManaReso.Get("H_FlowerCard").Backward(TweenType.Alpha);
- ManaReso.SaveToPool(SelFlower.gameObject);
- SelFlower.PosTra.SetCollider(true);
- PlantFlowerList.Remove(SelFlower);
- bool plantSta = false;
- for (int i = 0; i < PlantFlowerList.Count; i++)
- {
- if (PlantFlowerList[i].Sprite == SelFlower.Sprite)
- {
- plantSta = true;
- break;
- }
- }
- if (!plantSta)
- {
- FlowerItemDic[SelFlower.ObjType].SetActive(false);
- }
- }
- public static void SaveAllFlower()
- {
- for (int i = 0; i < PlantFlowerList.Count; i++)
- {
- ManaReso.SaveToPool(PlantFlowerList[i]);
-
- PlantFlowerList[i].PosTra.SetCollider(true);
- PlantFlowerList.RemoveAt(i);
- i--;
- }
- foreach (var kvp in FlowerItemDic)
- {
- kvp.Value.SetActive(false);
- }
- }
- public static void PlantFlower(ObjType objType)
- {
- bool haveSpace = false;
- for (int i = 0; i < FlowerTraList.Count; i++)
- {
- if (FlowerTraList[i].childCount == 0)
- {
- haveSpace = true;
- Flower flower = ManaReso.GetFlower(true, FlowerTraList[i], objType);
- flower.PosTra = FlowerTraList[i];
- PlantFlowerList.Add(flower);
- FlowerTraList[i].SetCollider(false);
- FlowerItemDic[objType].SetActive(true);
- break;
- }
- }
- if (!haveSpace)
- {
- ManaMessage.Show("没有空地了", 1);
- }
- }
- public static void PlantFlower(Transform postTra, ObjType objType)
- {
- Flower flower = ManaReso.GetFlower(true, postTra, objType);
- flower.PosTra = postTra;
- PlantFlowerList.Add(flower);
- postTra.SetCollider(false);
- FlowerItemDic[objType ].SetActive(true);
- }
- }
|