#if ENABLE_UPSCALER_FRAMEWORK
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEditor;
namespace UnityEngine.Rendering
{
#nullable enable
///
/// Manages the lifecycle of cached editors for UpscalerOptions ScriptableObjects.
///
public class UpscalerOptionsEditorCache
{
private readonly Dictionary m_EditorCache = new Dictionary();
///
/// Gets a cached editor for the given @options. If the editor is not
/// found in the cache, a new editor is created and then cached.
///
public Editor? GetOrCreateEditor(ScriptableObject options)
{
if (options == null)
return null;
if (!m_EditorCache.TryGetValue(options, out var editor) || editor == null)
{
editor = Editor.CreateEditor(options);
m_EditorCache[options] = editor;
}
return editor;
}
///
/// Destroys all cached editor instances.
/// Call this from the parent editor's OnDisable method.
///
public void Cleanup()
{
foreach (var editor in m_EditorCache.Values)
{
if (editor != null)
Object.DestroyImmediate(editor);
}
m_EditorCache.Clear();
}
}
#nullable disable
}
#endif
#endif // ENABLE_UPSCALER_FRAMEWORK