Ejemplo n.º 1
0
 private /*unsafe*/ void UpdateProjection(ScreenOrientation orientation)
 {
     if (QCARRuntimeUtilities.IsQCAREnabled())
     {
         this.mProjectionOrientation = orientation;
         QCARRuntimeUtilities.CacheSurfaceOrientation(orientation);
         Matrix4x4 matrixx = QCARUnity.GetProjectionGL(base.camera.nearClipPlane, base.camera.farClipPlane, this.mProjectionOrientation);
         if (this.mViewportRect.width != Screen.width)
         {
             //ref Matrix4x4 matrixxRef;
             //Matrix4x4 *matrixxRef = &matrixx;
             float num = (this.mViewportRect.width / ((float)Screen.width)) * matrixx[0];
             //(matrixxRef = (Matrix4x4) &matrixx)[0] = matrixxRef[0] * num;
             //(*matrixxRef)[0] = (*matrixxRef)[0] * num;
             matrixx[0] = num;
         }
         if (this.mViewportRect.height != Screen.height)
         {
             //ref Matrix4x4 matrixxRef2;
             //Matrix4x4 *matrixxRef2 = (Matrix4x4 *) &matrixx;
             float num2 = (this.mViewportRect.height / ((float)Screen.height)) * matrixx[5];
             //(matrixxRef2 = (Matrix4x4) &matrixx)[5] = matrixxRef2[5] * num2;
             //(*matrixxRef2)[5] = (*matrixxRef2)[5] * num2;
             matrixx[5] = num2;
         }
         base.camera.projectionMatrix = matrixx;
     }
 }
Ejemplo n.º 2
0
    // Update the camera clear flags and background color in response
    // to QCAR settings
    private void UpdateCameraClearFlags()
    {
        // Specifically handle when running in the free editor version
        // that does not support native plugins
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            mCameraState = CameraState.UNINITED;
            return;
        }

        // Update camera clear flags if necessary
        switch (mCameraState)
        {
        case CameraState.UNINITED:
            mCameraState = CameraState.DEVICE_INITED;
            break;

        case CameraState.DEVICE_INITED:
            // Check whether QCAR requires a transparent clear color
            if (QCARUnity.RequiresAlpha())
            {
                // Camera clears both depth and color buffer,
                // We set the clear color to transparent black as
                // required by QCAR.
                this.camera.clearFlags      = CameraClearFlags.SolidColor;
                this.camera.backgroundColor = new Color(0, 0, 0, 0);
                Debug.Log("Setting camera clear flags to transparent black");
            }
            else
            {
                // Check whether QCAR is rendering the video in native
                if (mCachedDrawVideoBackground)
                {
                    // Clear only depth
                    this.camera.clearFlags = CameraClearFlags.Depth;
                    Debug.Log("Setting camera clear flags to depth only");
                }
                else
                {
                    // Restore clear settings to Inspector values
                    this.camera.clearFlags      = mCachedCameraClearFlags;
                    this.camera.backgroundColor = mCachedCameraBackgroundColor;
                    Debug.Log("Setting camera clear flags to Inspector values");
                }
            }

            mCameraState = CameraState.RENDERING_INITED;
            break;

        case CameraState.RENDERING_INITED:
            // Check if the DrawVideoBackground setting has changed
            bool drawVideoBackground = QCARManager.Instance.DrawVideoBackground;
            if (drawVideoBackground != mCachedDrawVideoBackground)
            {
                mCameraState = CameraState.DEVICE_INITED;
                mCachedDrawVideoBackground = drawVideoBackground;
            }
            break;
        }
    }
