Slot.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class Slot : MonoBehaviour
  5. {
  6. #region 变量
  7. public bool Valid
  8. {
  9. get { return _Valid; }
  10. set
  11. {
  12. _Valid = value;
  13. if (_Valid)
  14. {
  15. Icon.SetActive(false);
  16. }
  17. else
  18. {
  19. Icon.SetActive(true);
  20. }
  21. }
  22. }
  23. private bool _Valid;
  24. public int Id;
  25. public bool Available;
  26. public Flower Flower;
  27. public FlowerInfo FlowerInfo;
  28. public GameObject Icon;
  29. public BoxCollider2D Collider;
  30. #endregion
  31. private void Awake()
  32. {
  33. Icon = transform.GetChild(0).gameObject;
  34. Collider = GetComponent<BoxCollider2D>();
  35. }
  36. public void Plant(FlowerInfo flowerInfo)
  37. {
  38. FlowerInfo = flowerInfo;
  39. Id = flowerInfo.Id;
  40. Collider.enabled = false;
  41. Available = false;
  42. FlowerInfo.Slot = this;
  43. FlowerInfo.Plant = true;
  44. Flower = ManaReso.GetFlower(flowerInfo, this, true);
  45. ManaGarden.PlantList.Add(this);
  46. }
  47. public void Retrieve()
  48. {
  49. Collider.enabled = true;
  50. Available = true;
  51. FlowerInfo.Plant = false;
  52. ManaReso.Save(Flower);
  53. ManaGarden.PlantList.Remove(this);
  54. }
  55. }