using System;
using System.Reflection;
using Unity.Collections;
namespace UnityEngine.Rendering.Universal
{
///
/// Defines the compatiblility with a set of renderer(s)
///
[AttributeUsage(AttributeTargets.Class)]
public class SupportedOnRendererAttribute : Attribute
{
///
/// Returns the compatible renderers
///
public Type[] rendererTypes { get; }
///
/// Sets a compatible renderer
///
/// The compatible renderer to set.
public SupportedOnRendererAttribute(Type renderer)
: this(new[] { renderer }) {}
///
/// Sets one or more compatible renderers
///
/// The compatible renderer(s) to set.
public SupportedOnRendererAttribute(params Type[] renderers)
{
if (renderers == null)
{
Debug.LogError($"The {nameof(SupportedOnRendererAttribute)} parameters cannot be null.");
return;
}
for (var i = 0; i < renderers.Length; i++)
{
var r = renderers[i];
if (r == null || !typeof(ScriptableRendererData).IsAssignableFrom(r))
{
Debug.LogError($"The {nameof(SupportedOnRendererAttribute)} Attribute targets an invalid {nameof(ScriptableRendererData)}. One of the types cannot be assigned from {nameof(ScriptableRendererData)}");
return;
}
}
rendererTypes = renderers;
}
}
}