ShowHide_Toggle.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. public bool isRoomMain;
  11. private Toggle toggle;
  12. private IQueueSystem mQueueSystem;
  13. void Awake()
  14. {
  15. toggle = GetComponent<Toggle>();
  16. toggle.onValueChanged.AddListener(ShowHideLevel3);
  17. mQueueSystem = this.GetService<IQueueSystem>();
  18. mQueueSystem.Level3QueueCount.Register(mQueueSystemCountNotNull).UnRegisterWhenGameObjectDestroyed(gameObject);
  19. }
  20. private void OnEnable()
  21. {
  22. Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}");
  23. if(isRoomMain)
  24. {
  25. bool state = false;
  26. foreach (var item in mQueueSystem.Level3List)
  27. {
  28. state = item.activeSelf;
  29. }
  30. toggle.isOn = state;
  31. isShow = toggle.isOn;
  32. ShowHideLevel3(state);
  33. }
  34. else
  35. {
  36. toggle.isOn = true;
  37. isShow = toggle.isOn;
  38. ShowHideLevel3(true);
  39. }
  40. }
  41. public void OnPointerEnter(PointerEventData eventData)
  42. {
  43. if(isShow)
  44. mImage.sprite = SpriteList[2];
  45. else
  46. mImage.sprite = SpriteList[3];
  47. }
  48. public void OnPointerExit(PointerEventData eventData)
  49. {
  50. if(isShow)
  51. mImage.sprite = SpriteList[0];
  52. else
  53. mImage.sprite = SpriteList[1];
  54. }
  55. private void mQueueSystemCountNotNull(int newCount)
  56. {
  57. Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}");
  58. }
  59. private bool isShow;
  60. private void ShowHideLevel3(bool on)
  61. {
  62. Debug.LogError("Level3Queue:" + mQueueSystem.Level3List.Count);
  63. if (on)
  64. mImage.sprite = SpriteList[2];
  65. else
  66. mImage.sprite = SpriteList[3];
  67. isShow =on;
  68. foreach (var go in mQueueSystem.Level3List)
  69. {
  70. go.SetActive(on);
  71. }
  72. }
  73. }