Ejemplo n.º 3
0
    // Update the camera projection matrix to match QCAR settings
    private void UpdateProjection(ScreenOrientation orientation)
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            // Skip this when running in the free editor version
            // that does not support native plugins
            return;
        }

        // This member stores the screen orientation used for the last projection matrix
        // update. It is used to counter rotate the poses later.
        mProjectionOrientation = orientation;

        // cache the current surface orientation:
        QCARRuntimeUtilities.CacheSurfaceOrientation(orientation);

        Matrix4x4 projectionMatrix = QCARUnity.GetProjectionGL(camera.nearClipPlane,
                                                               camera.farClipPlane, mProjectionOrientation);

        if (mViewportRect.width != Screen.width)
        {
            float viewportDistort = mViewportRect.width / Screen.width;
            projectionMatrix[0] *= viewportDistort;
        }

        if (mViewportRect.height != Screen.height)
        {
            float viewportDistort = mViewportRect.height / Screen.height;
            projectionMatrix[5] *= viewportDistort;
        }

        this.camera.projectionMatrix = projectionMatrix;
    }
    void Awake()
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            return;
        }

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // initialize QCAR
            QCARUnity.CheckInitializationError();
        }

        // In Unity 4.x, if the QCARBehaviour is already active from a previous scene,
        // we need to deactivate it briefly to be able to initialize the text tracker
        bool          enableQCARBehaviourAgain = false;
        QCARBehaviour qcarBehaviour            = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour && qcarBehaviour.enabled)
        {
            qcarBehaviour.enabled    = false;
            enableQCARBehaviourAgain = true;
        }

        if (TrackerManager.Instance.GetTracker(Tracker.Type.TEXT_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.TEXT_TRACKER);
        }

        // restart the QCARBehaviour if it was stopped again
        if (enableQCARBehaviourAgain)
        {
            qcarBehaviour.enabled = true;
        }
    }
Ejemplo n.º 5
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();
     }
 }
 private void Awake()
 {
     if (QCARRuntimeUtilities.IsQCAREnabled())
     {
         if (QCARRuntimeUtilities.IsPlayMode())
         {
             QCARUnity.CheckInitializationError();
         }
         bool flag = false;
         QCARAbstractBehaviour behaviour = (QCARAbstractBehaviour)UnityEngine.Object.FindObjectOfType(typeof(QCARAbstractBehaviour));
         if ((behaviour != null) && behaviour.enabled)
         {
             behaviour.enabled = false;
             flag = true;
         }
         if (TrackerManager.Instance.GetTracker <TextTracker>() == null)
         {
             TrackerManager.Instance.InitTracker <TextTracker>();
         }
         if (flag)
         {
             behaviour.enabled = true;
         }
     }
 }
 public void OnQCARInitializationError(QCARUnity.InitError initError)
 {
     if (initError != QCARUnity.InitError.INIT_SUCCESS)
     {
         SetErrorCode(initError);
         SetErrorOccurred(true);
     }
 }
Ejemplo n.º 8
0
 public void OnQCARInitializationError(QCARUnity.InitError initError)
 {
     if (initError != QCARUnity.InitError.INIT_SUCCESS)
     {
         mErrorOccurred = true;
         mPopUpMsg.SetErrorCode(initError);
     }
 }
