diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common.meta
new file mode 100644
index 00000000..36580c4a
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 04feaefc7cdee4c13abcd553a1a6e3a9
+folderAsset: yes
+timeCreated: 1528368324
+licenseType: Pro
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/BlurMode.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/BlurMode.cs
new file mode 100644
index 00000000..fcc3cab6
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/BlurMode.cs
@@ -0,0 +1,13 @@
+namespace Coffee.UIExtensions
+{
+ ///
+ /// Blur effect mode.
+ ///
+ public enum BlurMode
+ {
+ None = 0,
+ FastBlur = 1,
+ MediumBlur = 2,
+ DetailBlur = 3,
+ }
+}
\ No newline at end of file
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/BlurMode.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/BlurMode.cs.meta
new file mode 100644
index 00000000..504b62a0
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/BlurMode.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 5645838b01af8764d8f381f04b62b9a2
+timeCreated: 1528296875
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ColorMode.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ColorMode.cs
new file mode 100644
index 00000000..8a7aae4c
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ColorMode.cs
@@ -0,0 +1,13 @@
+namespace Coffee.UIExtensions
+{
+ ///
+ /// Color effect mode.
+ ///
+ public enum ColorMode
+ {
+ Multiply = 0,
+ Fill = 1,
+ Add = 2,
+ Subtract = 3,
+ }
+}
\ No newline at end of file
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ColorMode.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ColorMode.cs.meta
new file mode 100644
index 00000000..ba60cab4
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ColorMode.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e6ba1e487e0a19644afde2bd5531bd04
+timeCreated: 1528296875
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/MaterialResolver.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/MaterialResolver.cs
new file mode 100644
index 00000000..91f31664
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/MaterialResolver.cs
@@ -0,0 +1,103 @@
+#if UNITY_EDITOR
+using System.IO;
+using System.Linq;
+using System.Text;
+using UnityEditor;
+using UnityEngine;
+
+namespace Coffee.UIExtensions
+{
+ public class MaterialResolver
+ {
+ static readonly StringBuilder s_StringBuilder = new StringBuilder ();
+
+ public static Material GetOrGenerateMaterialVariant (Shader shader, params object[] append)
+ {
+ if (!shader) {
+ return null;
+ }
+
+ string[] keywords = append.Where (x => 0 < (int)x)
+ .Select (x => x.ToString ().ToUpper ())
+ .ToArray ();
+ Material mat = GetMaterial (shader, append);
+ if (mat) {
+ if(!mat.shaderKeywords.OrderBy(x=>x).SequenceEqual(keywords.OrderBy(x=>x)))
+ {
+ mat.shaderKeywords = keywords;
+ EditorUtility.SetDirty (mat);
+ if (!Application.isPlaying)
+ {
+ EditorApplication.delayCall += AssetDatabase.SaveAssets;
+ }
+ }
+ return mat;
+ }
+
+ var variantName = GetVariantName (shader, append);
+ Debug.Log ("Generate material : " + variantName);
+ mat = new Material (shader);
+ mat.shaderKeywords = keywords;
+
+ mat.name = variantName;
+ mat.hideFlags |= HideFlags.NotEditable;
+
+#if UIEFFECT_SEPARATE
+ string dir = Path.GetDirectoryName(GetDefaultMaterialPath (shader));
+ string materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat");
+
+ Directory.CreateDirectory (Path.GetDirectoryName (materialPath));
+ AssetDatabase.CreateAsset (mat, materialPath);
+ AssetDatabase.SaveAssets ();
+#else
+ if (append.Cast ().All (x => x == 0)) {
+ string materialPath = GetDefaultMaterialPath (shader);
+ Directory.CreateDirectory (Path.GetDirectoryName (materialPath));
+ AssetDatabase.CreateAsset (mat, materialPath);
+ AssetDatabase.SaveAssets ();
+ } else {
+ GetOrGenerateMaterialVariant (shader);
+ string materialPath = GetDefaultMaterialPath (shader);
+ mat.hideFlags |= HideFlags.HideInHierarchy;
+ AssetDatabase.AddObjectToAsset (mat, materialPath);
+ }
+#endif
+ return mat;
+ }
+
+ public static Material GetMaterial (Shader shader, params object[] append)
+ {
+ string variantName = GetVariantName (shader, append);
+ return AssetDatabase.FindAssets ("t:Material " + Path.GetFileName (shader.name))
+ .Select (x => AssetDatabase.GUIDToAssetPath (x))
+ .SelectMany (x => AssetDatabase.LoadAllAssetsAtPath (x))
+ .OfType ()
+ .FirstOrDefault (x => x.name == variantName);
+ }
+
+ public static string GetDefaultMaterialPath (Shader shader)
+ {
+ var name = Path.GetFileName (shader.name);
+ return AssetDatabase.FindAssets ("t:Material " + name)
+ .Select (x => AssetDatabase.GUIDToAssetPath (x))
+ .FirstOrDefault (x => Path.GetFileNameWithoutExtension (x) == name)
+ ?? ("Assets/" + name + ".mat");
+ }
+
+ public static string GetVariantName (Shader shader, params object[] append)
+ {
+ s_StringBuilder.Length = 0;
+
+#if UIEFFECT_SEPARATE
+ s_StringBuilder.Append("[Separated] ");
+#endif
+ s_StringBuilder.Append (Path.GetFileName (shader.name));
+ foreach (object mode in append.Where(x=>0<(int)x)) {
+ s_StringBuilder.Append ("-");
+ s_StringBuilder.Append (mode.ToString ());
+ }
+ return s_StringBuilder.ToString ();
+ }
+ }
+}
+#endif
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/MaterialResolver.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/MaterialResolver.cs.meta
new file mode 100644
index 00000000..6e5717fb
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/MaterialResolver.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 70261fa2760d4c040ac28aebb1f155fb
+timeCreated: 1528297353
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Matrix2x3.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Matrix2x3.cs
similarity index 100%
rename from Assets/Coffee/UIExtensions/UIEffect/Scripts/Matrix2x3.cs
rename to Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Matrix2x3.cs
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Matrix2x3.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Matrix2x3.cs.meta
similarity index 100%
rename from Assets/Coffee/UIExtensions/UIEffect/Scripts/Matrix2x3.cs.meta
rename to Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Matrix2x3.cs.meta
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Packer.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Packer.cs
similarity index 100%
rename from Assets/Coffee/UIExtensions/UIEffect/Scripts/Packer.cs
rename to Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Packer.cs
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Packer.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Packer.cs.meta
similarity index 100%
rename from Assets/Coffee/UIExtensions/UIEffect/Scripts/Packer.cs.meta
rename to Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/Packer.cs.meta
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ShadowStyle.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ShadowStyle.cs
new file mode 100644
index 00000000..4544ced4
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ShadowStyle.cs
@@ -0,0 +1,14 @@
+namespace Coffee.UIExtensions
+{
+ ///
+ /// Shadow effect style.
+ ///
+ public enum ShadowStyle
+ {
+ None = 0,
+ Shadow,
+ Outline,
+ Outline8,
+ Shadow3,
+ }
+}
\ No newline at end of file
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ShadowStyle.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ShadowStyle.cs.meta
new file mode 100644
index 00000000..337e8236
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ShadowStyle.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: b0eda5bf10146491c9cfe6a31c66f9a7
+timeCreated: 1528296875
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ToneMode.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ToneMode.cs
new file mode 100644
index 00000000..4ef28bab
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ToneMode.cs
@@ -0,0 +1,17 @@
+namespace Coffee.UIExtensions
+{
+ ///
+ /// Effect mode.
+ ///
+ public enum ToneMode
+ {
+ None = 0,
+ Grayscale = 1,
+ Sepia = 2,
+ Nega = 3,
+ Pixel = 4,
+ Mono = 5,
+ Cutoff = 6,
+ Hue = 7,
+ }
+}
\ No newline at end of file
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ToneMode.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ToneMode.cs.meta
new file mode 100644
index 00000000..76773db3
--- /dev/null
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/ToneMode.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 092769547c242d74cbad96631a00963f
+timeCreated: 1528296875
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectBase.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/UIEffectBase.cs
similarity index 60%
rename from Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectBase.cs
rename to Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/UIEffectBase.cs
index d978619c..5de7fea3 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectBase.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/UIEffectBase.cs
@@ -26,6 +26,17 @@ public abstract class UIEffectBase : BaseMeshEffect, ISerializationCallbackRecei
///
public Material effectMaterial { get { return m_EffectMaterial; } }
+ ///
+ /// Raises the validate event.
+ ///
+ protected override void OnValidate ()
+ {
+ base.OnValidate ();
+#if UNITY_EDITOR
+ UnityEditor.EditorApplication.delayCall += () => UpdateMaterial(false);
+#endif
+ }
+
///
/// Raises the before serialize event.
///
@@ -39,10 +50,41 @@ public virtual void OnBeforeSerialize()
public virtual void OnAfterDeserialize()
{
#if UNITY_EDITOR
- UnityEditor.EditorApplication.delayCall += () => targetGraphic.material = m_EffectMaterial;
+ UnityEditor.EditorApplication.delayCall += () => UpdateMaterial(true);
#endif
}
+#if UNITY_EDITOR
+ ///
+ /// Updates the material.
+ ///
+ /// If set to true ignore in play mode.
+ protected void UpdateMaterial(bool ignoreInPlayMode)
+ {
+ if(!this || ignoreInPlayMode && Application.isPlaying)
+ {
+ return;
+ }
+
+ var mat = GetMaterial();
+ if (m_EffectMaterial != mat || targetGraphic.material != mat)
+ {
+ targetGraphic.material = m_EffectMaterial = mat;
+ UnityEditor.EditorUtility.SetDirty(this);
+ UnityEditor.EditorUtility.SetDirty(targetGraphic);
+ }
+ }
+
+ ///
+ /// Gets the material.
+ ///
+ /// The material.
+ protected virtual Material GetMaterial()
+ {
+ return null;
+ }
+#endif
+
///
/// This function is called when the object becomes enabled and active.
///
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectBase.cs.meta b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/UIEffectBase.cs.meta
similarity index 100%
rename from Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectBase.cs.meta
rename to Assets/Coffee/UIExtensions/UIEffect/Scripts/Common/UIEffectBase.cs.meta
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIEffectEditor.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIEffectEditor.cs
index b2ab5821..61ad1acf 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIEffectEditor.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIEffectEditor.cs
@@ -38,7 +38,7 @@ public static void DrawEffectProperties(string shaderName, SerializedObject seri
changed |= EditorGUI.EndChangeCheck();
// When tone is enable, show parameters.
- if (spToneMode.intValue != (int)UIEffect.ToneMode.None)
+ if (spToneMode.intValue != (int)ToneMode.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ToneLevel"));
@@ -54,7 +54,7 @@ public static void DrawEffectProperties(string shaderName, SerializedObject seri
changed |= EditorGUI.EndChangeCheck();
// When color is enable, show parameters.
- if (spColorMode.intValue != (int)UIEffect.ColorMode.None)
+ if (spColorMode.intValue != (int)ColorMode.Multiply)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectColor"));
@@ -70,26 +70,26 @@ public static void DrawEffectProperties(string shaderName, SerializedObject seri
changed |= EditorGUI.EndChangeCheck();
// When blur is enable, show parameters.
- if (spBlurMode.intValue != (int)UIEffect.BlurMode.None)
+ if (spBlurMode.intValue != (int)BlurMode.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Blur"));
EditorGUI.indentLevel--;
}
- // Set effect material.
- if (!serializedObject.isEditingMultipleObjects && spToneMode.intValue == 0 && spColorMode.intValue == 0 && spBlurMode.intValue == 0)
- {
- spMaterial.objectReferenceValue = null;
- }
- else if (changed || !serializedObject.isEditingMultipleObjects)
- {
- spMaterial.objectReferenceValue = UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName),
- (UIEffect.ToneMode)spToneMode.intValue,
- (UIEffect.ColorMode)spColorMode.intValue,
- (UIEffect.BlurMode)spBlurMode.intValue
- );
- }
+// // Set effect material.
+// if (!serializedObject.isEditingMultipleObjects && spToneMode.intValue == 0 && spColorMode.intValue == 0 && spBlurMode.intValue == 0)
+// {
+// spMaterial.objectReferenceValue = null;
+// }
+// else if (changed || !serializedObject.isEditingMultipleObjects)
+// {
+// spMaterial.objectReferenceValue = UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName),
+// (UIEffect.ToneMode)spToneMode.intValue,
+// (UIEffect.ColorMode)spColorMode.intValue,
+// (UIEffect.BlurMode)spBlurMode.intValue
+// );
+// }
}
//################################
@@ -132,7 +132,7 @@ void OnAddCallback(ReorderableList ro)
{
_spAdditionalShadows.InsertArrayElementAtIndex(ro.count);
var element = _spAdditionalShadows.GetArrayElementAtIndex(ro.count - 1);
- element.FindPropertyRelative("shadowMode").intValue = (int)UIEffect.ShadowStyle.Shadow;
+ element.FindPropertyRelative("shadowMode").intValue = (int)ShadowStyle.Shadow;
element.FindPropertyRelative("shadowColor").colorValue = Color.black;
element.FindPropertyRelative("effectDistance").vector2Value = new Vector2(1f, -1f);
element.FindPropertyRelative("useGraphicAlpha").boolValue = true;
@@ -142,10 +142,10 @@ void OnAddCallback(ReorderableList ro)
float ElementHeightCallback(int index)
{
var element = _spAdditionalShadows.GetArrayElementAtIndex(index);
- if (element.FindPropertyRelative("shadowMode").intValue == (int)UIEffect.ShadowStyle.None)
+ if (element.FindPropertyRelative("shadowMode").intValue == (int)ShadowStyle.None)
return 16;
- return (_spBlurMode.intValue == (int)UIEffect.BlurMode.None ? 66 : 84) + (EditorGUIUtility.wideMode ? 0 : 18);
+ return (_spBlurMode.intValue == (int)BlurMode.None ? 66 : 84) + (EditorGUIUtility.wideMode ? 0 : 18);
}
///
@@ -159,7 +159,7 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
r.height = EditorGUIUtility.singleLineHeight;
var spMode = sp.FindPropertyRelative("shadowMode");
EditorGUI.PropertyField(r, spMode);
- if (spMode.intValue == (int)UIEffect.ShadowStyle.None)
+ if (spMode.intValue == (int)ShadowStyle.None)
return;
r.y += r.height;
@@ -169,7 +169,7 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
r.y += EditorGUIUtility.wideMode ? r.height : r.height * 2;
EditorGUI.PropertyField(r, sp.FindPropertyRelative("useGraphicAlpha"));
- if (_spBlurMode.intValue != (int)UIEffect.BlurMode.None)
+ if (_spBlurMode.intValue != (int)BlurMode.None)
{
r.y += r.height;
EditorGUI.PropertyField(r, sp.FindPropertyRelative("shadowBlur"));
@@ -209,14 +209,14 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(spShadowMode);
// When shadow is enable, show parameters.
- if (spShadowMode.intValue != (int)UIEffect.ShadowStyle.None)
+ if (spShadowMode.intValue != (int)ShadowStyle.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectDistance"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ShadowColor"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_UseGraphicAlpha"));
- if (_spBlurMode.intValue != (int)UIEffect.BlurMode.None)
+ if (_spBlurMode.intValue != (int)BlurMode.None)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ShadowBlur"));
}
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIShadowEditor.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIShadowEditor.cs
index b8148d1e..29d6f15c 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIShadowEditor.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UIShadowEditor.cs
@@ -32,7 +32,7 @@ void OnAddCallback(ReorderableList ro)
{
spAdditionalShadows.InsertArrayElementAtIndex(ro.count);
var element = spAdditionalShadows.GetArrayElementAtIndex(ro.count - 1);
- element.FindPropertyRelative("style").intValue = (int)UIShadow.ShadowStyle.Shadow;
+ element.FindPropertyRelative("style").intValue = (int)ShadowStyle.Shadow;
element.FindPropertyRelative("effectColor").colorValue = Color.black;
element.FindPropertyRelative("effectDistance").vector2Value = new Vector2(1f, -1f);
element.FindPropertyRelative("useGraphicAlpha").boolValue = true;
@@ -42,10 +42,10 @@ void OnAddCallback(ReorderableList ro)
float ElementHeightCallback(int index)
{
var element = spAdditionalShadows.GetArrayElementAtIndex(index);
- if (element.FindPropertyRelative("style").intValue == (int)UIShadow.ShadowStyle.None)
+ if (element.FindPropertyRelative("style").intValue == (int)ShadowStyle.None)
return 16;
- return (uiEffect && uiEffect.blurMode != UIEffect.BlurMode.None ? 84 : 64) + (EditorGUIUtility.wideMode ? 0 : 18);
+ return (uiEffect && uiEffect.blurMode != BlurMode.None ? 84 : 64) + (EditorGUIUtility.wideMode ? 0 : 18);
}
///
@@ -59,7 +59,7 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
r.height = EditorGUIUtility.singleLineHeight;
var spMode = sp.FindPropertyRelative("style");
EditorGUI.PropertyField(r, spMode);
- if (spMode.intValue == (int)UIShadow.ShadowStyle.None)
+ if (spMode.intValue == (int)ShadowStyle.None)
return;
r.y += r.height;
@@ -69,7 +69,7 @@ void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
r.y += EditorGUIUtility.wideMode ? r.height : r.height * 2;
EditorGUI.PropertyField(r, sp.FindPropertyRelative("useGraphicAlpha"));
- if (uiEffect && uiEffect.blurMode != UIEffect.BlurMode.None)
+ if (uiEffect && uiEffect.blurMode != BlurMode.None)
{
r.y += r.height;
EditorGUI.PropertyField(r, sp.FindPropertyRelative("blur"));
@@ -91,14 +91,14 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(spShadowMode);
// When shadow is enable, show parameters.
- if (spShadowMode.intValue != (int)UIShadow.ShadowStyle.None)
+ if (spShadowMode.intValue != (int)ShadowStyle.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectDistance"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectColor"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_UseGraphicAlpha"));
- if (uiEffect && uiEffect.blurMode != UIEffect.BlurMode.None)
+ if (uiEffect && uiEffect.blurMode != BlurMode.None)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Blur"));
}
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs
index cbd4243a..c339d62a 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs
@@ -38,12 +38,6 @@ public class UICustomEffect : UIEffectBase
///
public Vector4 customFactor2 { get { return m_CustomFactor2; } set { m_CustomFactor2 = value; SetDirty(); } }
-// protected override void OnValidate()
-// {
-// base.OnValidate();
-// Debug.Log("hog!");
-// }
-
///
/// Modifies the mesh.
///
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs
index e44a9be4..b2902456 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIDissolve.cs
@@ -1,25 +1,14 @@
using System;
-using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
-#if UNITY_EDITOR
-using System.IO;
-using System.Linq;
-using UnityEditor;
-#endif
-
namespace Coffee.UIExtensions
{
///
- /// UIDissolve.
+ /// Dissolve effect for uGUI.
///
[ExecuteInEditMode]
- [DisallowMultipleComponent]
- public class UIDissolve : BaseMeshEffect
-#if UNITY_EDITOR
- , ISerializationCallbackReceiver
-#endif
+ public class UIDissolve : UIEffectBase
{
//################################
// Constant or Static Members.
@@ -34,23 +23,19 @@ public class UIDissolve : BaseMeshEffect
[SerializeField] [Range(0, 1)] float m_Width = 0.5f;
[SerializeField] [Range(0, 1)] float m_Softness = 0.5f;
[SerializeField] [ColorUsage(false)] Color m_Color = new Color(0.0f, 0.25f, 1.0f);
- [SerializeField] UIEffect.ColorMode m_ColorMode = UIEffect.ColorMode.Add;
- [SerializeField] Material m_EffectMaterial;
- [Space]
+ [SerializeField] ColorMode m_ColorMode = ColorMode.Add;
+ [Header("Play Effect")]
[SerializeField] bool m_Play = false;
[SerializeField][Range(0.1f, 10)] float m_Duration = 1;
[SerializeField] AnimatorUpdateMode m_UpdateMode = AnimatorUpdateMode.Normal;
+
//################################
// Public Members.
//################################
- ///
- /// Graphic affected by the UIEffect.
- ///
- new public Graphic graphic { get { return base.graphic; } }
///
- /// Location for effect.
+ /// Current location[0-1] for dissolve effect. 0 is not dissolved, 1 is completely dissolved.
///
public float location
{
@@ -61,7 +46,7 @@ public float location
if (!Mathf.Approximately(m_Location, value))
{
m_Location = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -78,7 +63,7 @@ public float width
if (!Mathf.Approximately(m_Width, value))
{
m_Width = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -95,7 +80,7 @@ public float softness
if (!Mathf.Approximately(m_Softness, value))
{
m_Softness = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -111,7 +96,7 @@ public Color color
if (m_Color != value)
{
m_Color = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -119,12 +104,7 @@ public Color color
///
/// Color effect mode.
///
- public UIEffect.ColorMode colorMode { get { return m_ColorMode; } }
-
- ///
- /// Effect material.
- ///
- public virtual Material effectMaterial { get { return m_EffectMaterial; } }
+ public ColorMode colorMode { get { return m_ColorMode; } }
///
/// Play dissolve on enable.
@@ -141,50 +121,6 @@ public Color color
///
public AnimatorUpdateMode updateMode { get { return m_UpdateMode; } set { m_UpdateMode = value; } }
- ///
- /// This function is called when the object becomes enabled and active.
- ///
- protected override void OnEnable()
- {
- _time = 0;
- graphic.material = effectMaterial;
- base.OnEnable();
- }
-
- ///
- /// This function is called when the behaviour becomes disabled () or inactive.
- ///
- protected override void OnDisable()
- {
- graphic.material = null;
- base.OnDisable();
- }
-
-#if UNITY_EDITOR
- public void OnBeforeSerialize()
- {
- }
-
- public void OnAfterDeserialize()
- {
- var obj = this;
- EditorApplication.delayCall += () =>
- {
- if (Application.isPlaying || !obj || !obj.graphic)
- return;
-
- var mat = UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName), UIEffect.ToneMode.None, m_ColorMode, UIEffect.BlurMode.None);
-
- if (m_EffectMaterial == mat && graphic.material == mat)
- return;
-
- graphic.material = m_EffectMaterial = mat;
- EditorUtility.SetDirty(this);
- EditorUtility.SetDirty(graphic);
- EditorApplication.delayCall += AssetDatabase.SaveAssets;
- };
- }
-#endif
///
/// Modifies the mesh.
@@ -195,7 +131,7 @@ public override void ModifyMesh(VertexHelper vh)
return;
// rect.
- Rect rect = graphic.rectTransform.rect;
+ Rect rect = targetGraphic.rectTransform.rect;
// Calculate vertex position.
UIVertex vertex = default(UIVertex);
@@ -223,6 +159,30 @@ public void Play()
m_Play = true;
}
+
+ //################################
+ // Protected Members.
+ //################################
+ ///
+ /// This function is called when the object becomes enabled and active.
+ ///
+ protected override void OnEnable()
+ {
+ _time = 0;
+ base.OnEnable();
+ }
+
+#if UNITY_EDITOR
+ ///
+ /// Gets the material.
+ ///
+ /// The material.
+ protected override Material GetMaterial ()
+ {
+ return MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName), m_ColorMode);
+ }
+#endif
+
//################################
// Private Members.
//################################
@@ -246,14 +206,5 @@ void Update()
_time = 0;
}
}
-
- ///
- /// Mark the UIEffect as dirty.
- ///
- void _SetDirty()
- {
- if (graphic)
- graphic.SetVerticesDirty();
- }
}
}
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffect.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffect.cs
index 896f5d5f..fca774d6 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffect.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffect.cs
@@ -56,55 +56,55 @@ public class AdditionalShadow
//################################
public const string shaderName = "UI/Hidden/UI-Effect";
- ///
- /// Tone effect mode.
- ///
- public enum ToneMode
- {
- None = 0,
- Grayscale,
- Sepia,
- Nega,
- Pixel,
- Mono,
- Cutoff,
- Hue,
- }
-
- ///
- /// Color effect mode.
- ///
- public enum ColorMode
- {
- None = 0,
- Set,
- Add,
- Sub,
- }
-
- ///
- /// Shadow effect style.
- ///
- public enum ShadowStyle
- {
- None = 0,
- Shadow,
- Outline,
- Outline8,
- Shadow3,
- }
-
- ///
- /// Blur effect mode.
- ///
- public enum BlurMode
- {
- None = 0,
- Fast,
- Medium,
- Detail,
- }
-
+// ///
+// /// Tone effect mode.
+// ///
+// public enum ToneMode
+// {
+// None = 0,
+// Grayscale,
+// Sepia,
+// Nega,
+// Pixel,
+// Mono,
+// Cutoff,
+// Hue,
+// }
+//
+// ///
+// /// Color effect mode.
+// ///
+// public enum ColorMode
+// {
+// None = 0,
+// Set,
+// Add,
+// Sub,
+// }
+//
+// ///
+// /// Shadow effect style.
+// ///
+// public enum ShadowStyle
+// {
+// None = 0,
+// Shadow,
+// Outline,
+// Outline8,
+// Shadow3,
+// }
+//
+// ///
+// /// Blur effect mode.
+// ///
+// public enum BlurMode
+// {
+// None = 0,
+// Fast,
+// Medium,
+// Detail,
+// }
+//
//################################
// Serialize Members.
@@ -258,118 +258,129 @@ public override void ModifyMesh(VertexHelper vh)
tempVerts.Clear();
}
-#if UNITY_EDITOR
-
- protected override void OnValidate ()
- {
- base.OnValidate ();
- EditorApplication.delayCall += () => UpdateMaterial(false);
- }
-
- public override void OnAfterDeserialize()
- {
- if (!m_CustomEffect)
- {
- EditorApplication.delayCall += () => UpdateMaterial (true);
- }
- }
+//#if UNITY_EDITOR
+//
+// protected override void OnValidate ()
+// {
+// base.OnValidate ();
+// EditorApplication.delayCall += () => UpdateMaterial(false);
+// }
+//
+// public override void OnAfterDeserialize()
+// {
+// if (!m_CustomEffect)
+// {
+// EditorApplication.delayCall += () => UpdateMaterial (true);
+// }
+// }
+//
+// void UpdateMaterial(bool onlyEditMode)
+// {
+// if(!this || onlyEditMode && Application.isPlaying)
+// {
+// return;
+// }
+//
+// var mat = (0 == toneMode) && (0 == colorMode) && (0 == blurMode)
+// ? null
+// : GetOrGenerateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode);
+//
+// if (m_EffectMaterial != mat || targetGraphic.material != mat)
+// {
+// targetGraphic.material = m_EffectMaterial = mat;
+// EditorUtility.SetDirty(this);
+// EditorUtility.SetDirty(targetGraphic);
+// }
+// }
+//
+//
+//
+// public static Material GetOrGenerateMaterialVariant(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
+// {
+// if (!shader)
+// return null;
+//
+// Material mat = GetMaterial(shader, tone, color, blur);
+//
+// if (!mat)
+// {
+// Debug.Log("Generate material : " + GetVariantName(shader, tone, color, blur));
+// mat = new Material(shader);
+//
+// if (0 < tone)
+// mat.EnableKeyword("" + tone.ToString().ToUpper());
+// if (0 < color)
+// mat.EnableKeyword("UI_COLOR_" + color.ToString().ToUpper());
+// if (0 < blur)
+// mat.EnableKeyword("UI_BLUR_" + blur.ToString().ToUpper());
+//
+// mat.name = GetVariantName(shader, tone, color, blur);
+// mat.hideFlags |= HideFlags.NotEditable;
+//
+//#if UIEFFECT_SEPARATE
+// bool isMainAsset = true;
+// string dir = Path.GetDirectoryName(GetDefaultMaterialPath (shader));
+// string materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat");
+//#else
+// bool isMainAsset = (0 == tone) && (0 == color) && (0 == blur);
+// string materialPath = GetDefaultMaterialPath (shader);
+//#endif
+// if (isMainAsset)
+// {
+// Directory.CreateDirectory(Path.GetDirectoryName(materialPath));
+// AssetDatabase.CreateAsset(mat, materialPath);
+// AssetDatabase.SaveAssets();
+// }
+// else
+// {
+// mat.hideFlags |= HideFlags.HideInHierarchy;
+// AssetDatabase.AddObjectToAsset(mat, materialPath);
+// }
+// }
+// return mat;
+// }
+//
+// public static Material GetMaterial(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
+// {
+// string variantName = GetVariantName(shader, tone, color, blur);
+// return AssetDatabase.FindAssets("t:Material " + Path.GetFileName(shader.name))
+// .Select(x => AssetDatabase.GUIDToAssetPath(x))
+// .SelectMany(x => AssetDatabase.LoadAllAssetsAtPath(x))
+// .OfType()
+// .FirstOrDefault(x => x.name == variantName);
+// }
+//
+// public static string GetDefaultMaterialPath(Shader shader)
+// {
+// var name = Path.GetFileName (shader.name);
+// return AssetDatabase.FindAssets("t:Material " + name)
+// .Select(x => AssetDatabase.GUIDToAssetPath(x))
+// .FirstOrDefault(x => Path.GetFileNameWithoutExtension(x) == name)
+// ?? ("Assets/Coffee/UIExtensions/UIEffect/Materials/" + name + ".mat");
+// }
+//
+// public static string GetVariantName(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
+// {
+// return
+//#if UIEFFECT_SEPARATE
+// "[Separated] " + Path.GetFileName(shader.name)
+//#else
+// Path.GetFileName(shader.name)
+//#endif
+// + (0 < tone ? "-" + tone : "")
+// + (0 < color ? "-" + color : "")
+// + (0 < blur ? "-" + blur : "");
+// }
+//#endif
- void UpdateMaterial(bool onlyEditMode)
- {
- if(!this || onlyEditMode && Application.isPlaying)
- {
- return;
- }
-
- var mat = (0 == toneMode) && (0 == colorMode) && (0 == blurMode)
- ? null
- : GetOrGenerateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode);
-
- if (m_EffectMaterial != mat || targetGraphic.material != mat)
- {
- targetGraphic.material = m_EffectMaterial = mat;
- EditorUtility.SetDirty(this);
- EditorUtility.SetDirty(targetGraphic);
- }
- }
-
-
-
- public static Material GetOrGenerateMaterialVariant(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
- {
- if (!shader)
- return null;
-
- Material mat = GetMaterial(shader, tone, color, blur);
-
- if (!mat)
- {
- Debug.Log("Generate material : " + GetVariantName(shader, tone, color, blur));
- mat = new Material(shader);
-
- if (0 < tone)
- mat.EnableKeyword("UI_TONE_" + tone.ToString().ToUpper());
- if (0 < color)
- mat.EnableKeyword("UI_COLOR_" + color.ToString().ToUpper());
- if (0 < blur)
- mat.EnableKeyword("UI_BLUR_" + blur.ToString().ToUpper());
-
- mat.name = GetVariantName(shader, tone, color, blur);
- mat.hideFlags |= HideFlags.NotEditable;
-
-#if UIEFFECT_SEPARATE
- bool isMainAsset = true;
- string dir = Path.GetDirectoryName(GetDefaultMaterialPath (shader));
- string materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat");
-#else
- bool isMainAsset = (0 == tone) && (0 == color) && (0 == blur);
- string materialPath = GetDefaultMaterialPath (shader);
-#endif
- if (isMainAsset)
- {
- Directory.CreateDirectory(Path.GetDirectoryName(materialPath));
- AssetDatabase.CreateAsset(mat, materialPath);
- AssetDatabase.SaveAssets();
- }
- else
- {
- mat.hideFlags |= HideFlags.HideInHierarchy;
- AssetDatabase.AddObjectToAsset(mat, materialPath);
- }
- }
- return mat;
- }
-
- public static Material GetMaterial(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
- {
- string variantName = GetVariantName(shader, tone, color, blur);
- return AssetDatabase.FindAssets("t:Material " + Path.GetFileName(shader.name))
- .Select(x => AssetDatabase.GUIDToAssetPath(x))
- .SelectMany(x => AssetDatabase.LoadAllAssetsAtPath(x))
- .OfType()
- .FirstOrDefault(x => x.name == variantName);
- }
-
- public static string GetDefaultMaterialPath(Shader shader)
- {
- var name = Path.GetFileName (shader.name);
- return AssetDatabase.FindAssets("t:Material " + name)
- .Select(x => AssetDatabase.GUIDToAssetPath(x))
- .FirstOrDefault(x => Path.GetFileNameWithoutExtension(x) == name)
- ?? ("Assets/Coffee/UIExtensions/UIEffect/Materials/" + name + ".mat");
- }
-
- public static string GetVariantName(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
+#if UNITY_EDITOR
+ ///
+ /// Gets the material.
+ ///
+ /// The material.
+ protected override Material GetMaterial ()
{
- return
-#if UIEFFECT_SEPARATE
- "[Separated] " + Path.GetFileName(shader.name)
-#else
- Path.GetFileName(shader.name)
-#endif
- + (0 < tone ? "-" + tone : "")
- + (0 < color ? "-" + color : "")
- + (0 < blur ? "-" + blur : "");
+ return MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName), m_ToneMode, m_ColorMode, m_BlurMode);
}
#endif
@@ -445,7 +456,7 @@ void _ApplyShadowZeroAlloc(List verts, ref int start, ref int end, flo
Color vertColor = color;
- if(colorMode != ColorMode.None)
+ if(colorMode != ColorMode.Multiply)
{
vertColor.r = vertColor.g = vertColor.b = 1;
}
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectCapturedImage.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectCapturedImage.cs
index 44964c3f..93ee4a8a 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectCapturedImage.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIEffectCapturedImage.cs
@@ -3,16 +3,8 @@
using UnityEngine.Rendering;
using UnityEngine.UI;
-#if UNITY_EDITOR
-using UnityEditor;
-#endif
-
namespace Coffee.UIExtensions
{
- using BlurMode = UIEffect.BlurMode;
- using ColorMode = UIEffect.ColorMode;
- using ToneMode = UIEffect.ToneMode;
-
///
/// UIEffectCapturedImage
///
@@ -146,33 +138,6 @@ protected override void OnPopulateMesh(VertexHelper vh)
base.OnPopulateMesh(vh);
}
-#if UNITY_EDITOR
- public void OnBeforeSerialize()
- {
- }
-
- public void OnAfterDeserialize()
- {
- var obj = this;
- EditorApplication.delayCall += () =>
- {
- if (Application.isPlaying || !obj)
- return;
-
- var mat = (0 == toneMode) && (0 == colorMode) && (0 == blurMode)
- ? null
- : UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode);
-
- if (m_EffectMaterial == mat)
- return;
-
- m_EffectMaterial = mat;
- EditorUtility.SetDirty(this);
- EditorApplication.delayCall += AssetDatabase.SaveAssets;
- };
- }
-#endif
-
///
/// Gets the size of the desampling.
///
@@ -302,6 +267,52 @@ public void Release()
_Release(true);
}
+#if UNITY_EDITOR
+ ///
+ /// Raises the before serialize event.
+ ///
+ public void OnBeforeSerialize()
+ {
+ }
+
+ ///
+ /// Raises the after deserialize event.
+ ///
+ public void OnAfterDeserialize()
+ {
+ UnityEditor.EditorApplication.delayCall += () => UpdateMaterial(true);
+ }
+
+ ///
+ /// Raises the validate event.
+ ///
+ protected override void OnValidate ()
+ {
+ base.OnValidate ();
+ UnityEditor.EditorApplication.delayCall += () => UpdateMaterial(false);
+ }
+
+ ///
+ /// Updates the material.
+ ///
+ /// If set to true ignore in play mode.
+ protected void UpdateMaterial(bool ignoreInPlayMode)
+ {
+ if(!this || ignoreInPlayMode && Application.isPlaying)
+ {
+ return;
+ }
+
+ var mat = MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName), m_ToneMode, m_ColorMode, m_BlurMode);
+ if (m_EffectMaterial != mat)
+ {
+ material = null;
+ m_EffectMaterial = mat;
+ UnityEditor.EditorUtility.SetDirty(this);
+ }
+ }
+#endif
+
//################################
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShadow.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShadow.cs
index 209d263b..5a7d0dc8 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShadow.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShadow.cs
@@ -51,21 +51,6 @@ public class AdditionalShadow
public bool useGraphicAlpha = true;
}
- //################################
- // Constant or Static Members.
- //################################
- ///
- /// Shadow effect style.
- ///
- public enum ShadowStyle
- {
- None = 0,
- Shadow,
- Outline,
- Outline8,
- Shadow3,
- }
-
//################################
// Serialize Members.
//################################
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs
index 3b97aa9c..ae55659d 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs
+++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UIShiny.cs
@@ -18,7 +18,7 @@ namespace Coffee.UIExtensions
///
[ExecuteInEditMode]
[DisallowMultipleComponent]
- public class UIShiny : BaseMeshEffect
+ public class UIShiny : UIEffectBase
#if UNITY_EDITOR
, ISerializationCallbackReceiver
#endif
@@ -39,7 +39,6 @@ public class UIShiny : BaseMeshEffect
[FormerlySerializedAs("m_Alpha")]
[SerializeField][Range(0, 1)] float m_Brightness = 1f;
[SerializeField][Range(0, 1)] float m_Highlight = 1;
- [SerializeField] Material m_EffectMaterial;
[Space]
[SerializeField] bool m_Play = false;
[SerializeField] bool m_Loop = false;
@@ -51,10 +50,10 @@ public class UIShiny : BaseMeshEffect
//################################
// Public Members.
//################################
- ///
- /// Graphic affected by the UIEffect.
- ///
- new public Graphic graphic { get { return base.graphic; } }
+// ///
+// /// Graphic affected by the UIEffect.
+// ///
+// new public Graphic graphic { get { return base.graphic; } }
///
/// Location for shiny effect.
@@ -68,7 +67,7 @@ public float location
if (!Mathf.Approximately(m_Location, value))
{
m_Location = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -85,7 +84,7 @@ public float width
if (!Mathf.Approximately(m_Width, value))
{
m_Width = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -102,7 +101,7 @@ public float softness
if (!Mathf.Approximately(m_Softness, value))
{
m_Softness = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -120,7 +119,7 @@ public float alpha
if (!Mathf.Approximately(m_Brightness, value))
{
m_Brightness = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -137,7 +136,7 @@ public float brightness
if (!Mathf.Approximately(m_Brightness, value))
{
m_Brightness = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -154,7 +153,7 @@ public float highlight
if (!Mathf.Approximately(m_Highlight, value))
{
m_Highlight = value;
- _SetDirty();
+ SetDirty();
}
}
}
@@ -170,16 +169,11 @@ public float rotation
if (!Mathf.Approximately(m_Rotation, value))
{
m_Rotation = value;
- _SetDirty();
+ SetDirty();
}
}
}
- ///
- /// Effect material.
- ///
- public virtual Material effectMaterial { get { return m_EffectMaterial; } }
-
///
/// Play shinning on enable.
///
@@ -211,52 +205,58 @@ public float rotation
protected override void OnEnable()
{
_time = 0;
- graphic.material = effectMaterial;
+// graphic.material = effectMaterial;
base.OnEnable();
}
- ///
- /// This function is called when the behaviour becomes disabled () or inactive.
- ///
- protected override void OnDisable()
- {
- graphic.material = null;
- base.OnDisable();
- }
-#if UNITY_EDITOR
- public void OnBeforeSerialize()
- {
- }
+// ///
+// /// This function is called when the behaviour becomes disabled () or inactive.
+// ///
+// protected override void OnDisable()
+// {
+// graphic.material = null;
+// base.OnDisable();
+// }
- public void OnAfterDeserialize()
+#if UNITY_EDITOR
+ protected override Material GetMaterial()
{
- var obj = this;
- EditorApplication.delayCall += () =>
- {
- if (Application.isPlaying || !obj)
- return;
-
- var mat = GetMaterial(shaderName);
- if (m_EffectMaterial == mat && graphic.material == mat)
- return;
-
- graphic.material = m_EffectMaterial = mat;
- EditorUtility.SetDirty(this);
- EditorUtility.SetDirty(graphic);
- EditorApplication.delayCall += AssetDatabase.SaveAssets;
- };
+ return MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName));
}
- public static Material GetMaterial(string shaderName)
- {
- string name = Path.GetFileName(shaderName);
- return AssetDatabase.FindAssets("t:Material " + name)
- .Select(x => AssetDatabase.GUIDToAssetPath(x))
- .SelectMany(x => AssetDatabase.LoadAllAssetsAtPath(x))
- .OfType()
- .FirstOrDefault(x => x.name == name);
- }
+// public void OnBeforeSerialize()
+// {
+// }
+//
+// public void OnAfterDeserialize()
+// {
+// var obj = this;
+// EditorApplication.delayCall += () =>
+// {
+// if (Application.isPlaying || !obj)
+// return;
+//
+// var mat = GetMaterial(shaderName);
+// if (m_EffectMaterial == mat && graphic.material == mat)
+// return;
+//
+// graphic.material = m_EffectMaterial = mat;
+// EditorUtility.SetDirty(this);
+// EditorUtility.SetDirty(graphic);
+// EditorApplication.delayCall += AssetDatabase.SaveAssets;
+// };
+// }
+//
+// public static Material GetMaterial(string shaderName)
+// {
+// string name = Path.GetFileName(shaderName);
+// return AssetDatabase.FindAssets("t:Material " + name)
+// .Select(x => AssetDatabase.GUIDToAssetPath(x))
+// .SelectMany(x => AssetDatabase.LoadAllAssetsAtPath(x))
+// .OfType()
+// .FirstOrDefault(x => x.name == name);
+// }
#endif
///
@@ -330,13 +330,13 @@ void Update()
}
}
- ///
- /// Mark the UIEffect as dirty.
- ///
- void _SetDirty()
- {
- if (graphic)
- graphic.SetVerticesDirty();
- }
+// ///
+// /// Mark the UIEffect as dirty.
+// ///
+// void _SetDirty()
+// {
+// if (graphic)
+// graphic.SetVerticesDirty();
+// }
}
}
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect-Dissolve.shader b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect-Dissolve.shader
index 4d56698b..b382ceae 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect-Dissolve.shader
+++ b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect-Dissolve.shader
@@ -56,7 +56,7 @@ Shader "UI/Hidden/UI-Effect-Dissolve"
#pragma target 2.0
#pragma multi_compile __ UNITY_UI_ALPHACLIP
- #pragma shader_feature __ UI_COLOR_ADD UI_COLOR_SUB UI_COLOR_SET
+ #pragma shader_feature __ ADD SUBTRACT FILL
#include "UnityCG.cginc"
#include "UnityUI.cginc"
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.cginc b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.cginc
index f7fa1911..2178e220 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.cginc
+++ b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.cginc
@@ -1,26 +1,20 @@
#ifndef UI_EFFECT_INCLUDED
#define UI_EFFECT_INCLUDED
-//################################
-// Define
-//################################
#define PACKER_STEP 64
-#if UI_TONE_GRAYSCALE | UI_TONE_SEPIA | UI_TONE_NEGA | UI_TONE_PIXEL | UI_TONE_MONO | UI_TONE_CUTOFF | UI_TONE_HUE
+#if GRAYSCALE | SEPIA | NEGA | PIXEL | MONO | CUTOFF | HUE
#define UI_TONE
#endif
-#if UI_COLOR_ADD | UI_COLOR_SUB | UI_COLOR_SET
+#if ADD | SUBTRACT | FILL
#define UI_COLOR
#endif
-#if UI_BLUR_FAST | UI_BLUR_MEDIUM | UI_BLUR_DETAIL
+#if FASTBLUR | MEDIUMBLUR | DETAILBLUR
#define UI_BLUR
#endif
-//################################
-// Unpacker to vector
-//################################
// Unpack float to low-precision [0-1] fixed4.
fixed4 UnpackToVec4(float value)
{
@@ -40,9 +34,6 @@ fixed4 UnpackToVec4(float value)
return color;
}
-//################################
-// Blur effect
-//################################
// Calculate blur effect.
// Sample texture by blured uv, with bias.
fixed4 Blur(sampler2D tex, half2 uv, half2 addUv, half bias)
@@ -53,7 +44,7 @@ fixed4 Blur(sampler2D tex, half2 uv, half2 addUv, half bias)
+ tex2D(tex, uv + half2(-addUv.x, addUv.y))
+ tex2D(tex, uv + half2(addUv.x, -addUv.y))
+ tex2D(tex, uv + half2(-addUv.x, -addUv.y))
-#if UI_BLUR_DETAIL
+#if DETAILBLUR
+ tex2D(tex, uv + half2(addUv.x, 0))
+ tex2D(tex, uv + half2(-addUv.x, 0))
+ tex2D(tex, uv + half2(0, addUv.y))
@@ -74,13 +65,13 @@ fixed4 Tex2DBlurring(sampler2D tex, half2 uv, half2 blur)
{
half4 color = tex2D(tex, uv);
- #if UI_BLUR_FAST
+ #if FASTBLUR
return color * 0.41511
+ Blur( tex, uv, blur * 3, 0.12924 )
+ Blur( tex, uv, blur * 5, 0.01343 )
+ Blur( tex, uv, blur * 6, 0.00353 );
- #elif UI_BLUR_MEDIUM | UI_BLUR_DETAIL
+ #elif MEDIUMBLUR | DETAILBLUR
return color * 0.14387
+ Blur( tex, uv, blur * 1, 0.06781 )
+ Blur( tex, uv, blur * 2, 0.05791 )
@@ -93,64 +84,57 @@ fixed4 Tex2DBlurring(sampler2D tex, half2 uv, half2 blur)
#endif
}
-//################################
-// Tone effect
-//################################
fixed3 shift_hue(fixed3 RGB, half VSU, half VSW)
{
- fixed3 RESULT;
- RESULT.x = (0.299 + 0.701*VSU + 0.168*VSW)*RGB.x
+ fixed3 result;
+ result.x = (0.299 + 0.701*VSU + 0.168*VSW)*RGB.x
+ (0.587 - 0.587*VSU + 0.330*VSW)*RGB.y
+ (0.114 - 0.114*VSU - 0.497*VSW)*RGB.z;
- RESULT.y = (0.299 - 0.299*VSU - 0.328*VSW)*RGB.x
+ result.y = (0.299 - 0.299*VSU - 0.328*VSW)*RGB.x
+ (0.587 + 0.413*VSU + 0.035*VSW)*RGB.y
+ (0.114 - 0.114*VSU + 0.292*VSW)*RGB.z;
- RESULT.z = (0.299 - 0.3*VSU + 1.25*VSW)*RGB.x
+ result.z = (0.299 - 0.3*VSU + 1.25*VSW)*RGB.x
+ (0.587 - 0.588*VSU - 1.05*VSW)*RGB.y
+ (0.114 + 0.886*VSU - 0.203*VSW)*RGB.z;
- return (RESULT);
+ return result;
}
// Apply tone effect.
fixed4 ApplyToneEffect(fixed4 color, fixed factor)
{
- #ifdef UI_TONE_GRAYSCALE // Grayscale
+ #ifdef GRAYSCALE
color.rgb = lerp(color.rgb, Luminance(color.rgb), factor);
- #elif UI_TONE_SEPIA // Sepia
+ #elif SEPIA
color.rgb = lerp(color.rgb, Luminance(color.rgb) * half3(1.07, 0.74, 0.43), factor);
- #elif UI_TONE_NEGA // Nega
+ #elif NEGA
color.rgb = lerp(color.rgb, 1 - color.rgb, factor);
#endif
return color;
}
-
-//################################
-// Color effect
-//################################
// Apply color effect.
half4 ApplyColorEffect(half4 color, half4 factor)
{
- #ifdef UI_COLOR_SET // Set
+ #ifdef FILL
color.rgb = lerp(color.rgb, factor.rgb, factor.a);
- #elif UI_COLOR_ADD // Add
+ #elif ADD
color.rgb += factor.rgb * factor.a;
- #elif UI_COLOR_SUB // Sub
+ #elif SUBTRACT
color.rgb -= factor.rgb * factor.a;
#else
color.rgb = lerp(color.rgb, color.rgb * factor.rgb, factor.a);
#endif
- #if UI_TONE_CUTOFF
+ #if CUTOFF
color.a = factor.a;
#endif
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.shader b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.shader
index d79b06f3..19990b56 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.shader
+++ b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-Effect.shader
@@ -54,9 +54,9 @@ Shader "UI/Hidden/UI-Effect"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
- #pragma shader_feature __ UI_TONE_GRAYSCALE UI_TONE_SEPIA UI_TONE_NEGA UI_TONE_PIXEL UI_TONE_MONO UI_TONE_CUTOFF UI_TONE_HUE
- #pragma shader_feature __ UI_COLOR_ADD UI_COLOR_SUB UI_COLOR_SET
- #pragma shader_feature __ UI_BLUR_FAST UI_BLUR_MEDIUM UI_BLUR_DETAIL
+ #pragma shader_feature __ GRAYSCALE SEPIA NEGA PIXEL MONO CUTOFF HUE
+ #pragma shader_feature __ ADD SUBTRACT FILL
+ #pragma shader_feature __ FASTBLUR MEDIUMBLUR DETAILBLUR
#include "UnityCG.cginc"
#include "UnityUI.cginc"
@@ -87,7 +87,7 @@ Shader "UI/Hidden/UI-Effect"
#if defined (UI_TONE) || defined (UI_BLUR)
half4 effectFactor : TEXCOORD2;
#endif
- #if UI_TONE_HUE || UI_TONE_PIXEL
+ #if HUE || PIXEL
half4 extraFactor : TEXCOORD3;
#endif
};
@@ -114,10 +114,10 @@ Shader "UI/Hidden/UI-Effect"
OUT.effectFactor = UnpackToVec4(IN.uv1.x);
#endif
- #if UI_TONE_HUE
+ #if HUE
OUT.extraFactor.x = cos(OUT.effectFactor.x*3.14159265359 * 2);
OUT.extraFactor.y = sin(OUT.effectFactor.x*3.14159265359 * 2);
- #elif UI_TONE_PIXEL
+ #elif PIXEL
OUT.extraFactor.xy = max(2, (1-OUT.effectFactor.x*0.98) * _MainTex_TexelSize.zw);
#endif
@@ -131,7 +131,7 @@ Shader "UI/Hidden/UI-Effect"
fixed4 frag(v2f IN) : SV_Target
{
- #if UI_TONE_PIXEL
+ #if PIXEL
IN.texcoord = round(IN.texcoord * IN.extraFactor.xy) / IN.extraFactor.xy;
#endif
@@ -142,18 +142,18 @@ Shader "UI/Hidden/UI-Effect"
#endif
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
- #ifdef UI_TONE_CUTOFF
+ #ifdef CUTOFF
clip (color.a - 1 + IN.effectFactor.x * 1.001);
#elif UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
- #if UI_TONE_MONO
+ #if MONO
color.rgb = IN.color.rgb;
color.a = color.a * tex2D(_MainTex, IN.texcoord).a + IN.effectFactor.x * 2 - 1;
- #elif UI_TONE_HUE
+ #elif HUE
color.rgb = shift_hue(color.rgb, IN.extraFactor.x, IN.extraFactor.y);
- #elif defined (UI_TONE) & !UI_TONE_CUTOFF
+ #elif defined (UI_TONE) & !CUTOFF
color = ApplyToneEffect(color, IN.effectFactor.x);
#endif
diff --git a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-EffectCapture.shader b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-EffectCapture.shader
index 98f77351..a770c044 100644
--- a/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-EffectCapture.shader
+++ b/Assets/Coffee/UIExtensions/UIEffect/Shaders/UI-EffectCapture.shader
@@ -21,9 +21,9 @@ Shader "UI/Hidden/UI-EffectCapture"
#pragma fragment frag
#pragma target 2.0
- #pragma shader_feature __ UI_TONE_GRAYSCALE UI_TONE_SEPIA UI_TONE_NEGA UI_TONE_PIXEL UI_TONE_MONO UI_TONE_CUTOFF UI_TONE_HUE
- #pragma shader_feature __ UI_COLOR_ADD UI_COLOR_SUB UI_COLOR_SET
- #pragma shader_feature __ UI_BLUR_FAST UI_BLUR_MEDIUM UI_BLUR_DETAIL
+ #pragma shader_feature __ GRAYSCALE SEPIA NEGA PIXEL MONO CUTOFF HUE
+ #pragma shader_feature __ ADD SUBTRACT FILL
+ #pragma shader_feature __ FASTBLUR MEDIUMBLUR DETAILBLUR
#include "UnityCG.cginc"
#include "UI-Effect.cginc"
@@ -53,10 +53,10 @@ Shader "UI/Hidden/UI-EffectCapture"
OUT.texcoord = v.texcoord;
OUT.effectFactor = _EffectFactor;
- #if UI_TONE_HUE
+ #if HUE
OUT.effectFactor.y = sin(OUT.effectFactor.x*3.14159265359*2);
OUT.effectFactor.x = cos(OUT.effectFactor.x*3.14159265359*2);
- #elif UI_TONE_PIXEL
+ #elif PIXEL
OUT.effectFactor.xy = max(2, (1-OUT.effectFactor.x) * _MainTex_TexelSize.zw);
#endif
@@ -74,7 +74,7 @@ Shader "UI/Hidden/UI-EffectCapture"
fixed4 frag(v2f IN) : SV_Target
{
- #if UI_TONE_PIXEL
+ #if PIXEL
IN.texcoord = round(IN.texcoord * IN.effectFactor.xy) / IN.effectFactor.xy;
#endif
@@ -84,7 +84,7 @@ Shader "UI/Hidden/UI-EffectCapture"
half4 color = tex2D(_MainTex, IN.texcoord);
#endif
- #if UI_TONE_HUE
+ #if HUE
color.rgb = shift_hue(color.rgb, IN.effectFactor.x, IN.effectFactor.y);
#elif defined (UI_TONE)
color = ApplyToneEffect(color, IN.effectFactor.x);
diff --git a/Assets/Editor/MaterialBundle.cs b/Assets/Editor/MaterialBundle.cs
index 06fac57d..532bc6f9 100644
--- a/Assets/Editor/MaterialBundle.cs
+++ b/Assets/Editor/MaterialBundle.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections;
+using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
@@ -6,10 +8,6 @@
namespace Coffee.UIExtensions
{
- using BlurMode = UIEffect.BlurMode;
- using ColorMode = UIEffect.ColorMode;
- using ToneMode = UIEffect.ToneMode;
-
public static class MaterialBundle
{
[MenuItem("UIEffect/Generate Material Bundle")]
@@ -36,6 +34,13 @@ static void Generate()
, (BlurMode[])Enum.GetValues(typeof(BlurMode))
);
+ GenerateMaterialVariants(
+ Shader.Find(UIDissolve.shaderName)
+ , new ToneMode[]{ToneMode.None}
+ , (ColorMode[])Enum.GetValues(typeof(ColorMode))
+ , new BlurMode[]{BlurMode.None}
+ );
+
AssetDatabase.StopAssetEditing();
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
@@ -51,9 +56,10 @@ from blur in blurs
for (int i = 0; i < combinations.Length; i++)
{
var comb = combinations[i];
-
- EditorUtility.DisplayProgressBar("Genarate Effect Material Bundle", UIEffect.GetVariantName(shader, comb.tone, comb.color, comb.blur), (float)i / combinations.Length);
- UIEffect.GetOrGenerateMaterialVariant(shader, comb.tone, comb.color, comb.blur);
+ var name = MaterialResolver.GetVariantName(shader, comb.tone, comb.color, comb.blur);
+ EditorUtility.DisplayProgressBar("Genarate Effect Material Bundle", name, (float)i / combinations.Length);
+
+ MaterialResolver.GetOrGenerateMaterialVariant(shader, comb.tone, comb.color, comb.blur);
}
EditorUtility.ClearProgressBar();
}