ScreenCaptureDemo.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using UnityEngine;
  2. //-----------------------------------------------------------------------------
  3. // Copyright 2012-2017 RenderHeads Ltd. All rights reserved.
  4. //-----------------------------------------------------------------------------
  5. namespace RenderHeads.Media.AVProMovieCapture.Demos
  6. {
  7. public class ScreenCaptureDemo : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private AudioClip _audioBG;
  11. [SerializeField]
  12. private AudioClip _audioHit;
  13. [SerializeField]
  14. private float _speed = 1.0f;
  15. [SerializeField]
  16. private CaptureBase _capture;
  17. [SerializeField]
  18. private GUISkin _guiSkin;
  19. [SerializeField]
  20. private bool _spinCamera = true;
  21. // State
  22. private float _timer;
  23. private void Start()
  24. {
  25. // Play music track
  26. if (_audioBG != null)
  27. {
  28. AudioSource.PlayClipAtPoint(_audioBG, Vector3.zero);
  29. }
  30. }
  31. private void Update()
  32. {
  33. // Press the S key to trigger audio and background color change - useful for testing A/V sync
  34. if (Input.GetKeyDown(KeyCode.S))
  35. {
  36. if (_audioHit != null && _capture.IsCapturing())
  37. {
  38. AudioSource.PlayClipAtPoint(_audioHit, Vector3.zero);
  39. Camera.main.backgroundColor = new Color(Random.value, Random.value, Random.value, 0);
  40. }
  41. }
  42. // ESC to stop capture and quit
  43. if (Input.GetKeyDown(KeyCode.Escape))
  44. {
  45. if (_capture != null && _capture.IsCapturing())
  46. {
  47. _capture.StopCapture();
  48. }
  49. else
  50. {
  51. Application.Quit();
  52. }
  53. }
  54. // Spin the camera around
  55. if (_spinCamera && Camera.main != null)
  56. {
  57. Camera.main.transform.RotateAround(Vector3.zero, Vector3.up, 20f * Time.deltaTime * _speed);
  58. }
  59. }
  60. private void OnGUI()
  61. {
  62. GUI.skin = _guiSkin;
  63. Rect r = new Rect(Screen.width - 108, 64, 128, 28);
  64. GUI.Label(r, "Frame " + Time.frameCount);
  65. }
  66. }
  67. }