summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs')
-rw-r--r--Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs56
1 files changed, 56 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs
new file mode 100644
index 00000000..bf9e66e2
--- /dev/null
+++ b/Client/Assets/Scripts/XEditor/XSkillEditor/Effect/ImageEffectBase.cs
@@ -0,0 +1,56 @@
+#if UNITY_EDITOR
+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 m_shader;
+ private Material m_Material;
+ protected string m_shaderName = "Mobile/Diffuse";
+ protected virtual 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;
+ }
+ public virtual Shader shader
+ {
+ get
+ {
+ if (m_shader == null)
+ {
+ m_shader = Shader.Find(m_shaderName);
+ }
+ return m_shader;
+ }
+ set
+ {
+ m_shader = value;
+ }
+ }
+ protected Material material {
+ get {
+ if (m_Material == null) {
+ m_Material = new Material (shader);
+ m_Material.hideFlags = HideFlags.HideAndDontSave;
+ }
+ return m_Material;
+ }
+ }
+
+ protected virtual void OnDisable() {
+ if( m_Material ) {
+ DestroyImmediate( m_Material );
+ }
+ }
+}
+#endif \ No newline at end of file