Slot.cs 1.6 KB

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