Ejemplo n.º 9
0
    // This method is called by Unity whenever assets are updated (deleted,
    // moved or added)
    public static void OnPostprocessAllAssets(string[] importedAssets,
                                              string[] deletedAssets,
                                              string[] movedAssets,
                                              string[] movedFromAssetPaths)
    {
        // Set the Unity version for internal use
        string path = Path.Combine(Application.dataPath, "StreamingAssets/QCAR");

        QCARUnity.SetUnityVersion(path, false);
    }
 void Start()
 {
     // Check for an initialization error on start.
     QCARUnity.InitError errorCode = QCARUnity.CheckInitializationError();
     if (errorCode != QCARUnity.InitError.INIT_SUCCESS)
     {
         SetErrorCode(errorCode);
         SetErrorOccurred(true);
     }
 }
        // Implementation of the IQCARErrorHandler function which sets the
        // error message.
        private void SetErrorCode(QCARUnity.InitError errorCode)
        {
            Debug.LogError("QCAR initialization failed: " + mErrorText);
            switch (errorCode)
            {
                case QCARUnity.InitError.INIT_EXTERNAL_DEVICE_NOT_DETECTED:
                    mErrorText =
                        "Failed to initialize Vuforia because this " +
                        "device is not docked with required external hardware.";
                    break;
                case QCARUnity.InitError.INIT_LICENSE_ERROR_MISSING_KEY:
                    mErrorText =
                        "Vuforia App key is missing. Please get a valid key, " + 
					    "by logging into your account at developer.vuforia.com " + 
					    "and creating a new project";
                    break;
                case QCARUnity.InitError.INIT_LICENSE_ERROR_INVALID_KEY:
                    mErrorText =
                        "Invalid Key used. " + 
                        "Please make sure you are using a valid Vuforia App Key";
                    break;
                case QCARUnity.InitError.INIT_LICENSE_ERROR_NO_NETWORK_TRANSIENT:
                    mErrorText =
                        "Unable to contact server. Please try again later.";
                    break;
                case QCARUnity.InitError.INIT_LICENSE_ERROR_NO_NETWORK_PERMANENT:
                    mErrorText =
                        "No network available. Please make sure you are connected to the internet.";
                    break;
                case QCARUnity.InitError.INIT_LICENSE_ERROR_CANCELED_KEY:
                    mErrorText =
                        "This App license key has been cancelled " + 
                        "and may no longer be used. Please get a new license key.";
                    break;
    #if UNITY_IPHONE
                case QCARUnity.InitError.INIT_NO_CAMERA_ACCESS:
                    mErrorText = 
                        "Camera Access was denied to this App. \n" + 
                        "When running on iOS8 devices, \n" + 
                        "users must explicitly allow the App to access the camera.\n" + 
                        "To restore camera access on your device, go to: \n" + 
                        "Settings > Privacy > Camera > [This App Name] and switch it ON.";
                    break;
    #endif
                case QCARUnity.InitError.INIT_DEVICE_NOT_SUPPORTED:
                    mErrorText =
                        "Failed to initialize QCAR because this device is not " +
                        "supported.";
                    break;
                case QCARUnity.InitError.INIT_ERROR:
                    mErrorText = "Failed to initialize QCAR.";
                    break;
            }
        }
Ejemplo n.º 12
0
    private void UpdateCameraClearFlags()
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            this.mCameraState = CameraState.UNINITED;
        }
        else
        {
            switch (this.mCameraState)
            {
            case CameraState.UNINITED:
                this.mCameraState = CameraState.DEVICE_INITED;
                return;

            case CameraState.DEVICE_INITED:
                if (!QCARUnity.RequiresAlpha())
                {
                    if (this.mCachedDrawVideoBackground)
                    {
                        base.camera.clearFlags = CameraClearFlags.Depth;
                        Debug.Log("Setting camera clear flags to depth only");
                    }
                    else
                    {
                        base.camera.clearFlags      = this.mCachedCameraClearFlags;
                        base.camera.backgroundColor = this.mCachedCameraBackgroundColor;
                        Debug.Log("Setting camera clear flags to Inspector values");
                    }
                    break;
                }
                base.camera.clearFlags      = CameraClearFlags.Color;
                base.camera.backgroundColor = new Color(0f, 0f, 0f, 0f);
                Debug.Log("Setting camera clear flags to transparent black");
                break;

            case CameraState.RENDERING_INITED:
            {
                bool drawVideoBackground = QCARManager.Instance.DrawVideoBackground;
                if (drawVideoBackground != this.mCachedDrawVideoBackground)
                {
                    this.mCameraState = CameraState.DEVICE_INITED;
                    this.mCachedDrawVideoBackground = drawVideoBackground;
                }
                return;
            }

            default:
                return;
            }
            this.mCameraState = CameraState.RENDERING_INITED;
        }
    }
