12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using Blue;
- public class ShowHide_Toggle : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IController
- {
- public List<Sprite> SpriteList;
- public Image mImage;
- public bool isRoomMain;
- private Toggle toggle;
- private IQueueSystem mQueueSystem;
- void Awake()
- {
- toggle = GetComponent<Toggle>();
- toggle.onValueChanged.AddListener(ShowHideLevel3);
- mQueueSystem = this.GetService<IQueueSystem>();
- 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);
- }
- }
- }
|