- ImageEffectBase.cs
- Scripts /
- ImageEffects /
- Effects /
- Standard Assets /
- Assets /
- project /
1 using System;
2 using UnityEngine;
3
4 namespace UnityStandardAssets.ImageEffects
5 {
6 [RequireComponent(typeof (Camera))]
7 [AddComponentMenu("")]
8 public class ImageEffectBase : MonoBehaviour
9 {
10 /// Provides a shader property that is set in the inspector
11 /// and a material instantiated from the shader
12 public Shader shader;
13
14 private Material m_Material;
15
16
17 protected virtual void Start()
18 {
19 // Disable if we don't support image effects
20 if (!SystemInfo.supportsImageEffects)
21 {
22 enabled = false;
23 return;
24 }
25
26 // Disable the image effect if the shader can't
27 // run on the users graphics card
28 if (!shader || !shader.isSupported)
29 enabled = false;
30 }
31
32
33 protected Material material
34 {
35 get
36 {
37 if (m_Material == null)
38 {
39 m_Material = new Material(shader);
40 m_Material.hideFlags = HideFlags.HideAndDontSave;
41 }
42 return m_Material;
43 }
44 }
45
46
47 protected virtual void OnDisable()
48 {
49 if (m_Material)
50 {
51 DestroyImmediate(m_Material);
52 }
53 }
54 }
55 }
2 using UnityEngine;
3
4 namespace UnityStandardAssets.ImageEffects
5 {
6 [RequireComponent(typeof (Camera))]
7 [AddComponentMenu("")]
8 public class ImageEffectBase : MonoBehaviour
9 {
10 /// Provides a shader property that is set in the inspector
11 /// and a material instantiated from the shader
12 public Shader shader;
13
14 private Material m_Material;
15
16
17 protected virtual void Start()
18 {
19 // Disable if we don't support image effects
20 if (!SystemInfo.supportsImageEffects)
21 {
22 enabled = false;
23 return;
24 }
25
26 // Disable the image effect if the shader can't
27 // run on the users graphics card
28 if (!shader || !shader.isSupported)
29 enabled = false;
30 }
31
32
33 protected Material material
34 {
35 get
36 {
37 if (m_Material == null)
38 {
39 m_Material = new Material(shader);
40 m_Material.hideFlags = HideFlags.HideAndDontSave;
41 }
42 return m_Material;
43 }
44 }
45
46
47 protected virtual void OnDisable()
48 {
49 if (m_Material)
50 {
51 DestroyImmediate(m_Material);
52 }
53 }
54 }
55 }