Ejemplo n.º 13
0
 private void Start()
 {
     if ((KeepAliveAbstractBehaviour.Instance != null) && KeepAliveAbstractBehaviour.Instance.KeepARCameraAlive)
     {
         UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
     }
     Debug.Log("QCARWrapper.Start");
     if (this.mAndroidUnityPlayer != null)
     {
         this.mAndroidUnityPlayer.Start();
     }
     if (QCARUnity.CheckInitializationError() != QCARUnity.InitError.INIT_SUCCESS)
     {
         this.mIsInitialized = false;
     }
     else
     {
         if (TrackerManager.Instance.GetTracker <MarkerTracker>() == null)
         {
             TrackerManager.Instance.InitTracker <MarkerTracker>();
         }
         if (TrackerManager.Instance.GetTracker <ImageTracker>() == null)
         {
             TrackerManager.Instance.InitTracker <ImageTracker>();
         }
         this.mCachedDrawVideoBackground   = QCARManager.Instance.DrawVideoBackground;
         this.mCachedCameraClearFlags      = base.camera.clearFlags;
         this.mCachedCameraBackgroundColor = base.camera.backgroundColor;
         Screen.sleepTimeout = -1;
         this.ResetCameraClearFlags();
         this.mClearMaterial = new Material(Shader.Find("Diffuse"));
         QCARUnity.SetHint(QCARUnity.QCARHint.HINT_MAX_SIMULTANEOUS_IMAGE_TARGETS, this.MaxSimultaneousImageTargets);
         QCARUnityImpl.SetUnityVersion(Application.persistentDataPath, true);
         ((StateManagerImpl)TrackerManager.Instance.GetStateManager()).AssociateMarkerBehaviours();
         this.StartQCAR();
         QCARManager.Instance.WorldCenterMode = this.mWorldCenterMode;
         QCARManager.Instance.WorldCenter     = this.mWorldCenter;
         QCARManager.Instance.ARCamera        = base.camera;
         QCARManager.Instance.Init();
         this.mIsInitialized = true;
         foreach (ITrackerEventHandler handler in this.mTrackerEventHandlers)
         {
             handler.OnInitialized();
         }
         this.mHasStartedOnce = true;
         if (QCARRuntimeUtilities.IsPlayMode())
         {
             this.UpdateProjection(ScreenOrientation.Portrait);
         }
     }
 }
    // Implementation of the IQCARErrorHandler function which sets the
    // error message.
    private void SetErrorCode(QCARUnity.InitError errorCode)
    {
        switch (errorCode)
        {
            case QCARUnity.InitError.INIT_DEVICE_NOT_SUPPORTED:
                mErrorText =
                      "Failed to initialize QCAR because this device is not " +
                      "supported.";

                break;
            case QCARUnity.InitError.INIT_ERROR:
                mErrorText = "Failed to initialize QCAR.";
                break;
        }
    }
    void Awake()
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            return;
        }

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // initialize QCAR
            QCARUnity.CheckInitializationError();
        }

        if (TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);
        }

        if (mDataSetsToLoad.Count <= 0)
        {
            Debug.LogWarning("No data sets defined. Not loading any data sets.");
            return;
        }

        foreach (string dataSetName in mDataSetsToLoad)
        {
            if (!DataSet.Exists(dataSetName))
            {
                Debug.LogError("Data set " + dataSetName + " does not exist.");
                continue;
            }

            ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
            DataSet      dataSet      = imageTracker.CreateDataSet();

            if (!dataSet.Load(dataSetName))
            {
                Debug.LogError("Failed to load data set " + dataSetName + ".");
                continue;
            }

            // Activate the data set if it is the one specified in the editor.
            if (mDataSetsToActivate.Contains(dataSetName))
            {
                imageTracker.ActivateDataSet(dataSet);
            }
        }
    }
Ejemplo n.º 16
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();
        }
    }
    void Awake()
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            return;
        }


        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // initialize QCAR
            QCARUnity.CheckInitializationError();
        }

        if (TrackerManager.Instance.GetTracker(Tracker.Type.TEXT_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.TEXT_TRACKER);
        }
    }
