ImageEffectBase.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. namespace UnityStandardAssets.ImageEffects
  4. {
  5. [RequireComponent(typeof (Camera))]
  6. [AddComponentMenu("")]
  7. public class ImageEffectBase : MonoBehaviour
  8. {
  9. /// Provides a shader property that is set in the inspector
  10. /// and a material instantiated from the shader
  11. public Shader shader;
  12. private Material m_Material;
  13. protected virtual void Start()
  14. {
  15. // Disable the image effect if the shader can't
  16. // run on the users graphics card
  17. if (!shader || !shader.isSupported)
  18. enabled = false;
  19. }
  20. protected Material material
  21. {
  22. get
  23. {
  24. if (m_Material == null)
  25. {
  26. m_Material = new Material(shader);
  27. m_Material.hideFlags = HideFlags.HideAndDontSave;
  28. }
  29. return m_Material;
  30. }
  31. }
  32. protected virtual void OnDisable()
  33. {
  34. if (m_Material)
  35. {
  36. DestroyImmediate(m_Material);
  37. }
  38. }
  39. }
  40. }