unity-atoms/Source/AtomicUI/UIContainer.cs
Jeff Campbell e5f6659eda Removed unused namepaces
* Removed unused namespaces across all files in Unity.Atoms assembly.
* Removed unused namspaces in runtime and Test assembly code.
2019-04-07 11:15:23 +02:00

56 lines
1.5 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace UnityAtoms.UI
{
public class UIContainer : MonoBehaviour, IGameEventListener<string>
{
[SerializeField]
private StringVariable UIStateVariable = null;
[SerializeField]
private List<StringConstant> 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<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()
{
if (UIStateVariable.Changed != null)
{
UIStateVariable.Changed.RegisterListener(this);
}
}
private void OnDestroy()
{
if (UIStateVariable.Changed != null)
{
UIStateVariable.Changed.UnregisterListener(this);
}
}
}
}