using System.Collections.Generic; using UnityEngine; namespace UnityAtoms.UI { public class UIContainer : MonoBehaviour, IGameEventListener { [SerializeField] private StringVariable UIStateVariable = null; [SerializeField] private List VisibleForStates = null; void Start() { StateNameChanged(UIStateVariable.Value); } public void OnEventRaised(string stateName) { StateNameChanged(stateName); } private void StateNameChanged(string stateName) { if (VisibleForStates.Exists((state) => state.Value == stateName)) { GetComponent().alpha = 1f; GetComponent().blocksRaycasts = true; GetComponent().interactable = true; } else { GetComponent().alpha = 0f; GetComponent().blocksRaycasts = false; GetComponent().interactable = false; } } private void Awake() { if (UIStateVariable.Changed != null) { UIStateVariable.Changed.RegisterListener(this); } } private void OnDestroy() { if (UIStateVariable.Changed != null) { UIStateVariable.Changed.UnregisterListener(this); } } } }