/**
* Copyright 2019 The Knights Of Unity, created by Pawel Stolarczyk
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace DemoGame.Scripts.Menus
{
///
/// Manages visibility of the gameobject.
///
public class Menu : MonoBehaviour, IMenu
{
#region Fields
///
/// Reference to used to show or hide the gameobject.
///
[SerializeField] private CanvasGroup _canvasGroup = null;
///
/// Button returning from this panel to main menu.
///
[SerializeField] protected Button _backButton = null;
#endregion
#region Properties
///
/// If true, method was called and
/// this panel is visible to the viewer.
///
public bool IsShown { get; protected set; }
#endregion
#region Methods
///
/// Makes this menu visible to the viewer.
///
[ContextMenu("Show")]
public virtual void Show()
{
_canvasGroup.alpha = 1;
_canvasGroup.blocksRaycasts = true;
IsShown = true;
}
///
/// Hides this menu.
///
[ContextMenu("Hide")]
public virtual void Hide()
{
_canvasGroup.alpha = 0;
_canvasGroup.blocksRaycasts = false;
IsShown = false;
}
///
/// Sets the handler for .
///
public virtual void SetBackButtonHandler(Action onBack)
{
_backButton?.onClick.AddListener(() => onBack());
}
#endregion
}
}