Exemplo n.º 1
0
 private void Update()
 {
     if (QCARManager.Instance.Initialized)
     {
         if (this.mAndroidUnityPlayer != null)
         {
             this.mAndroidUnityPlayer.Update();
         }
         ScreenOrientation surfaceOrientation = (ScreenOrientation)QCARWrapper.Instance.GetSurfaceOrientation();
         CameraDeviceImpl  instance           = (CameraDeviceImpl)CameraDevice.Instance;
         if (instance.CameraReady && (QCARUnity.IsRendererDirty() || (this.mProjectionOrientation != surfaceOrientation)))
         {
             this.ConfigureVideoBackground(false);
             this.UpdateProjection(surfaceOrientation);
             instance.ResetDirtyFlag();
         }
         this.mClearMaterial.SetPass(0);
         if (((QCARManagerImpl)QCARManager.Instance).Update(this.mProjectionOrientation, this.CameraDeviceMode, ref this.mVideoMode))
         {
             this.UpdateCameraClearFlags();
             foreach (ITrackerEventHandler handler in this.mTrackerEventHandlers)
             {
                 handler.OnTrackablesUpdated();
             }
         }
     }
     else if (QCARRuntimeUtilities.IsPlayMode())
     {
         Debug.LogWarning("Scripts have been recompiled during Play mode, need to restart!");
         QCARWrapper.Create();
         PlayModeEditorUtility.Instance.RestartPlayMode();
     }
 }
Exemplo n.º 2
0
    // Updates the scene with new tracking data. Calls registered
    // ITrackerEventHandlers
    void Update()
    {
        if (QCARManager.Instance.Initialized)
        {
            // Get the current orientation of the surface:
            ScreenOrientation surfaceOrientation = (ScreenOrientation)QCARWrapper.Instance.GetSurfaceOrientation();

            // Check if we need to update the video background configuration and projection matrix:
            CameraDeviceImpl cameraDeviceImpl = (CameraDeviceImpl)CameraDevice.Instance;
            if (cameraDeviceImpl.CameraReady &&
                (QCARUnity.IsRendererDirty() || mProjectionOrientation != surfaceOrientation))
            {
                ConfigureVideoBackground(false);
                UpdateProjection(surfaceOrientation);
                cameraDeviceImpl.ResetDirtyFlag();
            }

            // Bind a simple material to clear the OpenGL state
            mClearMaterial.SetPass(0);

            // QCARManager renders the camera image and updates the trackables
            ((QCARManagerImpl)QCARManager.Instance).Update(mProjectionOrientation);

            // Tell Unity that we may have changed the OpenGL state behind the scenes
            GL.InvalidateState();

            // Update the camera clear flags
            UpdateCameraClearFlags();

            // Let the trackable event handlers know that all trackables have been updated
            foreach (ITrackerEventHandler handler in mTrackerEventHandlers)
            {
                handler.OnTrackablesUpdated();
            }
        }
        else if (QCARRuntimeUtilities.IsPlayMode())
        {
            // in some rare occasions, Unity re-compiles the scripts shortly after starting play mode
            // this invalidates the internal state, so we have to restart play mode in order to ensure correct execution.
            Debug.LogWarning("Scripts have been recompiled during Play mode, need to restart!");
            // re-establish wrapper:
            QCARWrapper.Create();
            // stop and restart play mode
            QCARRuntimeUtilities.RestartPlayMode();
        }
    }