Example #1
0
    /// @note Each scene load causes an OnDestroy of the current SDK, followed
    /// by and Awake of a new one.  That should not cause the underlying native
    /// code to hiccup.  Exception: developer may call Application.DontDestroyOnLoad
    /// on the SDK if they want it to survive across scene loads.
    void Awake()
    {
        SVR.AtwAPI.BeginTrace("gvrviewer-awake");
        if (instance == null)
        {
            instance = this;
        }
        if (instance != this)
        {
            Debug.LogError("There must be only one GvrViewer object in a scene.");
            UnityEngine.Object.DestroyImmediate(this);
            return;
        }
#if UNITY_IOS
        Application.targetFrameRate = 60;
#endif
        // Prevent the screen from dimming / sleeping
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        GvrViewerInternal.Instance.StereoScreenScale = StereoScreenScale;

        // Set up stereo pre- and post-render stages only for:
        // - Unity without the GVR native integration
        // - In-editor emulator when the current platform is Android or iOS.
        //   Since GVR is the only valid VR SDK on Android or iOS, this prevents it from
        //   interfering with VR SDKs on other platforms.
#if !UNITY_HAS_GOOGLEVR || (UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS))
        //AddPrePostRenderStages();
#endif  // !UNITY_HAS_GOOGLEVR || UNITY_EDITOR

        SVR.AtwAPI.BeginTrace("1");
        InitDevice();
        SVR.AtwAPI.EndTrace();
        //if(stereoScreen == null)
        SVR.AtwAPI.BeginTrace("2");
        stereoScreen = device.CreateStereoScreen();
        SVR.AtwAPI.EndTrace();

        Svr.SvrLog.Log("GvrViewer Awake Resume");
        SVR.AtwAPI.EndTrace();

        Application.lowMemory += OnLowMemory;
    }
 /// Presents the #StereoScreen to the device for distortion correction and display.
 /// @note This function is only used if #DistortionCorrection is set to _Native_,
 /// and it only has an effect if the device supports it.
 public void PostRender(StereoScreen stereoScreen)
 {
     device.PostRender(stereoScreen);
 }