CameraCapture.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Rendering;
  5. namespace UnityEditor.Recorder.Input
  6. {
  7. internal static class CameraCapture
  8. {
  9. private static Dictionary<Camera, HashSet<Action<RenderTargetIdentifier, CommandBuffer> > > actionDict =
  10. new Dictionary<Camera, HashSet<Action<RenderTargetIdentifier, CommandBuffer> > >();
  11. public static IEnumerator<Action<RenderTargetIdentifier, CommandBuffer> > GetActions(Camera camera)
  12. {
  13. HashSet<Action<RenderTargetIdentifier, CommandBuffer> > actions;
  14. if (!actionDict.TryGetValue(camera, out actions))
  15. return null;
  16. return actions.GetEnumerator();
  17. }
  18. public static void AddCaptureAction(Camera camera, Action<RenderTargetIdentifier, CommandBuffer> action)
  19. {
  20. HashSet<Action<RenderTargetIdentifier, CommandBuffer> > actions = null;
  21. actionDict.TryGetValue(camera, out actions);
  22. if (actions == null)
  23. {
  24. actions = new HashSet<Action<RenderTargetIdentifier, CommandBuffer> >();
  25. actionDict.Add(camera, actions);
  26. }
  27. actions.Add(action);
  28. }
  29. public static void RemoveCaptureAction(Camera camera, Action<RenderTargetIdentifier, CommandBuffer> action)
  30. {
  31. if (camera == null)
  32. return;
  33. HashSet<Action<RenderTargetIdentifier, CommandBuffer> > actions;
  34. if (actionDict.TryGetValue(camera, out actions))
  35. actions.Remove(action);
  36. }
  37. }
  38. }