VideoRecordConfigPanel.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. using NRKernal.Record;
  10. using System;
  11. using System.Collections.Generic;
  12. using UnityEngine;
  13. using UnityEngine.UI;
  14. namespace NRKernal.NRExamples
  15. {
  16. public class VideoRecordConfigPanel : MonoBehaviour
  17. {
  18. [SerializeField]
  19. private VideoCapture2LocalExample m_VideoCapture2LocalExample;
  20. [SerializeField]
  21. private Dropdown m_QualityDropDown;
  22. [SerializeField]
  23. private Dropdown m_RenderModeDropDown;
  24. [SerializeField]
  25. private Dropdown m_AudioStateDropDown;
  26. [SerializeField]
  27. private Toggle m_UseGreenBGToggle;
  28. List<string> _ResolutionOptions = new List<string>() {
  29. VideoCapture2LocalExample.ResolutionLevel.High.ToString(),
  30. VideoCapture2LocalExample.ResolutionLevel.Middle.ToString(),
  31. VideoCapture2LocalExample.ResolutionLevel.Low.ToString()
  32. };
  33. List<string> _RendermodeOptions = new List<string>() {
  34. BlendMode.Blend.ToString(),
  35. BlendMode.RGBOnly.ToString(),
  36. BlendMode.VirtualOnly.ToString()
  37. };
  38. List<string> _AudioStateOptions = new List<string>() {
  39. NRVideoCapture.AudioState.MicAudio.ToString(),
  40. NRVideoCapture.AudioState.ApplicationAudio.ToString(),
  41. NRVideoCapture.AudioState.ApplicationAndMicAudio.ToString(),
  42. NRVideoCapture.AudioState.None.ToString()
  43. };
  44. void Start()
  45. {
  46. InitConfigPanel();
  47. }
  48. private void InitConfigPanel()
  49. {
  50. m_QualityDropDown.options.Clear();
  51. m_QualityDropDown.AddOptions(_ResolutionOptions);
  52. int default_quality_index = 0;
  53. for (int i = 0; i < _ResolutionOptions.Count; i++)
  54. {
  55. if (_ResolutionOptions[i].Equals(m_VideoCapture2LocalExample.resolutionLevel.ToString()))
  56. {
  57. default_quality_index = i;
  58. }
  59. }
  60. m_QualityDropDown.value = default_quality_index;
  61. m_QualityDropDown.onValueChanged.AddListener((index) =>
  62. {
  63. Enum.TryParse<VideoCapture2LocalExample.ResolutionLevel>(_ResolutionOptions[index],
  64. out m_VideoCapture2LocalExample.resolutionLevel);
  65. });
  66. m_RenderModeDropDown.options.Clear();
  67. m_RenderModeDropDown.AddOptions(_RendermodeOptions);
  68. int default_blendmode_index = 0;
  69. for (int i = 0; i < _RendermodeOptions.Count; i++)
  70. {
  71. if (_RendermodeOptions[i].Equals(m_VideoCapture2LocalExample.blendMode.ToString()))
  72. {
  73. default_blendmode_index = i;
  74. }
  75. }
  76. m_RenderModeDropDown.value = default_blendmode_index;
  77. m_RenderModeDropDown.onValueChanged.AddListener((index) =>
  78. {
  79. Enum.TryParse<BlendMode>(_RendermodeOptions[index],
  80. out m_VideoCapture2LocalExample.blendMode);
  81. });
  82. m_AudioStateDropDown.options.Clear();
  83. m_AudioStateDropDown.AddOptions(_AudioStateOptions);
  84. int default_audiostate_index = 0;
  85. for (int i = 0; i < _AudioStateOptions.Count; i++)
  86. {
  87. if (_AudioStateOptions[i].Equals(m_VideoCapture2LocalExample.audioState.ToString()))
  88. {
  89. default_audiostate_index = i;
  90. }
  91. }
  92. m_AudioStateDropDown.value = default_audiostate_index;
  93. m_AudioStateDropDown.onValueChanged.AddListener((index) =>
  94. {
  95. Enum.TryParse<NRVideoCapture.AudioState>(_AudioStateOptions[index],
  96. out m_VideoCapture2LocalExample.audioState);
  97. });
  98. m_UseGreenBGToggle.isOn = m_VideoCapture2LocalExample.useGreenBackGround;
  99. m_UseGreenBGToggle.onValueChanged.AddListener((val) =>
  100. {
  101. m_VideoCapture2LocalExample.useGreenBackGround = val;
  102. });
  103. }
  104. }
  105. }