// 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.Reactor.Reactions;
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;
#if INPUT_SYSTEM_PACKAGE
using UnityEngine.InputSystem.UI;
#endif
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable PartialTypeWithSinglePart
namespace Doozy.Runtime.UIManager.Containers
{
///
/// Specialized container that behaves like a tooltip,
/// with parenting, tracking and positioning options.
///
[AddComponentMenu("Doozy/UI/Containers/UITooltip")]
[DisallowMultipleComponent]
public partial class UITooltip : UIContainerComponent
{
#if UNITY_EDITOR
[UnityEditor.MenuItem("GameObject/Doozy/UI/Containers/UITooltip", false, 8)]
private static void CreateComponent(UnityEditor.MenuCommand menuCommand)
{
GameObjectUtils.AddToScene("UITooltip", false, true);
}
#endif
/// Describes where a tooltip can be instantiated under
public enum Parenting
{
/// The parent of the tooltip will be the TooltipCanvas
TooltipsCanvas = 0,
/// The parent of the tooltip will be the RectTransform of UITooltipTrigger that triggered the tooltip
TooltipTrigger = 1,
/// The parent of the tooltip will be the RectTransform of the GameObject that has the given UITagId
UITag = 2
}
/// Describes the how the tooltip behaves when it is shown
public enum Tracking
{
/// The tooltip will be shown at a predefined position and it will stay there until it is hidden
Disabled = 0,
/// The tooltip will follow the pointer until it is hidden
FollowPointer = 1,
/// The tooltip will follow the GameObject of the trigger until it is hidden
FollowTrigger = 2,
/// The tooltip will follow the GameObject of the given UITag until it is hidden
FollowTarget = 3
}
/// Describes where the tooltip should be positioned relative to the tracked target
public enum Positioning
{
TopLeft = 0,
TopCenter = 1,
TopRight = 2,
MiddleLeft = 3,
MiddleCenter = 4,
MiddleRight = 5,
BottomLeft = 6,
BottomCenter = 7,
BottomRight = 8
}
/// Maximum sorting order value for tooltips
public const int k_MaxSortingOrder = 32767;
/// Default tooltip name
public const string k_DefaultTooltipName = "None";
/// Default category used by the UITagId to identify the default Tooltip Canvas
public const string k_DefaultTooltipCanvasUITagCategory = "UITooltip";
/// Default name used by the UITagId to identify the default Tooltip Canvas
public const string k_DefaultTooltipCanvasUITagName = "Canvas";
/// Get all the visible tooltips (returns all tooltips that are either in the isVisible or isShowing state)
public static IEnumerable visibleTooltips =>
database.Where(item => item.isVisible || item.isShowing);
private LayoutElement m_LayoutElement;
/// Reference to the LayoutElement attached to this GameObject
public LayoutElement layoutElement =>
m_LayoutElement
? m_LayoutElement
: m_LayoutElement = GetComponent() ?? gameObject.AddComponent();
/// Internal static reference to the default canvas used to display tooltips
[ClearOnReload]
private static Canvas s_tooltipsCanvas;
///
/// Static reference to the default canvas used to display tooltips (tooltips 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 tooltipsCanvas
{
get
{
if (s_tooltipsCanvas != null) return s_tooltipsCanvas;
//look for UITag
UITag uiTag = UITag.GetTags(k_DefaultTooltipCanvasUITagCategory, k_DefaultTooltipCanvasUITagName).FirstOrDefault();
if (uiTag != null)
{
s_tooltipsCanvas = uiTag.GetComponent