AutoLoadPipelineAsset.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4. [ExecuteAlways]
  5. public class AutoLoadPipelineAsset : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private UniversalRenderPipelineAsset m_PipelineAsset;
  9. private RenderPipelineAsset m_PreviousPipelineAsset;
  10. private bool m_overrodeQualitySettings;
  11. void OnEnable()
  12. {
  13. UpdatePipeline();
  14. }
  15. void OnDisable()
  16. {
  17. ResetPipeline();
  18. }
  19. private void UpdatePipeline()
  20. {
  21. if (m_PipelineAsset)
  22. {
  23. if (QualitySettings.renderPipeline != null && QualitySettings.renderPipeline != m_PipelineAsset)
  24. {
  25. m_PreviousPipelineAsset = QualitySettings.renderPipeline;
  26. QualitySettings.renderPipeline = m_PipelineAsset;
  27. m_overrodeQualitySettings = true;
  28. }
  29. else if (GraphicsSettings.renderPipelineAsset != m_PipelineAsset)
  30. {
  31. m_PreviousPipelineAsset = GraphicsSettings.renderPipelineAsset;
  32. GraphicsSettings.renderPipelineAsset = m_PipelineAsset;
  33. m_overrodeQualitySettings = false;
  34. }
  35. }
  36. }
  37. private void ResetPipeline()
  38. {
  39. if (m_PreviousPipelineAsset)
  40. {
  41. if (m_overrodeQualitySettings)
  42. {
  43. QualitySettings.renderPipeline = m_PreviousPipelineAsset;
  44. }
  45. else
  46. {
  47. GraphicsSettings.renderPipelineAsset = m_PreviousPipelineAsset;
  48. }
  49. }
  50. }
  51. }