using System; using System.Collections.Generic; namespace UnityEngine.Rendering { /// /// Bridge class for camera captures. /// public static class CameraCaptureBridge { private class CameraEntry { internal HashSet> actions; internal IEnumerator> cachedEnumerator; } private static Dictionary actionDict = new(); private static bool _enabled; /// /// Enable camera capture. /// public static bool enabled { get { return _enabled; } set { _enabled = value; } } /// /// Provides the set actions to the renderer to be triggered at the end of the render loop for camera capture /// /// The camera to get actions for /// Enumeration of actions public static IEnumerator> GetCaptureActions(Camera camera) { if (!actionDict.TryGetValue(camera, out var entry) || entry.actions.Count == 0) return null; return entry.actions.GetEnumerator(); } internal static IEnumerator> GetCachedCaptureActionsEnumerator(Camera camera) { if (!actionDict.TryGetValue(camera, out var entry) || entry.actions.Count == 0) return null; // internal use only entry.cachedEnumerator.Reset(); return entry.cachedEnumerator; } /// /// Adds actions for camera capture /// /// The camera to add actions for /// The action to add public static void AddCaptureAction(Camera camera, Action action) { actionDict.TryGetValue(camera, out var entry); if (entry == null) { entry = new CameraEntry {actions = new HashSet>()}; actionDict.Add(camera, entry); } entry.actions.Add(action); entry.cachedEnumerator = entry.actions.GetEnumerator(); } /// /// Removes actions for camera capture /// /// The camera to remove actions for /// The action to remove public static void RemoveCaptureAction(Camera camera, Action action) { if (camera == null) return; if (actionDict.TryGetValue(camera, out var entry)) { entry.actions.Remove(action); entry.cachedEnumerator = entry.actions.GetEnumerator(); } } } }