using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.UI;
namespace UnityEngine.Perception.GroundTruth
{
///
/// Interface that should be defined by a class that wants to be able to provide a image to the overlay
/// panel.
///
public interface IOverlayPanelProvider
{
///
/// The image to the overlay panel.
///
Texture overlayImage { get; }
///
/// The label of the overlay panel.
///
string label { get; }
}
///
/// Some labeler's result in a full screen image per frame. The overlay panel controls which of these labeler's image
/// is currently shown.
///
public class OverlayPanel : MonoBehaviour
{
internal PerceptionCamera perceptionCamera { get; set; }
bool m_Enabled;
GUIStyle m_LabelStyle;
GUIStyle m_SliderStyle;
GUIStyle m_SelectorToggleStyle;
GUIStyle m_WindowStyle;
float m_SegmentTransparency = 0.8f;
float m_BackgroundTransparency;
GameObject m_SegCanvas;
GameObject m_SegVisual;
RawImage m_OverlayImage;
int m_CachedHeight;
int m_CachedWidth;
bool m_ShowPopup = false;
Texture2D m_NormalDropDownTexture;
Texture2D m_HoverDropDownTexture;
void SetEnabled(bool isEnabled)
{
if (isEnabled == m_Enabled) return;
m_Enabled = isEnabled;
m_SegCanvas.SetActive(isEnabled);
foreach (var p in perceptionCamera.labelers)
{
if (p is IOverlayPanelProvider)
{
p.visualizationEnabled = isEnabled;
}
}
// Clear out the handle to the cached overlay texture if we are not isEnabled
if (!isEnabled)
m_OverlayImage.texture = null;
}
void SetupVisualizationElements()
{
m_Enabled = true;
m_SegmentTransparency = 0.8f;
m_BackgroundTransparency = 0.0f;
m_SegVisual = GameObject.Instantiate(Resources.Load("SegmentTexture"));
m_OverlayImage = m_SegVisual.GetComponent();
m_OverlayImage.material.SetFloat("_SegmentTransparency", m_SegmentTransparency);
m_OverlayImage.material.SetFloat("_BackTransparency", m_BackgroundTransparency);
if (m_SegVisual.transform is RectTransform rt)
{
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Screen.width);
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Screen.height);
}
if (m_SegCanvas == null)
{
m_SegCanvas = new GameObject("overlay_canvas");
m_SegCanvas.AddComponent();
var canvas = m_SegCanvas.AddComponent