// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved.
// This code can only be used under the standard Unity Asset Store End User License Agreement
// A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms
using System;
using System.Collections.Generic;
using System.Linq;
using Doozy.Runtime.Common.Attributes;
using Doozy.Runtime.Common.Extensions;
using Doozy.Runtime.Common.Utils;
using Doozy.Runtime.Global;
using Doozy.Runtime.Signals;
using Doozy.Runtime.UIManager.Components;
using Doozy.Runtime.UIManager.Containers.Internal;
using Doozy.Runtime.UIManager.Input;
using Doozy.Runtime.UIManager.ScriptableObjects;
using Doozy.Runtime.UIManager.Triggers;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
// ReSharper disable PartialTypeWithSinglePart
// ReSharper disable MemberCanBePrivate.Global
namespace Doozy.Runtime.UIManager.Containers
{
///
/// Specialized container that behaves like a popup (modal window),
/// with parenting and positioning options.
///
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(Canvas))]
[RequireComponent(typeof(GraphicRaycaster))]
[AddComponentMenu("Doozy/UI/Containers/UIPopup")]
[DisallowMultipleComponent]
public partial class UIPopup : UIContainerComponent
{
#if UNITY_EDITOR
[UnityEditor.MenuItem("GameObject/Doozy/UI/Containers/UIPopup", false, 8)]
private static void CreateComponent(UnityEditor.MenuCommand menuCommand)
{
GameObjectUtils.AddToScene("UIPopup", false, true);
}
#endif
/// Describes where a popup can be instantiated under
public enum Parenting
{
/// The parent of the popup will be the PopupCanvas
PopupsCanvas = 0,
/// The parent of the popup will be the RectTransform of the GameObject that has the given UITagId
UITag = 1
}
/// Maximum sorting order value for popups (it's 1 level lower than popups)
public const int k_MaxSortingOrder = 32766;
/// Default popup name
public const string k_DefaultPopupName = "None";
/// Default category used by the UITagId to identify the default Popup Canvas
public const string k_DefaultPopupCanvasUITagCategory = "UIPopup";
/// Default name used by the UITagId to identify the default Popup Canvas
public const string k_DefaultPopupCanvasUITagName = "Canvas";
/// Default name for the popups queue.
public const string k_DefaultQueueName = "Default";
/// Get all the visible popups (returns all popups that are either in the isVisible or isShowing state)
public static IEnumerable visiblePopups =>
database.Where(item => item.isVisible || item.isShowing);
/// Internal static reference to the default canvas used to display popups
[ClearOnReload]
private static Canvas s_popupsCanvas;
///
/// Static reference to the default canvas used to display popups (popups get parented to this canvas).
/// You can override the default canvas by referencing another canvas (at runtime) to be used as the default canvas.
///
public static Canvas popupsCanvas
{
get
{
if (s_popupsCanvas != null) return s_popupsCanvas;
//look for UITag
UITag uiTag = UITag.GetTags(k_DefaultPopupCanvasUITagCategory, k_DefaultPopupCanvasUITagName).FirstOrDefault();
if (uiTag != null)
{
s_popupsCanvas = uiTag.GetComponent