Exemplo n.º 1
0
    /// <summary>
    /// returns true if we have access to QCAR (on a mobile device OR in the emulator in Unity Pro with a webcam connected)
    /// </summary>
    public static bool IsQCAREnabled()
    {
#if UNITY_EDITOR
        if (sWebCamUsed == WebCamUsed.UNKNOWN)
        {
            // query the webcam if it should be used
            WebCamBehaviour webcam = (WebCamBehaviour)Object.FindObjectOfType(typeof(WebCamBehaviour));
            sWebCamUsed = webcam.IsWebCamUsed() ? WebCamUsed.TRUE : WebCamUsed.FALSE;
        }

        return(sWebCamUsed == WebCamUsed.TRUE);
#else
        return(true);
#endif
    }
Exemplo n.º 2
0
    public void OnEnable()
    {
        WebCamBehaviour webCam = (WebCamBehaviour)target;

        // We don't want to initialize if this is a prefab.
        if (QCARUtilities.GetPrefabType(webCam) == PrefabType.Prefab)
        {
            return;
        }

        // Initialize scene manager
        if (!SceneManager.Instance.SceneInitialized)
        {
            SceneManager.Instance.InitScene();
        }
    }
Exemplo n.º 3
0
    private int InitCameraDevice(int camera)
    {
        int rslt = 0;

        try
        {
            WebCamBehaviour webCamBehaviour = (WebCamBehaviour)Object.FindObjectOfType(typeof(WebCamBehaviour));
            webCamBehaviour.InitCamera();
            mWebCam = webCamBehaviour.ImplementationClass;

            QCARWrapper.Instance.CameraDeviceSetCameraConfiguration(mWebCam.ResampledTextureSize.x, mWebCam.ResampledTextureSize.y);

            rslt = 1;
        }catch (NullReferenceException ex) {
            Debug.LogError(ex.Message);
        }

        QCARWrapper.Instance.CameraDeviceInitCamera(camera);

        return(rslt);
    }
Exemplo n.º 4
0
    public override void OnInspectorGUI()
    {
        if (!EditorApplication.isPlaying)
        {
            WebCamBehaviour webCam = (WebCamBehaviour)target;
            if (QCARUtilities.GetPrefabType(webCam) != PrefabType.Prefab)
            {
                webCam.TurnOffWebCam = EditorGUILayout.Toggle("Don't use for Play Mode", webCam.TurnOffWebCam);

                if (!webCam.TurnOffWebCam)
                {
                    // check if play mode is supported by this Unity version:
                    if (!webCam.CheckNativePluginSupport())
                    {
                        EditorGUILayout.HelpBox("Play Mode requires a Unity Pro license!", MessageType.Warning);
                    }

                    int      currentDeviceIndex = 0;
                    string[] deviceNames        = GetDeviceNames();
                    for (int i = 0; i < deviceNames.Length; i++)
                    {
                        if (deviceNames[i] != null) // sometimes this happens during Play Mode startup on Mac
                        {
                            if (deviceNames[i].Equals(webCam.DeviceName))
                            {
                                currentDeviceIndex = i;
                            }
                        }
                    }

                    // check if there is a device profile for the currently selected webcam
                    if (sWebCamProfiles == null)
                    {
                        sWebCamProfiles = new WebCamProfile();
                    }
                    string deviceName = deviceNames[currentDeviceIndex];
                    if (deviceName.Equals(NO_CAMERAS_TEXT))
                    {
                        EditorGUILayout.HelpBox("No camera connected!\nTo run your application using Play Mode, please connect a webcam to your computer.", MessageType.Warning);
                    }
                    else
                    {
                        if (!sWebCamProfiles.ProfileAvailable(deviceNames[currentDeviceIndex]))
                        {
                            EditorGUILayout.HelpBox("Webcam profile not found!\n" +
                                                    "Unfortunately there is no profile for your webcam model: '" +
                                                    deviceNames[currentDeviceIndex] + "'.\n\n" +
                                                    "The default profile will been used. You can configure a profile yourself by editing '" +
                                                    Path.Combine(Application.dataPath, "Editor/QCAR/WebcamProfiles/profiles.xml") +
                                                    "'.", MessageType.Warning);
                        }
                    }

                    EditorGUILayout.Space();
                    EditorGUILayout.BeginHorizontal();

                    EditorGUILayout.PrefixLabel("Camera Device");
                    int newDeviceIndex = EditorGUILayout.Popup(currentDeviceIndex, deviceNames);

                    if ((newDeviceIndex != currentDeviceIndex) && (!deviceNames[newDeviceIndex].Equals(NO_CAMERAS_TEXT)))
                    {
                        webCam.DeviceName = deviceNames[newDeviceIndex];
                    }

                    EditorGUILayout.EndHorizontal();

                    webCam.FlipHorizontally = EditorGUILayout.Toggle("Flip Horizontally", webCam.FlipHorizontally);

                    EditorGUILayout.Space();

                    EditorGUILayout.HelpBox("Here you can enter the index of the layer that will be used internally for our render to texture " +
                                            "functionality. the ARCamera will be configured to not draw this layer.", MessageType.None);
                    webCam.RenderTextureLayer = EditorGUILayout.IntField("Render Texture Layer", webCam.RenderTextureLayer);
                }

                if (GUI.changed)
                {
                    EditorUtility.SetDirty(webCam);
                    SceneManager.Instance.SceneUpdated();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Webcam settings cannot be changed during Play Mode.", MessageType.Info);
            }
        }
    }