Slot.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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, bool anim)
  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. if (anim)
  46. {
  47. Flower.PlayAnim();
  48. }
  49. ManaGarden.PlantList.Add(this);
  50. }
  51. public void Retrieve()
  52. {
  53. Collider.enabled = true;
  54. Available = true;
  55. FlowerInfo.Plant = false;
  56. ManaReso.Save(Flower);
  57. ManaGarden.PlantList.Remove(this);
  58. }
  59. }