Ejemplo n.º 18
0
    IEnumerator Starter()
    {
        if (GameObject.Find("ObjLoaderHolder") == null)
        {
            var g = GameObject.Instantiate(Resources.Load("ObjLoaderHolder"));
            g.name = "ObjLoaderHolder";
        }

        ////////////////////////////////////////////////////////////////////////////////
        // Load data set
        ////////////////////////////////////////////////////////////////////////////////
        int count = 0;

        while (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            yield return(new WaitForSeconds(0.5f));

            count++;
            if (count > 10)
            {
                Debug.LogError("Timeout exception of waying QCARRuntimeUtilities.IsQCAREnabled");
                yield break;
            }
        }
        Debug.Log("DataSetLoadBehaviour: IsQCAREnabled == true");
        var path = Configuration.ConfigMaganer.Instance.Application.XmlPath;

        if (!path.StartsWith("/"))
        {
            path = System.IO.Path.Combine(Application.persistentDataPath, path);
        }

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // initialize QCAR
            QCARUnity.CheckInitializationError();
        }

        if (TrackerManager.Instance.GetTracker <ImageTracker>() == null)
        {
            TrackerManager.Instance.InitTracker <ImageTracker>();
        }

        if (!DataSet.Exists(path, DataSet.StorageType.STORAGE_ABSOLUTE))
        {
            Debug.LogError("Data set " + path + " does not exist.");
            Application.Quit();
        }

        ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker <ImageTracker>();
        DataSet      dataSet      = imageTracker.CreateDataSet();

        if (!dataSet.Load(path, DataSet.StorageType.STORAGE_ABSOLUTE))
        {
            Debug.LogError("Failed to load data set " + path + ".");
            Application.Quit();
        }
        imageTracker.ActivateDataSet(dataSet);
        Debug.Log("Dataset activated: " + path);
        ////////////////////////////////////////////////////////////////////////////////



        while (!QCARManager.Instance.Initialized)
        {
            yield return(new WaitForEndOfFrame());
        }
        ////////////////////////////////////////////////////////////////////////////////
        QCARRenderer.Instance.DrawVideoBackground = Configuration.ConfigMaganer.Instance.Application.Debug;
        ////////////////////////////////////////////////////////////////////////////////

        if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_INFINITY))
        {
            Debug.Log("Camera focus mode setted to FOCUS_MODE_INFINITY");
        }
        else
        {
            Debug.Log("Camera can't focus to FOCUS_MODE_INFINITY");
        }

        var markersLister = Camera.main.GetComponent <MarkersLister>();

        DataSetTrackableBehaviour[] trackableBehaviours = (DataSetTrackableBehaviour[])GameObject.FindObjectsOfType(typeof(DataSetTrackableBehaviour));
        var selectionObjectOriginal = (GameObject)Resources.Load("SelectionObject");

        foreach (DataSetTrackableBehaviour trackableBehaviour in trackableBehaviours)
        {
            IEditorDataSetTrackableBehaviour editorTrackableBehaviour = trackableBehaviour;

            if (editorTrackableBehaviour.gameObject.transform.childCount == 0)
            {
                editorTrackableBehaviour.gameObject.name = "Marker[" + editorTrackableBehaviour.TrackableName + "]";
                editorTrackableBehaviour.gameObject.AddComponent <TurnOffBehaviour>();

                var markerName     = editorTrackableBehaviour.TrackableName;
                var trackableEvent = editorTrackableBehaviour.gameObject.AddComponent <TrackableEventHandler>();

                if (Configuration.ConfigMaganer.Instance.Application.Debug)
                {
                    var obj = (GameObject)GameObject.Instantiate(selectionObjectOriginal);
                    obj.transform.parent        = editorTrackableBehaviour.gameObject.transform;
                    obj.transform.localPosition = Vector3.zero;
                    obj.transform.localScale    = Vector3.one;
                }

                markersLister.AddMarker(markerName, trackableEvent);
            }
        }
    }
