ScriptableRendererFeature.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine.Scripting.APIUpdating;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. /// <summary>
  5. /// You can add a <c>ScriptableRendererFeature</c> to the <c>ScriptableRenderer</c>. Use this scriptable renderer feature to inject render passes into the renderer.
  6. /// </summary>
  7. /// <seealso cref="ScriptableRenderer"/>
  8. /// <seealso cref="ScriptableRenderPass"/>
  9. [ExcludeFromPreset]
  10. [MovedFrom("UnityEngine.Rendering.LWRP")] public abstract class ScriptableRendererFeature : ScriptableObject
  11. {
  12. [SerializeField, HideInInspector] private bool m_Active = true;
  13. /// <summary>
  14. /// Returns the state of the ScriptableRenderFeature (true: the feature is active, false: the feature is inactive). Use the method ScriptableRenderFeature.SetActive to change the value of this variable.
  15. /// </summary>
  16. public bool isActive => m_Active;
  17. /// <summary>
  18. /// Initializes this feature's resources. This is called every time serialization happens.
  19. /// </summary>
  20. public abstract void Create();
  21. /// <summary>
  22. /// Injects one or multiple <c>ScriptableRenderPass</c> in the renderer.
  23. /// </summary>
  24. /// <param name="renderPasses">List of render passes to add to.</param>
  25. /// <param name="renderingData">Rendering state. Use this to setup render passes.</param>
  26. public abstract void AddRenderPasses(ScriptableRenderer renderer,
  27. ref RenderingData renderingData);
  28. void OnEnable()
  29. {
  30. Create();
  31. }
  32. void OnValidate()
  33. {
  34. Create();
  35. }
  36. /// <summary>
  37. /// Sets the state of ScriptableRenderFeature (true: the feature is active, false: the feature is inactive).
  38. /// If the feature is active, it is added to the renderer it is attached to, otherwise the feature is skipped while rendering.
  39. /// </summary>
  40. /// <param name="active">The true value activates the ScriptableRenderFeature and the false value deactivates it.</param>
  41. public void SetActive(bool active)
  42. {
  43. m_Active = active;
  44. }
  45. }
  46. }