Exemplo n.º 1
0
        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;
            };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates the material variants.
        /// </summary>
        static void GenerateMaterialVariants(Shader shader)
        {
            var combinations = (from tone in (ToneMode[])Enum.GetValues(typeof(ToneMode))
                                from color in (ColorMode[])Enum.GetValues(typeof(ColorMode))
                                from blur in (BlurMode[])Enum.GetValues(typeof(BlurMode))
                                select new { tone, color, blur }).ToArray();

            for (int i = 0; i < combinations.Length; i++)
            {
                var comb = combinations[i];

                EditorUtility.DisplayProgressBar("Genarate Effect Material", UIEffect.GetVariantName(shader, comb.tone, comb.color, comb.blur), (float)i / combinations.Length);
                UIEffect.GetOrGenerateMaterialVariant(shader, comb.tone, comb.color, comb.blur);
            }
            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 3
0
        static void GenerateMaterialVariants(Shader shader, ToneMode[] tones, ColorMode[] colors, BlurMode[] blurs)
        {
            var combinations = (from tone in tones
                                from color in colors
                                from blur in blurs
                                select new { tone, color, blur }).ToArray();

            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);
            }
            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 4
0
        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;
            };
        }
Exemplo n.º 5
0
        //################################
        // Constant or Static Members.
        //################################
        /// <summary>
        /// Draw effect properties.
        /// </summary>
        public static void DrawEffectProperties(string shaderName, SerializedObject serializedObject)
        {
            bool changed = false;

            //================
            // Effect material.
            //================
            var spMaterial = serializedObject.FindProperty("m_EffectMaterial");

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(spMaterial);
            EditorGUI.EndDisabledGroup();

            //================
            // Tone setting.
            //================
            var spToneMode = serializedObject.FindProperty("m_ToneMode");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(spToneMode);
            changed |= EditorGUI.EndChangeCheck();

            // When tone is enable, show parameters.
            if (spToneMode.intValue != (int)UIEffect.ToneMode.None)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ToneLevel"));
                EditorGUI.indentLevel--;
            }

            //================
            // Color setting.
            //================
            var spColorMode = serializedObject.FindProperty("m_ColorMode");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(spColorMode);
            changed |= EditorGUI.EndChangeCheck();

            // When color is enable, show parameters.
            if (spColorMode.intValue != (int)UIEffect.ColorMode.None)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectColor"));
                EditorGUI.indentLevel--;
            }

            //================
            // Blur setting.
            //================
            var spBlurMode = serializedObject.FindProperty("m_BlurMode");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(spBlurMode);
            changed |= EditorGUI.EndChangeCheck();

            // When blur is enable, show parameters.
            if (spBlurMode.intValue != (int)UIEffect.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
                                                                                        );
            }
        }