Skip to content

Instantly share code, notes, and snippets.

@opless
Created April 9, 2015 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opless/dce9b6a6343fcbd30db8 to your computer and use it in GitHub Desktop.
Save opless/dce9b6a6343fcbd30db8 to your computer and use it in GitHub Desktop.
ImageEffectBase.cs
using UnityEngine;
[RequireComponent (typeof(Camera))]
[AddComponentMenu("")]
public class ImageEffectBase : MonoBehaviour
{
/// Provides a shader property that is set in the inspector
/// and a material instantiated from the shader
public Shader shader;
private Material m_Material;
virtual protected void Start ()
{
// Disable if we don't support image effects
if (!SystemInfo.supportsImageEffects) {
enabled = false;
return;
}
// Disable the image effect if the shader can't
// run on the users graphics card
if (!shader || !shader.isSupported)
enabled = false;
}
protected Material material {
get {
if (m_Material == null) {
m_Material = new Material (shader);
m_Material.hideFlags = HideFlags.HideAndDontSave;
}
return m_Material;
}
}
virtual protected void OnDisable ()
{
if (m_Material) {
DestroyImmediate (m_Material);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment