//======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
using UnityEngine;
using UnityEngine.VR;
///
/// Controls the message displayed as the zed is initialized, and if it becomes disconnected.
/// Needs to be pre-attached to the ZED rig to work; not added in programmatically.
///
/// There are separate text elements for the mono view and the stereo view to account for the
/// difference in display resolutions. 'Mono' elements are displayed in a 'Screen Space - Overlay'
/// canvas, and 'Stereo' elements in a 'Screen Space - Camera' canvas.
///
public class GUIMessage : MonoBehaviour
{
///
/// Text under the loading sign for the mono rig ("Loading...", "Camera is not detected", etc.)
///
private UnityEngine.UI.Text textmono;
///
/// Text under the loading sign for stereo rig's left eye ("Loading...", "Camera is not detected", etc.)
///
private UnityEngine.UI.Text textleft;
///
/// Text under the loading sign for stereo rig's right eye ("Loading...", "Camera is not detected", etc.)
///
private UnityEngine.UI.Text textright;
///
/// Flag set to true when the ZED is finished initializing.
/// Starts a timer to wait for the ZED's textures to be loaded.
///
private bool ready = false;
///
/// Warning container for the mono rig. Contains the text, background, and loading graphic.
///
private GameObject warningmono;
///
/// Warning container for the stereo rig's left eye. Contains the text, background, and loading graphic.
///
private GameObject warningleft;
///
/// Warning container for the stereo rig's right eye. Contains the text, background, and loading graphic.
///
private GameObject warningright;
///
/// Timer used to add a 0.5 second delay between the ZED being initialized and the message disappearing.
/// This is done to let the ZED textures to finish being made.
///
private float timerWarning = 0.0f;
///
/// If true, stops calling most of the logic in Update() which updates the canvas elements.
/// Called once the ZED is ready and all elements have been properly disabled.
///
private bool init = false;
///
/// Timer used to delay clearing the text by 0.2 seconds once the camera is initialized.
///
private float timer;
///
/// Reference to the loading spinner animation for the mono rig.
///
private GameObject imagemono;
///
/// Reference to the loading spinner animation for the stereo rig's left eye.
///
private GameObject imageleft;
///
/// Reference to the loading spinner animation for the stereo rig's right eye.
///
private GameObject imageright;
///
/// Opening status given during the ZED's last attempt to initialize.
/// Used to check if an error has gone on for more than one frame before changing text.
///
private sl.ERROR_CODE oldInitStatus;
///
/// The zed manager.
///
private ZEDManager zedManager;
///
/// Creates canvas(es) and canvas elements depending on whether the ZED rig is mono (ZED_Rig_Mono)
/// or stereo (ZED_Rig_Stereo).
///
private void Awake()
{
zedManager = GetComponent();
oldInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST;
if (!zedManager.IsStereoRig) //Without VR, we use a Screen Space - Overlay canvas.
{
//Instantiate the mono warning prefab and set basic settings for it.
warningmono = Instantiate(Resources.Load("PrefabsUI/Warning") as GameObject, transform);
warningmono.SetActive(true);
warningmono.GetComponent