//////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2007-2020 , Inc. All Rights Reserved. // //////////////////////////////////////////////////////////////////////////////// using System; using UnityEngine; using GCSeries.Core.Interop; using GCSeries.Core.Sdk; namespace GCSeries.Core { public sealed partial class ZProvider { private sealed class State : IDisposable { private State() { try { // Initialize logging for the plugin. ZPlugin.InitializeLogging(); // Initialize the context. this.Context = new ZContext(); // Attempt to retrieve the display. ZDisplay display = this.Context.DisplayManager.GetDisplay( ZDisplayType.zSpace); // Create and initialize the primary viewport. this.Viewport = this.Context.CreateViewport( (display != null) ? display.Position : Vector2Int.zero); this.IsInitialized = true; } catch { if (Application.isPlaying) { Debug.LogWarning( "Failed to properly initialize the " + "Provider. Reverting to mock tracker-less, " + "monoscopic 3D."); } this.Dispose(); } } ~State() { this.Dispose(); } //////////////////////////////////////////////////////////////////// // Public Static Methods //////////////////////////////////////////////////////////////////// /// /// A reference to the Provider's persistent state. /// public static State Instance { get { if (s_instance == null) { s_instance = new State(); } return s_instance; } } /// /// Shut down and clean up the Provider's persistent state. /// This includes shutting down the state's SDK context. /// public static void ShutDown() { if (s_instance != null) { s_instance.Dispose(); s_instance = null; } } //////////////////////////////////////////////////////////////////// // Public Properties //////////////////////////////////////////////////////////////////// /// /// Gets whether the Provider's persistent state (e.g. SDK /// context) has been properly initialized. /// public bool IsInitialized { get; private set; } = false; /// /// The SDK context. /// public ZContext Context { get; private set; } = null; /// /// The primary viewport for managing the application window's /// position and size as well as its corresponding stereo frustum. /// public ZViewport Viewport { get; private set; } = null; //////////////////////////////////////////////////////////////////// // Public Methods //////////////////////////////////////////////////////////////////// public void Dispose() { this.Viewport?.Dispose(); this.Context?.Dispose(); this.Viewport = null; this.Context = null; this.IsInitialized = false; ZPlugin.ShutDownLogging(); } //////////////////////////////////////////////////////////////////// // Private Members //////////////////////////////////////////////////////////////////// private static State s_instance = null; } } }