Ejemplo n.º 19
0
    // Starts up the QCAR extension with the properties that were set in the
    // Unity inspector.
    void Start()
    {
        // keeps the ARCamera object alive across scenes:
        if (KeepAliveBehaviour.Instance != null && KeepAliveBehaviour.Instance.KeepARCameraAlive)
        {
            DontDestroyOnLoad(gameObject);
        }

        Debug.Log("QCARWrapper.Start");
        // First we check if QCAR initialized correctly.
        if (QCARUnity.CheckInitializationError() != QCARUnity.InitError.INIT_SUCCESS)
        {
            mIsInitialized = false;
            return;
        }

        // Initialize the trackers if they haven't already been initialized.
        if (TrackerManager.Instance.GetTracker(Tracker.Type.MARKER_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.MARKER_TRACKER);
        }

        if (TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);
        }

        // Cache the camera start values
        mCachedDrawVideoBackground   = QCARManager.Instance.DrawVideoBackground;
        mCachedCameraClearFlags      = this.camera.clearFlags;
        mCachedCameraBackgroundColor = this.camera.backgroundColor;

        // keep the device's screen turned on and bright.
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        // Reset the camera clear flags and create a simple material
        ResetCameraClearFlags();
        mClearMaterial = new Material(Shader.Find("Diffuse"));

        // Set QCAR hints from the Inspector options
        QCARUnity.SetHint(QCARUnity.QCARHint.HINT_MAX_SIMULTANEOUS_IMAGE_TARGETS,
                          MaxSimultaneousImageTargets);

        // Set the Unity version for internal use
        QCARUnityImpl.SetUnityVersion(Application.persistentDataPath, true);

        // register markers in QCAR:
        StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();

        stateManager.AssociateMarkerBehaviours();

        // Start the camera and tracker
        StartQCAR();

        // Initialize the QCARManager
        QCARManager.Instance.WorldCenterMode = mWorldCenterMode;
        QCARManager.Instance.WorldCenter     = mWorldCenter;
        QCARManager.Instance.ARCamera        = camera;
        QCARManager.Instance.Init();

        // Initialize local variables
        mIsInitialized = true;

        // Let the trackable event handlers know that QCAR has been initialized
        foreach (ITrackerEventHandler handler in mTrackerEventHandlers)
        {
            handler.OnInitialized();
        }

        mHasStartedOnce = true;
    }
 // Sets a hint for the QCAR SDK
 // Hints help the SDK to understand the developer's needs.
 // However, depending on the device or SDK version the hints
 // might not be taken into consideration.
 // Returns false if the hint is unknown or deprecated.
 public static bool SetHint(QCARUnity.QCARHint hint, int value)
 {
     Debug.Log("SetHint");
     return QCARWrapper.Instance.QcarSetHint((int)hint, value) == 1;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Pauses QCAR
 /// </summary>
 public void OnPause()
 {
     QCARUnity.OnPause();
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Resumes QCAR
 /// </summary>
 public void OnResume()
 {
     QCARUnity.OnResume();
 }
Ejemplo n.º 23
0
    public void SetErrorCode(QCARUnity.InitError errorCode)
    {
        mCurrentError = new ErrorData();
        mCurrentError.Title = "QCAR Initialization Error";
        mCurrentError.Text = "";
        Debug.LogError("QCAR initialization failed: " + errorCode);
        mErrorcode = errorCode;
        switch (errorCode)
        {
            case QCARUnity.InitError.INIT_LICENSE_ERROR_MISSING_KEY:
                mCurrentError.Text =
                      "Vuforia App key is missing. Please get a valid key, by logging into your account at developer.vuforia.com and creating a new project ";
                break;
        #if UNITY_IPHONE
            case QCARUnity.InitError.INIT_NO_CAMERA_ACCESS:
                 mCurrentError.Text =
                    "Camera Access was denied to this App. \n" +
                    "When running on iOS8 devices, \n" +
                    "users must explictly allow the App to access the camera.\n" +
                    "To restore camera access on your device, go to: \n" +
                    "Settings > Privacy > Camera > [This App Name] and switch it ON.";
                break;
        #endif
            case QCARUnity.InitError.INIT_LICENSE_ERROR_INVALID_KEY:
                mCurrentError.Text =
                      " Invalid Key used. Please make sure you are using a valid Vuforia App Key";

                break;

            case QCARUnity.InitError.INIT_LICENSE_ERROR_NO_NETWORK_TRANSIENT:
                mCurrentError.Text =
                      "Unable to contact server. Please try again later.";

                break;

            case QCARUnity.InitError.INIT_LICENSE_ERROR_NO_NETWORK_PERMANENT:
                mCurrentError.Text =
                      "No network available. Please make sure you are connected to the Internet.";

                break;

            case QCARUnity.InitError.INIT_LICENSE_ERROR_CANCELED_KEY:
                mCurrentError.Text = "This app license key has been canceled and may no longer be used. Please get a new license key";
                break;

            case QCARUnity.InitError.INIT_ERROR:
                mCurrentError.Text = "Failed to initialize QCAR.";
                break;
        }
    }
Ejemplo n.º 24
0
 /// <summary>
 /// Deinitializes QCAR
 /// </summary>
 public void OnDestroy()
 {
     QCARUnity.Deinit();
 }