summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Editor/UIEffectEditor.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-04-07 21:33:14 +0800
committerchai <chaifix@163.com>2021-04-07 21:33:14 +0800
commitc47b92e92cf33ae8bf2f38929e137294397e4735 (patch)
treec67ae3419eaf15e84f1679186e107f598de33978 /Assets/Scripts/Editor/UIEffectEditor.cs
Diffstat (limited to 'Assets/Scripts/Editor/UIEffectEditor.cs')
-rw-r--r--Assets/Scripts/Editor/UIEffectEditor.cs114
1 files changed, 114 insertions, 0 deletions
diff --git a/Assets/Scripts/Editor/UIEffectEditor.cs b/Assets/Scripts/Editor/UIEffectEditor.cs
new file mode 100644
index 0000000..028ee73
--- /dev/null
+++ b/Assets/Scripts/Editor/UIEffectEditor.cs
@@ -0,0 +1,114 @@
+using UnityEditor;
+using UnityEditorInternal;
+using UnityEngine;
+using System.Linq;
+using System;
+
+namespace Coffee.UIEffects.Editors
+{
+ /// <summary>
+ /// UIEffect editor.
+ /// </summary>
+ [CustomEditor(typeof(UIEffect))]
+ [CanEditMultipleObjects]
+ public class UIEffectEditor : Editor
+ {
+ SerializedProperty _spEffectMode;
+ SerializedProperty _spEffectFactor;
+ SerializedProperty _spColorMode;
+ SerializedProperty _spColorFactor;
+ SerializedProperty _spBlurMode;
+ SerializedProperty _spBlurFactor;
+ SerializedProperty _spAdvancedBlur;
+
+ protected void OnEnable()
+ {
+ _spEffectMode = serializedObject.FindProperty("m_EffectMode");
+ _spEffectFactor = serializedObject.FindProperty("m_EffectFactor");
+ _spColorMode = serializedObject.FindProperty("m_ColorMode");
+ _spColorFactor = serializedObject.FindProperty("m_ColorFactor");
+ _spBlurMode = serializedObject.FindProperty("m_BlurMode");
+ _spBlurFactor = serializedObject.FindProperty("m_BlurFactor");
+ _spAdvancedBlur = serializedObject.FindProperty("m_AdvancedBlur");
+ }
+
+ public override void OnInspectorGUI()
+ {
+ //================
+ // Effect setting.
+ //================
+ using (new MaterialDirtyScope(targets))
+ EditorGUILayout.PropertyField(_spEffectMode);
+
+ // When effect is enable, show parameters.
+ if (_spEffectMode.intValue != (int) EffectMode.None)
+ {
+ EditorGUI.indentLevel++;
+ EditorGUILayout.PropertyField(_spEffectFactor);
+ EditorGUI.indentLevel--;
+ }
+
+
+ //================
+ // Color setting.
+ //================
+ using (new MaterialDirtyScope(targets))
+ EditorGUILayout.PropertyField(_spColorMode);
+
+ // When color is enable, show parameters.
+ {
+ EditorGUI.indentLevel++;
+ EditorGUILayout.PropertyField(_spColorFactor);
+ EditorGUI.indentLevel--;
+ }
+
+
+ //================
+ // Blur setting.
+ //================
+ using (new MaterialDirtyScope(targets))
+ EditorGUILayout.PropertyField(_spBlurMode);
+
+ // When blur is enable, show parameters.
+ if (_spBlurMode.intValue != (int) BlurMode.None)
+ {
+ EditorGUI.indentLevel++;
+ EditorGUILayout.PropertyField(_spBlurFactor);
+
+ // When you change a property, it marks the material as dirty.
+ using (new MaterialDirtyScope(targets))
+ EditorGUILayout.PropertyField(_spAdvancedBlur);
+ EditorGUI.indentLevel--;
+
+ // Advanced blur requires uv2 channel.
+ if (_spAdvancedBlur.boolValue)
+ {
+ ShowCanvasChannelsWarning();
+ }
+ }
+
+ serializedObject.ApplyModifiedProperties();
+ }
+
+ void ShowCanvasChannelsWarning()
+ {
+ var effect = target as UIEffect;
+ if (effect == null || !effect.graphic) return;
+
+ var channel = effect.uvMaskChannel;
+ var canvas = effect.graphic.canvas;
+ if (canvas == null || (canvas.additionalShaderChannels & channel) == channel) return;
+
+ EditorGUILayout.BeginHorizontal();
+ {
+ var msg = string.Format("Enable '{0}' of Canvas.additionalShaderChannels to use 'UIEffect'.", channel);
+ EditorGUILayout.HelpBox(msg, MessageType.Warning);
+ if (GUILayout.Button("Fix"))
+ {
+ canvas.additionalShaderChannels |= channel;
+ }
+ }
+ EditorGUILayout.EndHorizontal();
+ }
+ }
+}