namespace UIWidgets
{
using UnityEngine;
using UnityEngine.UI;
///
/// Lightbox.
/// Display modal image.
///
[RequireComponent(typeof(Image))]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
[AddComponentMenu("UI/New UI Widgets/Lightbox")]
public class Lightbox : MonoBehaviour
{
///
/// The modal key.
///
protected int? ModalKey;
///
/// Display specified image.
///
/// Image to display.
/// Modal background sprite.
/// Modal background color.
/// Canvas.
public virtual void Show(
Sprite sprite,
Sprite modalSprite = null,
Color? modalColor = null,
Canvas canvas = null)
{
var image = GetComponent();
image.sprite = sprite;
image.preserveAspect = true;
var parent = (canvas != null) ? canvas.transform as RectTransform : UtilitiesUI.FindTopmostCanvas(gameObject.transform);
if (parent != null)
{
transform.SetParent(parent, false);
}
if (modalColor == null)
{
modalColor = new Color(0, 0, 0, 0.8f);
}
ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close, parent);
transform.SetAsLastSibling();
gameObject.SetActive(true);
}
///
/// Close lightbox.
///
public virtual void Close()
{
gameObject.SetActive(false);
if (ModalKey.HasValue)
{
ModalHelper.Close(ModalKey.Value);
}
}
}
}