ShowHide_Toggle.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. using Blue;
  6. public class ShowHide_Toggle : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IController
  7. {
  8. public List<Sprite> SpriteList;
  9. public Image mImage;
  10. private Toggle toggle;
  11. private IQueueSystem mQueueSystem;
  12. void Awake()
  13. {
  14. toggle = GetComponent<Toggle>();
  15. toggle.onValueChanged.AddListener(ShowHideLevel3);
  16. mQueueSystem = this.GetService<IQueueSystem>();
  17. mQueueSystem.Level3QueueCount.Register(mQueueSystemCountNotNull).UnRegisterWhenGameObjectDestroyed(gameObject);
  18. }
  19. private void OnEnable()
  20. {
  21. Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}");
  22. isShow = toggle.isOn;
  23. }
  24. public void OnPointerEnter(PointerEventData eventData)
  25. {
  26. if(isShow)
  27. mImage.sprite = SpriteList[2];
  28. else
  29. mImage.sprite = SpriteList[3];
  30. }
  31. public void OnPointerExit(PointerEventData eventData)
  32. {
  33. if(isShow)
  34. mImage.sprite = SpriteList[0];
  35. else
  36. mImage.sprite = SpriteList[1];
  37. }
  38. private void mQueueSystemCountNotNull(int newCount)
  39. {
  40. Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}");
  41. }
  42. private bool isShow;
  43. private void ShowHideLevel3(bool on)
  44. {
  45. Debug.LogError("Level3Queue:" + mQueueSystem.Level3List.Count);
  46. if (on)
  47. mImage.sprite = SpriteList[2];
  48. else
  49. mImage.sprite = SpriteList[3];
  50. isShow =on;
  51. foreach (var go in mQueueSystem.Level3List)
  52. {
  53. go.SetActive(on);
  54. }
  55. }
  56. }