public void Begin() { SelectDeviceAndMode(); if (_device != null) { _device.Deinterlace = _deinterlace; if (!_device.Start(_mode, _videoInput)) { Debug.LogWarning("[AVPro Live Camera] Device failed to start."); _device.Close(); _device = null; _mode = null; _videoInput = -1; } } }
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); } } }