2019-04-07 10:03:16 -04:00
|
|
|
using System.Collections.Generic;
|
2019-03-17 18:43:20 -04:00
|
|
|
using UnityEngine;
|
2019-04-07 10:03:16 -04:00
|
|
|
using UnityEngine.Serialization;
|
2019-03-17 18:43:20 -04:00
|
|
|
|
|
|
|
namespace UnityAtoms.UI
|
|
|
|
{
|
2019-05-29 12:52:27 -04:00
|
|
|
[AddComponentMenu("Unity Atoms/UI/Container")]
|
2019-03-17 18:43:20 -04:00
|
|
|
public class UIContainer : MonoBehaviour, IGameEventListener<string>
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
[FormerlySerializedAs("UIStateVariable")]
|
2019-03-17 18:43:20 -04:00
|
|
|
[SerializeField]
|
2019-04-08 10:14:50 -04:00
|
|
|
private StringVariable _UIStateVariable = null;
|
2019-04-07 10:03:16 -04:00
|
|
|
|
|
|
|
[FormerlySerializedAs("VisibleForStates")]
|
2019-03-17 18:43:20 -04:00
|
|
|
[SerializeField]
|
2019-04-08 10:14:50 -04:00
|
|
|
private List<StringConstant> _visibleForStates = null;
|
2019-03-17 18:43:20 -04:00
|
|
|
|
2019-04-07 10:03:16 -04:00
|
|
|
private void Start()
|
2019-03-17 18:43:20 -04:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
StateNameChanged(_UIStateVariable.Value);
|
2019-03-17 18:43:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnEventRaised(string stateName)
|
|
|
|
{
|
|
|
|
StateNameChanged(stateName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StateNameChanged(string stateName)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_visibleForStates.Exists((state) => state.Value == stateName))
|
2019-03-17 18:43:20 -04:00
|
|
|
{
|
|
|
|
GetComponent<CanvasGroup>().alpha = 1f;
|
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = true;
|
|
|
|
GetComponent<CanvasGroup>().interactable = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetComponent<CanvasGroup>().alpha = 0f;
|
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = false;
|
|
|
|
GetComponent<CanvasGroup>().interactable = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_UIStateVariable.Changed != null)
|
2019-03-17 18:43:20 -04:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
_UIStateVariable.Changed.RegisterListener(this);
|
2019-03-17 18:43:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_UIStateVariable.Changed != null)
|
2019-03-17 18:43:20 -04:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
_UIStateVariable.Changed.UnregisterListener(this);
|
2019-03-17 18:43:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|