ImageEffectBase.cs 889 B

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