using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using Blue; public class ShowHide_Toggle : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IController { public List SpriteList; public Image mImage; public bool isRoomMain; private Toggle toggle; private IQueueSystem mQueueSystem; void Awake() { toggle = GetComponent(); toggle.onValueChanged.AddListener(ShowHideLevel3); mQueueSystem = this.GetService(); mQueueSystem.Level3QueueCount.Register(mQueueSystemCountNotNull).UnRegisterWhenGameObjectDestroyed(gameObject); } private void OnEnable() { Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}"); if(isRoomMain) { bool state = false; foreach (var item in mQueueSystem.Level3List) { state = item.activeSelf; } toggle.isOn = state; isShow = toggle.isOn; ShowHideLevel3(state); } else { toggle.isOn = true; isShow = toggle.isOn; ShowHideLevel3(true); } } public void OnPointerEnter(PointerEventData eventData) { if(isShow) mImage.sprite = SpriteList[2]; else mImage.sprite = SpriteList[3]; } public void OnPointerExit(PointerEventData eventData) { if(isShow) mImage.sprite = SpriteList[0]; else mImage.sprite = SpriteList[1]; } private void mQueueSystemCountNotNull(int newCount) { Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}"); } private bool isShow; private void ShowHideLevel3(bool on) { Debug.LogError("Level3Queue:" + mQueueSystem.Level3List.Count); if (on) mImage.sprite = SpriteList[2]; else mImage.sprite = SpriteList[3]; isShow =on; foreach (var go in mQueueSystem.Level3List) { go.SetActive(on); } } }