Beispiel #1
0
        private void EnumerateDevices()
        {
            // Enumerate all cameras
            int numDevices = AVProLiveCameraManager.Instance.NumDevices;

            print("num devices: " + numDevices);
            for (int i = 0; i < numDevices; i++)
            {
                AVProLiveCameraDevice device = AVProLiveCameraManager.Instance.GetDevice(i);

                // Enumerate video inputs (only for devices with multiple analog input sources, eg TV cards)
                print("device " + i + ": " + device.Name + " (" + device.GUID + ") has " + device.NumVideoInputs + " videoInputs");
                for (int j = 0; j < device.NumVideoInputs; j++)
                {
                    print("  videoInput " + j + ": " + device.GetVideoInputName(j));
                }

                // Enumerate camera modes
                print("device " + i + ": " + device.Name + " (" + device.GUID + ") has " + device.NumModes + " modes");
                for (int j = 0; j < device.NumModes; j++)
                {
                    AVProLiveCameraDeviceMode mode = device.GetMode(j);
                    print("  mode " + j + ": " + mode.Width + "x" + mode.Height + " @" + mode.FPS.ToString("F2") + "fps [" + mode.Format + "]");
                }

                // Enumerate camera settings
                print("device " + i + ": " + device.Name + " (" + device.GUID + ") has " + device.NumSettings + " video settings");
                for (int j = 0; j < device.NumSettings; j++)
                {
                    AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                    switch (settingBase.DataTypeValue)
                    {
                    case AVProLiveCameraSettingBase.DataType.Boolean:
                    {
                        AVProLiveCameraSettingBoolean settingBool = (AVProLiveCameraSettingBoolean)settingBase;
                        print(string.Format("  setting {0}: {1}({2}) value:{3} default:{4} canAuto:{5} isAuto:{6}", j, settingBase.Name, settingBase.PropertyIndex, settingBool.CurrentValue, settingBool.DefaultValue, settingBase.CanAutomatic, settingBase.IsAutomatic));
                    }
                    break;

                    case AVProLiveCameraSettingBase.DataType.Float:
                    {
                        AVProLiveCameraSettingFloat settingFloat = (AVProLiveCameraSettingFloat)settingBase;
                        print(string.Format("  setting {0}: {1}({2}) value:{3} default:{4} range:{5}-{6} canAuto:{7} isAuto:{8}", j, settingBase.Name, settingBase.PropertyIndex, settingFloat.CurrentValue, settingFloat.DefaultValue, settingFloat.MinValue, settingFloat.MaxValue, settingBase.CanAutomatic, settingBase.IsAutomatic));
                    }
                    break;
                    }
                }

                _instances.Add(new UIData()
                {
                    scrollPos           = Vector2.zero,
                    scrollVideoInputPos = Vector2.zero,
                    showSettings        = false,
                    showModes           = false,
                    material            = null
                });
            }
        }
    public AVProLiveCameraSettingBase GetVideoSettingByType(SettingsEnum type)
    {
        AVProLiveCameraSettingBase result = null;

        if (!_settingsByType.TryGetValue((int)type, out result))
        {
            result = null;
        }
        return(result);
    }
    public AVProLiveCameraSettingBase GetVideoSettingByIndex(int index)
    {
        AVProLiveCameraSettingBase result = null;

        if (index >= 0 && index < _settings.Count)
        {
            result = _settings[index];
        }

        return(result);
    }
    private void EnumVideoSettings()
    {
        int numVideoSettings = AVProLiveCameraPlugin.GetNumDeviceVideoSettings(_deviceIndex);

        for (int i = 0; i < numVideoSettings; i++)
        {
            int    settingType;
            int    dataType;
            string name;
            bool   canAutomatic;
            if (AVProLiveCameraPlugin.GetDeviceVideoSettingInfo(_deviceIndex, i, out settingType, out dataType, out name, out canAutomatic))
            {
                AVProLiveCameraSettingBase setting = null;

                // Data type is boolean
                if (dataType == 0)
                {
                    bool defaultValue;
                    bool currentValue;
                    bool isAutomatic;
                    if (AVProLiveCameraPlugin.GetDeviceVideoSettingBoolean(_deviceIndex, i, out defaultValue, out currentValue, out isAutomatic))
                    {
                        setting = new AVProLiveCameraSettingBoolean(_deviceIndex, i, settingType, name, canAutomatic, isAutomatic, defaultValue, currentValue);
                    }
                }
                // Data type is float
                else if (dataType == 1)
                {
                    bool  isAutomatic;
                    float defaultValue;
                    float currentValue;
                    float minValue, maxValue;
                    if (AVProLiveCameraPlugin.GetDeviceVideoSettingFloat(_deviceIndex, i, out defaultValue, out currentValue, out minValue, out maxValue, out isAutomatic))
                    {
                        setting = new AVProLiveCameraSettingFloat(_deviceIndex, i, settingType, name, canAutomatic, isAutomatic, defaultValue, currentValue, minValue, maxValue);
                    }
                }

                if (setting != null)
                {
                    _settings.Add(setting);
                    _settingsByType.Add(settingType, setting);
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        _camera = (this.target) as AVProLiveCamera;

        //EditorGUIUtility.LookLikeInspector();
        //DrawDefaultInspector();

        if (!Application.isPlaying)
        {
            EditorGUILayout.LabelField("Search for Capture Device:", "");
            EditorGUILayout.Space();

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Device Select By");
            GUILayout.BeginVertical();

            AVProLiveCamera.SelectDeviceBy newDeviceSelection = (AVProLiveCamera.SelectDeviceBy)EditorGUILayout.EnumPopup("", _camera._deviceSelection);
            switch (newDeviceSelection)
            {
            case AVProLiveCamera.SelectDeviceBy.Default:
                break;

            case AVProLiveCamera.SelectDeviceBy.Name:
                if (_camera._deviceSelection != newDeviceSelection && _camera._desiredDeviceNames.Count == 0)
                {
                    _camera._desiredDeviceNames.Add("Enter Camera Name");
                }
                EditorGUILayout.BeginVertical();
                for (int index = 0; index < _camera._desiredDeviceNames.Count; index++)
                {
                    EditorGUILayout.BeginHorizontal();


                    /*EditorGUILayout.BeginHorizontal(GUILayout.Width(96));
                     * if (index != 0)
                     * {
                     *      if (GUILayout.Button("Up"))
                     *      {
                     *              string temp = _camera._desiredDeviceNames[index - 1];
                     *              _camera._desiredDeviceNames[index - 1] = _camera._desiredDeviceNames[index];
                     *              _camera._desiredDeviceNames[index] = temp;
                     *              HandleUtility.Repaint();
                     *      }
                     * }
                     * if (index + 1 < _camera._desiredDeviceNames.Count)
                     * {
                     *      if (GUILayout.Button("Down"))
                     *      {
                     *              string temp = _camera._desiredDeviceNames[index + 1];
                     *              _camera._desiredDeviceNames[index + 1] = _camera._desiredDeviceNames[index];
                     *              _camera._desiredDeviceNames[index] = temp;
                     *              HandleUtility.Repaint();
                     *      }
                     * }
                     * EditorGUILayout.EndHorizontal();*/

                    if (GUILayout.Button("-"))
                    {
                        _camera._desiredDeviceNames.RemoveAt(index);
                        break;
                    }
                    else
                    {
                        _camera._desiredDeviceNames[index] = EditorGUILayout.TextField(_camera._desiredDeviceNames[index]);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (GUILayout.Button("+"))
                {
                    _camera._desiredDeviceNames.Add(string.Empty);
                    this.Repaint();
                }
                EditorGUILayout.EndVertical();
                break;

            case AVProLiveCamera.SelectDeviceBy.Index:
                _camera._desiredDeviceIndex = EditorGUILayout.IntField(_camera._desiredDeviceIndex);
                break;
            }
            _camera._deviceSelection = newDeviceSelection;
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();



            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Mode Select By");
            GUILayout.BeginVertical();
            AVProLiveCamera.SelectModeBy newResolutionSelection = (AVProLiveCamera.SelectModeBy)EditorGUILayout.EnumPopup("", _camera._modeSelection);
            switch (newResolutionSelection)
            {
            case AVProLiveCamera.SelectModeBy.Default:
                break;

            case AVProLiveCamera.SelectModeBy.Resolution:
                if (_camera._modeSelection != newResolutionSelection && _camera._desiredResolutions.Count == 0)
                {
                    _camera._desiredResolutions.Add(new Vector2(640, 360));
                }
                EditorGUILayout.BeginVertical();
                _camera._maintainAspectRatio = EditorGUILayout.Toggle("Maintain Aspect Ratio", _camera._maintainAspectRatio);
                for (int index = 0; index < _camera._desiredResolutions.Count; index++)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("-"))
                    {
                        _camera._desiredResolutions.RemoveAt(index);
                        break;
                    }
                    else
                    {
                        Vector2 res = _camera._desiredResolutions[index];
                        res.x = EditorGUILayout.FloatField(res.x, GUILayout.Width(64));
                        EditorGUILayout.LabelField("x", "", GUILayout.Width(24));
                        res.y = EditorGUILayout.FloatField(res.y, GUILayout.Width(64));
                        _camera._desiredResolutions[index] = res;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (GUILayout.Button("+"))
                {
                    _camera._desiredResolutions.Add(new Vector2(640, 360));
                    this.Repaint();
                }

                EditorGUILayout.EndVertical();
                break;

            case AVProLiveCamera.SelectModeBy.Index:
                _camera._desiredModeIndex = EditorGUILayout.IntField(_camera._desiredModeIndex);
                break;
            }
            _camera._modeSelection = newResolutionSelection;
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();



            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Video Input Select By");
            GUILayout.BeginVertical();
            AVProLiveCamera.SelectDeviceBy newVideoInputSelection = (AVProLiveCamera.SelectDeviceBy)EditorGUILayout.EnumPopup("", _camera._videoInputSelection);
            switch (newVideoInputSelection)
            {
            case AVProLiveCamera.SelectDeviceBy.Default:
                break;

            case AVProLiveCamera.SelectDeviceBy.Name:
                if (_camera._videoInputSelection != newVideoInputSelection && _camera._desiredVideoInputs.Count == 0)
                {
                    _camera._desiredVideoInputs.Add(AVProLiveCameraPlugin.VideoInput.Video_Serial_Digital);
                }
                EditorGUILayout.BeginVertical();
                for (int index = 0; index < _camera._desiredVideoInputs.Count; index++)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("-"))
                    {
                        _camera._desiredVideoInputs.RemoveAt(index);
                        break;
                    }
                    else
                    {
                        _camera._desiredVideoInputs[index] = (AVProLiveCameraPlugin.VideoInput)EditorGUILayout.EnumPopup(_camera._desiredVideoInputs[index]);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (GUILayout.Button("+"))
                {
                    _camera._desiredVideoInputs.Add(AVProLiveCameraPlugin.VideoInput.Video_Serial_Digital);
                    this.Repaint();
                }
                EditorGUILayout.EndVertical();
                break;

            case AVProLiveCamera.SelectDeviceBy.Index:
                _camera._desiredVideoInputIndex = EditorGUILayout.IntField(_camera._desiredVideoInputIndex);
                break;
            }
            _camera._videoInputSelection = newVideoInputSelection;
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();

            _camera._playOnStart = EditorGUILayout.Toggle("Play On Start", _camera._playOnStart);
            _camera._deinterlace = EditorGUILayout.Toggle("Deinterlace", _camera._deinterlace);
        }
        else
        {
            if (_camera.Device != null)
            {
                _preview = GUILayout.Toggle(_preview, "Inspector Preview");

                AVProLiveCameraDevice device = _camera.Device;


                if (_preview && device.OutputTexture != null)
                {
                    Rect textureRect = GUILayoutUtility.GetRect(64.0f, 64.0f, GUILayout.MinWidth(64.0f), GUILayout.MinHeight(64.0f));
                    GUI.DrawTexture(textureRect, device.OutputTexture, ScaleMode.ScaleToFit);
                }

                GUILayout.Label("Device: " + device.Name);
                GUILayout.Label(string.Format("Mode: {0}x{1} {2}", device.CurrentWidth, device.CurrentHeight, device.CurrentFormat));

                if (device.FramesTotal > 30)
                {
                    GUILayout.Label("Displaying at " + device.DisplayFPS.ToString("F1") + " fps");
                }
                else
                {
                    GUILayout.Label("Displaying at ... fps");
                }

                if (device.IsRunning)
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Stop Camera"))
                    {
                        device.Close();
                    }
                    if (device.IsPaused)
                    {
                        if (GUILayout.Button("Unpause Stream"))
                        {
                            device.Play();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Pause Stream"))
                        {
                            device.Pause();
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    if (GUILayout.Button("Start Camera"))
                    {
                        _camera.Begin();
                    }
                }

                GUI.enabled = device.CanShowConfigWindow();
                if (GUILayout.Button("Show Config Window"))
                {
                    device.ShowConfigWindow();
                }
                GUI.enabled = true;

                if (device.NumSettings > 0)
                {
                    EditorGUILayout.PrefixLabel("Device Settings", EditorStyles.boldLabel);
                    for (int j = 0; j < device.NumSettings; j++)
                    {
                        AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                        GUILayout.BeginHorizontal();
                        GUI.enabled = !settingBase.IsAutomatic;
                        if (GUILayout.Button("D", GUILayout.ExpandWidth(false)))
                        {
                            settingBase.SetDefault();
                        }
                        GUI.enabled = true;
                        GUILayout.Label(settingBase.Name, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(64.0f));
                        GUI.enabled = !settingBase.IsAutomatic;
                        switch (settingBase.DataTypeValue)
                        {
                        case AVProLiveCameraSettingBase.DataType.Boolean:
                            AVProLiveCameraSettingBoolean settingBool = (AVProLiveCameraSettingBoolean)settingBase;
                            settingBool.CurrentValue = GUILayout.Toggle(settingBool.CurrentValue, "", GUILayout.ExpandWidth(true));
                            break;

                        case AVProLiveCameraSettingBase.DataType.Float:
                            AVProLiveCameraSettingFloat settingFloat = (AVProLiveCameraSettingFloat)settingBase;
                            float sliderValue = GUILayout.HorizontalSlider(settingFloat.CurrentValue, settingFloat.MinValue, settingFloat.MaxValue, GUILayout.ExpandWidth(true));
                            if (GUI.enabled)
                            {
                                settingFloat.CurrentValue = sliderValue;
                            }

                            GUILayout.Label(((long)settingFloat.CurrentValue).ToString(), GUILayout.Width(32.0f), GUILayout.ExpandWidth(false));
                            GUI.enabled             = settingBase.CanAutomatic;
                            settingBase.IsAutomatic = GUILayout.Toggle(settingBase.IsAutomatic, "", GUILayout.Width(32.0f));
                            GUI.enabled             = true;
                            break;
                        }
                        GUI.enabled = true;
                        GUILayout.EndHorizontal();
                    }
                    if (GUILayout.Button("Defaults"))
                    {
                        for (int j = 0; j < device.NumSettings; j++)
                        {
                            AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                            settingBase.SetDefault();
                        }
                    }
                    device.Update_Settings();
                }
                //EditorGUILayout.Toggle("Running:", device.IsRunning);
            }

            if (_preview)
            {
                //HandleUtility.Repaint();
                this.Repaint();
            }
        }

        GUI.enabled    = true;
        _camera._flipX = EditorGUILayout.Toggle("Flip X", _camera._flipX);
        _camera._flipY = EditorGUILayout.Toggle("Flip Y", _camera._flipY);
        EditorGUILayout.Space();
        _camera._updateHotSwap    = EditorGUILayout.Toggle("Update HotSwap", _camera._updateHotSwap);
        _camera._updateFrameRates = EditorGUILayout.Toggle("Update Frame Rates", _camera._updateFrameRates);
        _camera._updateSettings   = EditorGUILayout.Toggle("Update Settings", _camera._updateSettings);

        if (GUI.changed)
        {
            EditorUtility.SetDirty(_camera);
        }
    }
Beispiel #6
0
        public void OnGUI()
        {
            if (_guiSkin != null)
            {
                if (_buttonStyle == null)
                {
                    _buttonStyle = _guiSkin.FindStyle("LeftButton");
                }
                GUI.skin = _guiSkin;
            }
            if (_buttonStyle == null)
            {
                _buttonStyle = GUI.skin.button;
            }

            _horizScrollPos = GUILayout.BeginScrollView(_horizScrollPos, false, false);
            GUILayout.BeginHorizontal();
            for (int i = 0; i < AVProLiveCameraManager.Instance.NumDevices; i++)
            {
                GUILayout.BeginVertical("box", GUILayout.MaxWidth(300));

                AVProLiveCameraDevice device = AVProLiveCameraManager.Instance.GetDevice(i);

                GUI.enabled = device.IsConnected;

                Rect cameraRect = GUILayoutUtility.GetRect(300, 168);
                if (GUI.Button(cameraRect, ""))
                {
                    if (_zoomed == null)
                    {
                        _zoomed      = device.OutputTexture;
                        _zoomSrcDest = cameraRect;
                        _zoomUp      = true;
                    }
                }

                // Thumbnail image
                if (device.OutputTexture != null && _zoomed != device.OutputTexture)
                {
                    if (_material != null)
                    {
                        DrawTexture(cameraRect, device.OutputTexture, ScaleMode.ScaleToFit, _material);
                    }
                    else
                    {
                        GUI.DrawTexture(cameraRect, device.OutputTexture, ScaleMode.ScaleToFit, false);
                    }
                }

                GUILayout.Box("Camera " + i + ": " + device.Name);
                if (!device.IsRunning)
                {
                    GUILayout.BeginHorizontal();
                    GUI.color = Color.green;
                    if (GUILayout.Button("Start"))
                    {
                        if (_zoomed == null)
                        {
                            device.Start(-1);
                        }
                    }
                    GUI.color = Color.white;
                }
                else
                {
                    GUILayout.Box(string.Format("{0}x{1} {2}", device.CurrentWidth, device.CurrentHeight, device.CurrentFormat));
                    GUILayout.BeginHorizontal();
                    GUILayout.Box(string.Format("Capture {0}hz Display {1}hz", device.CaptureFPS.ToString("F2"), device.DisplayFPS.ToString("F2")));
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUI.color = Color.red;
                    if (GUILayout.Button("Stop"))
                    {
                        if (_zoomed == null)
                        {
                            device.Close();
                        }
                    }
                    GUI.color = Color.white;
                }
                GUI.enabled = device.CanShowConfigWindow();
                if (GUILayout.Button("Configure", GUILayout.ExpandWidth(false)))
                {
                    if (_zoomed == null)
                    {
                        device.ShowConfigWindow();
                    }
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                if (device.NumVideoInputs > 0)
                {
                    GUILayout.Label("Select a video input:");
                    _scrollVideoInputPos[i] = GUILayout.BeginScrollView(_scrollVideoInputPos[i], false, false);
                    for (int j = 0; j < device.NumVideoInputs; j++)
                    {
                        if (GUILayout.Button(device.GetVideoInputName(j)))
                        {
                            if (_zoomed == null)
                            {
                                // Start selected device
                                device.Close();
                                device.Start(-1, j);
                            }
                        }
                    }
                    GUILayout.EndScrollView();
                }

                if (device.Deinterlace != GUILayout.Toggle(device.Deinterlace, "Deinterlace", GUILayout.ExpandWidth(true)))
                {
                    device.Deinterlace = !device.Deinterlace;
                    if (device.IsRunning)
                    {
                        device.Close();
                        device.Start(-1, -1);
                    }
                }

                GUILayout.BeginHorizontal();
                device.FlipX = GUILayout.Toggle(device.FlipX, "Flip X", GUILayout.ExpandWidth(true));
                device.FlipY = GUILayout.Toggle(device.FlipY, "Flip Y", GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                _scrollPos[i] = GUILayout.BeginScrollView(_scrollPos[i], false, false);

                if (device.NumSettings > 0)
                {
                    GUI.color        = Color.cyan;
                    _showSettings[i] = GUILayout.Toggle(_showSettings[i], "Settings ▶", GUILayout.ExpandWidth(true));
                    GUI.color        = Color.white;
                    if (_showSettings[i])
                    {
                        device.UpdateSettings = GUILayout.Toggle(device.UpdateSettings, "Update Settings", GUILayout.ExpandWidth(true));

                        for (int j = 0; j < device.NumSettings; j++)
                        {
                            AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                            GUILayout.BeginHorizontal();
                            GUI.enabled = !settingBase.IsAutomatic;
                            if (GUILayout.Button("D", GUILayout.ExpandWidth(false)))
                            {
                                settingBase.SetDefault();
                            }
                            GUI.enabled = true;
                            GUILayout.Label(settingBase.Name, GUILayout.ExpandWidth(false));
                            GUI.enabled = !settingBase.IsAutomatic;
                            switch (settingBase.DataTypeValue)
                            {
                            case AVProLiveCameraSettingBase.DataType.Boolean:
                                AVProLiveCameraSettingBoolean settingBool = (AVProLiveCameraSettingBoolean)settingBase;
                                settingBool.CurrentValue = GUILayout.Toggle(settingBool.CurrentValue, "", GUILayout.ExpandWidth(true));
                                break;

                            case AVProLiveCameraSettingBase.DataType.Float:
                                AVProLiveCameraSettingFloat settingFloat = (AVProLiveCameraSettingFloat)settingBase;
                                settingFloat.CurrentValue = GUILayout.HorizontalSlider(settingFloat.CurrentValue, settingFloat.MinValue, settingFloat.MaxValue, GUILayout.ExpandWidth(true));

                                GUI.enabled             = settingBase.CanAutomatic;
                                settingBase.IsAutomatic = GUILayout.Toggle(settingBase.IsAutomatic, "", GUILayout.Width(32.0f));
                                GUI.enabled             = true;

                                break;
                            }
                            GUI.enabled = true;
                            GUILayout.EndHorizontal();
                        }

                        if (GUILayout.Button("Defaults"))
                        {
                            for (int j = 0; j < device.NumSettings; j++)
                            {
                                AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                                settingBase.SetDefault();
                            }
                        }
                    }
                }

                GUI.color     = Color.cyan;
                _showModes[i] = GUILayout.Toggle(_showModes[i], "Modes ▶", GUILayout.ExpandWidth(true));
                GUI.color     = Color.white;
                if (_showModes[i])
                {
                    for (int j = 0; j < device.NumModes; j++)
                    {
                        AVProLiveCameraDeviceMode mode = device.GetMode(j);
                        if (GUILayout.Button("" + mode.Width + "x" + mode.Height + " " + mode.FPS.ToString("F2") + "hz " + "[" + mode.Format + "]", _buttonStyle))
                        {
                            if (_zoomed == null)
                            {
                                // Start selected device
                                device.Close();
                                Debug.Log("Selecting mode: " + j);
                                device.Start(mode);
                            }
                        }
                    }
                }

                GUILayout.EndScrollView();


                GUILayout.EndVertical();
            }

            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            // Show zoomed camera image
            if (_zoomed != null)
            {
                Rect fullScreenRect = new Rect(0f, 0f, Screen.width, Screen.height);

                float t = Mathf.Clamp01(_zoomTimer / ZoomTime);
                t = Mathf.SmoothStep(0f, 1f, t);
                Rect r = new Rect();
                r.x      = Mathf.Lerp(_zoomSrcDest.x, fullScreenRect.x, t);
                r.y      = Mathf.Lerp(_zoomSrcDest.y, fullScreenRect.y, t);
                r.width  = Mathf.Lerp(_zoomSrcDest.width, fullScreenRect.width, t);
                r.height = Mathf.Lerp(_zoomSrcDest.height, fullScreenRect.height, t);

                if (_material != null)
                {
                    DrawTexture(r, _zoomed, ScaleMode.ScaleToFit, _material);
                }
                else
                {
                    GUI.DrawTexture(r, _zoomed, ScaleMode.ScaleToFit, false);
                }
            }
        }
    public override void OnInspectorGUI()
    {
        if (_camera == null)
        {
            return;
        }

        serializedObject.Update();

        if (!Application.isPlaying)
        {
            GUILayout.Label("Search for Capture Device:");
            EditorGUILayout.Space();

            GUILayout.BeginVertical();

            SerializedProperty propDeviceSelection = serializedObject.FindProperty("_deviceSelection");
            EditorGUILayout.PropertyField(propDeviceSelection, new GUIContent("Device Select By"));

            AVProLiveCamera.SelectDeviceBy newDeviceSelection = _camera._deviceSelection;
            switch (newDeviceSelection)
            {
            case AVProLiveCamera.SelectDeviceBy.Default:
                break;

            case AVProLiveCamera.SelectDeviceBy.Name:
                if (_camera._deviceSelection != newDeviceSelection && _camera._desiredDeviceNames.Count == 0)
                {
                    serializedObject.FindProperty("_desiredDeviceNames").arraySize++;
                    serializedObject.ApplyModifiedProperties();
                    serializedObject.FindProperty("_desiredDeviceNames").GetArrayElementAtIndex(0).stringValue = "Enter Device Name";
                    serializedObject.ApplyModifiedProperties();
                }
                EditorGUILayout.BeginVertical();
                for (int index = 0; index < _camera._desiredDeviceNames.Count; index++)
                {
                    EditorGUILayout.BeginHorizontal();


                    /*EditorGUILayout.BeginHorizontal(GUILayout.Width(96));
                     * if (index != 0)
                     * {
                     *      if (GUILayout.Button("Up"))
                     *      {
                     *              string temp = _camera._desiredDeviceNames[index - 1];
                     *              _camera._desiredDeviceNames[index - 1] = _camera._desiredDeviceNames[index];
                     *              _camera._desiredDeviceNames[index] = temp;
                     *              HandleUtility.Repaint();
                     *      }
                     * }
                     * if (index + 1 < _camera._desiredDeviceNames.Count)
                     * {
                     *      if (GUILayout.Button("Down"))
                     *      {
                     *              string temp = _camera._desiredDeviceNames[index + 1];
                     *              _camera._desiredDeviceNames[index + 1] = _camera._desiredDeviceNames[index];
                     *              _camera._desiredDeviceNames[index] = temp;
                     *              HandleUtility.Repaint();
                     *      }
                     * }
                     * EditorGUILayout.EndHorizontal();*/

                    if (GUILayout.Button("-"))
                    {
                        serializedObject.FindProperty("_desiredDeviceNames").DeleteArrayElementAtIndex(index);
                        break;
                    }
                    else
                    {
                        SerializedProperty propDesiredDeviceName = serializedObject.FindProperty("_desiredDeviceNames").GetArrayElementAtIndex(index);
                        EditorGUILayout.PropertyField(propDesiredDeviceName, new GUIContent(""), GUILayout.ExpandWidth(true));
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (GUILayout.Button("+"))
                {
                    serializedObject.FindProperty("_desiredDeviceNames").arraySize++;
                    this.Repaint();
                }
                EditorGUILayout.EndVertical();
                break;

            case AVProLiveCamera.SelectDeviceBy.Index:
            {
                SerializedProperty propDesiredDeviceIndex = serializedObject.FindProperty("_desiredDeviceIndex");
                EditorGUILayout.PropertyField(propDesiredDeviceIndex, new GUIContent(" "));
            }
            break;
            }
            GUILayout.EndVertical();
            EditorGUILayout.Space();



            GUILayout.BeginVertical();

            SerializedProperty propModeSelection = serializedObject.FindProperty("_modeSelection");
            EditorGUILayout.PropertyField(propModeSelection, new GUIContent("Mode Select By"));

            AVProLiveCamera.SelectModeBy newResolutionSelection = _camera._modeSelection;
            switch (newResolutionSelection)
            {
            case AVProLiveCamera.SelectModeBy.Default:
                break;

            case AVProLiveCamera.SelectModeBy.Resolution:
                if (_camera._modeSelection != newResolutionSelection && _camera._desiredResolutions.Count == 0)
                {
                    serializedObject.FindProperty("_desiredResolutions").arraySize++;
                }
                EditorGUILayout.BeginVertical();

                SerializedProperty propMaintainAspect = serializedObject.FindProperty("_maintainAspectRatio");
                EditorGUILayout.PropertyField(propMaintainAspect);

                for (int index = 0; index < _camera._desiredResolutions.Count; index++)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("-"))
                    {
                        serializedObject.FindProperty("_desiredResolutions").DeleteArrayElementAtIndex(index);
                        break;
                    }
                    else
                    {
                        SerializedProperty propResX = serializedObject.FindProperty("_desiredResolutions").GetArrayElementAtIndex(index).FindPropertyRelative("x");
                        EditorGUILayout.PropertyField(propResX, new GUIContent(""), GUILayout.Width(64f));

                        EditorGUILayout.LabelField("x", "", GUILayout.Width(24));

                        SerializedProperty propResY = serializedObject.FindProperty("_desiredResolutions").GetArrayElementAtIndex(index).FindPropertyRelative("y");
                        EditorGUILayout.PropertyField(propResY, new GUIContent(""), GUILayout.Width(64f));
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (GUILayout.Button("+"))
                {
                    serializedObject.FindProperty("_desiredResolutions").arraySize++;
                    this.Repaint();
                }

                EditorGUILayout.EndVertical();
                break;

            case AVProLiveCamera.SelectModeBy.Index:
            {
                SerializedProperty propDesiredModeIndex = serializedObject.FindProperty("_desiredModeIndex");
                EditorGUILayout.PropertyField(propDesiredModeIndex, new GUIContent(" "));
            }
            break;
            }
            GUILayout.EndVertical();
            EditorGUILayout.Space();



            GUILayout.BeginVertical();

            SerializedProperty propInputSelection = serializedObject.FindProperty("_videoInputSelection");
            EditorGUILayout.PropertyField(propInputSelection, new GUIContent("Video Input Select By"));

            AVProLiveCamera.SelectDeviceBy newVideoInputSelection = _camera._videoInputSelection;
            switch (newVideoInputSelection)
            {
            case AVProLiveCamera.SelectDeviceBy.Default:
                break;

            case AVProLiveCamera.SelectDeviceBy.Name:
                if (_camera._videoInputSelection != newVideoInputSelection && _camera._desiredVideoInputs.Count == 0)
                {
                    _camera._desiredVideoInputs.Add(AVProLiveCameraPlugin.VideoInput.Video_Serial_Digital);
                }
                EditorGUILayout.BeginVertical();
                for (int index = 0; index < _camera._desiredVideoInputs.Count; index++)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("-"))
                    {
                        serializedObject.FindProperty("_desiredVideoInputs").DeleteArrayElementAtIndex(index);
                        break;
                    }
                    else
                    {
                        SerializedProperty propDesiredVideoInput = serializedObject.FindProperty("_desiredVideoInputs").GetArrayElementAtIndex(index);
                        EditorGUILayout.PropertyField(propDesiredVideoInput, new GUIContent(" "));
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (GUILayout.Button("+"))
                {
                    serializedObject.FindProperty("_desiredVideoInputs").arraySize++;
                    this.Repaint();
                }
                EditorGUILayout.EndVertical();
                break;

            case AVProLiveCamera.SelectDeviceBy.Index:
            {
                SerializedProperty propDesiredVideoInputIndex = serializedObject.FindProperty("_desiredVideoInputIndex");
                EditorGUILayout.PropertyField(propDesiredVideoInputIndex, new GUIContent(" "));
            }
            break;
            }
            GUILayout.EndVertical();
            EditorGUILayout.Space();

            SerializedProperty propPlayOnStart = serializedObject.FindProperty("_playOnStart");
            EditorGUILayout.PropertyField(propPlayOnStart);

            SerializedProperty propDeinterlace = serializedObject.FindProperty("_deinterlace");
            EditorGUILayout.PropertyField(propDeinterlace);
        }
        else
        {
            if (_camera.Device != null)
            {
                _preview = GUILayout.Toggle(_preview, "Inspector Preview");

                AVProLiveCameraDevice device = _camera.Device;


                if (_preview && device.OutputTexture != null)
                {
                    Rect textureRect = GUILayoutUtility.GetRect(64.0f, 64.0f, GUILayout.MinWidth(64.0f), GUILayout.MinHeight(64.0f));
                    GUI.DrawTexture(textureRect, device.OutputTexture, ScaleMode.ScaleToFit, false);
                }

                GUILayout.Label("Device: " + device.Name);
                GUILayout.Label(string.Format("Mode: {0}x{1} {2}", device.CurrentWidth, device.CurrentHeight, device.CurrentFormat));

                if (device.FramesTotal > 30)
                {
                    GUILayout.Label("Displaying at " + device.DisplayFPS.ToString("F1") + " fps");
                }
                else
                {
                    GUILayout.Label("Displaying at ... fps");
                }

                if (device.IsRunning)
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Stop Camera"))
                    {
                        device.Close();
                    }
                    if (device.IsPaused)
                    {
                        if (GUILayout.Button("Unpause Stream"))
                        {
                            device.Play();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Pause Stream"))
                        {
                            device.Pause();
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    if (GUILayout.Button("Start Camera"))
                    {
                        _camera.Begin();
                    }
                }

                GUI.enabled = device.CanShowConfigWindow();
                if (GUILayout.Button("Show Config Window"))
                {
                    device.ShowConfigWindow();
                }
                GUI.enabled = true;

                _showSettings = GUILayout.Toggle(_showSettings, "Show Settings");
                if (_showSettings && device.NumSettings > 0)
                {
                    EditorGUILayout.PrefixLabel("Device Settings", EditorStyles.boldLabel);
                    EditorGUI.BeginChangeCheck();
                    for (int j = 0; j < device.NumSettings; j++)
                    {
                        AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                        GUILayout.BeginHorizontal();
                        GUI.enabled = !settingBase.IsAutomatic;
                        if (GUILayout.Button("D", GUILayout.ExpandWidth(false)))
                        {
                            settingBase.SetDefault();
                        }
                        GUI.enabled = true;
                        GUILayout.Label(settingBase.Name, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(96.0f));
                        GUI.enabled = !settingBase.IsAutomatic;
                        switch (settingBase.DataTypeValue)
                        {
                        case AVProLiveCameraSettingBase.DataType.Boolean:
                            AVProLiveCameraSettingBoolean settingBool = (AVProLiveCameraSettingBoolean)settingBase;
                            settingBool.CurrentValue = GUILayout.Toggle(settingBool.CurrentValue, "", GUILayout.ExpandWidth(true));
                            break;

                        case AVProLiveCameraSettingBase.DataType.Float:
                            AVProLiveCameraSettingFloat settingFloat = (AVProLiveCameraSettingFloat)settingBase;
                            float sliderValue = GUILayout.HorizontalSlider(settingFloat.CurrentValue, settingFloat.MinValue, settingFloat.MaxValue, GUILayout.ExpandWidth(true));
                            if (GUI.enabled)
                            {
                                settingFloat.CurrentValue = sliderValue;
                            }

                            GUILayout.Label(((long)settingFloat.CurrentValue).ToString(), GUILayout.Width(32.0f), GUILayout.ExpandWidth(false));
                            GUI.enabled             = settingBase.CanAutomatic;
                            settingBase.IsAutomatic = GUILayout.Toggle(settingBase.IsAutomatic, "", GUILayout.Width(32.0f));
                            GUI.enabled             = true;
                            break;
                        }
                        GUI.enabled = true;
                        GUILayout.EndHorizontal();
                    }
                    if (GUILayout.Button("Defaults"))
                    {
                        for (int j = 0; j < device.NumSettings; j++)
                        {
                            AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                            settingBase.SetDefault();
                        }
                    }
                    if (EditorGUI.EndChangeCheck() || (Time.frameCount % 30) == 0)
                    {
                        // This is an expensive function call so we want to limit it
                        device.Update_Settings();
                    }
                }
                //EditorGUILayout.Toggle("Running:", device.IsRunning);
            }

#if !AVPROLIVECAMERA_UNITYFEATURE_EDITORAUTOREFRESH
            if (_preview)
            {
                //HandleUtility.Repaint();
                this.Repaint();
            }
#endif
        }

        GUI.enabled = true;

        EditorGUILayout.PropertyField(_propFlipX);
        EditorGUILayout.PropertyField(_propFlipY);

        EditorGUILayout.Space();

        EditorGUILayout.PropertyField(_propHotSwap);
        EditorGUILayout.PropertyField(_propFrameRates);
        EditorGUILayout.PropertyField(_propSettings);

        if (GUI.changed)
        {
            EditorUtility.SetDirty(_camera);
        }

        serializedObject.ApplyModifiedProperties();
    }