Exemple #1
0
        public Scale(string _baseNote, ToneMode tonemode)
        {
            baseNote = _baseNote;
            t        = tonemode;

            GenerateScale(t);
        }
Exemple #2
0
        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 <Material>()
                   .FirstOrDefault(x => x.name == variantName));
        }
Exemple #3
0
        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 : ""));
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public void GenerateScale(ToneMode tonemode)
        {
            _interimsMode = ScaleModes[tonemode];

            int indexOfFirstNote = Array.IndexOf(allNotes, baseNote);

            for (int i = 0; i < _interimsMode.Count; i++)
            {
                var indexOfNote = indexOfFirstNote + _interimsMode[i] >= allNotes.Length
                    ? indexOfFirstNote + _interimsMode[i] - allNotes.Length
                    : indexOfFirstNote + _interimsMode[i];

                wantedScale.Add(allNotes[indexOfNote]);
            }
        }
        /// <summary>
        /// Mark the UIEffect as dirty.
        /// </summary>
        /// <param name="isMaterialDirty">If set to true material dirty.</param>
        void SetDirty(bool isMaterialDirty = false)
        {
            //
            if (!mainEffect)
            {
                mainEffect = GetComponent <UIEffect>();
            }

            // Only main effect update material.
            if (mainEffect != this)
            {
                m_ToneMode  = mainEffect.m_ToneMode;
                m_ColorMode = mainEffect.m_ColorMode;
                m_BlurMode  = mainEffect.m_BlurMode;
                return;
            }

            // Update material if needed.
            if (isMaterialDirty && mainEffect == this)
            {
                const int TONE_SHIFT     = 0;
                const int TONE_GRAYSCALE = (int)ToneMode.Grayscale;
                const int TONE_SEPIA     = (int)ToneMode.Sepia;
                const int TONE_NEGA      = (int)ToneMode.Nega;

                const int COLOR_SHIFT = 2;
                const int COLOR_SET   = (int)ColorMode.Set;
                const int COLOR_ADD   = (int)ColorMode.Add;
                const int COLOR_SUB   = (int)ColorMode.Sub;

                const int BLUR_SHIFT  = 4;
                const int BLUR_FAST   = (int)BlurMode.Fast;
                const int BLUR_DETAIL = (int)BlurMode.Detail;

                // Calculate shader keyword identifier from effect modes.
                int identifier = ((int)m_ToneMode << TONE_SHIFT) | ((int)m_ColorMode << COLOR_SHIFT) | ((int)m_BlurMode << BLUR_SHIFT);

                // When all effect modes are disable(None), graphic uses default material.
                if (identifier == 0)
                {
                    graphic.material = null;
                    graphic.SetVerticesDirty();
                    return;
                }

                // Generate and cache new material by given identifier.
                if (!s_SharedMaterials[identifier])
                {
                    if (!s_SharedMaterials[0])
                    {
                        s_SharedMaterials[0] = new Material(shader);
                    }
                    Material mat = new Material(s_SharedMaterials[0]);

                    // Bits for tone effect.
                    int toneBits = identifier >> TONE_SHIFT;
                    mat.EnableKeyword(
                        TONE_NEGA == (toneBits & TONE_NEGA) ? "UI_TONE_NEGA"
                                                : TONE_SEPIA == (toneBits & TONE_SEPIA) ? "UI_TONE_SEPIA"
                                                : TONE_GRAYSCALE == (toneBits & TONE_GRAYSCALE) ? "UI_TONE_GRAYSCALE"
                                                : "UI_TONE_OFF"
                        );

                    // Bits for color effect.
                    int colorBits = identifier >> COLOR_SHIFT;
                    mat.EnableKeyword(
                        COLOR_SUB == (colorBits & COLOR_SUB) ? "UI_COLOR_SUB"
                                                : COLOR_ADD == (colorBits & COLOR_ADD) ? "UI_COLOR_ADD"
                                                : COLOR_SET == (colorBits & COLOR_SET) ? "UI_COLOR_SET"
                                                : "UI_COLOR_OFF"
                        );

                    // Bits for blur effect.
                    int blurBits = identifier >> BLUR_SHIFT;
                    mat.EnableKeyword(
                        BLUR_DETAIL == (blurBits & BLUR_DETAIL) ? "UI_BLUR_DETAIL"
                                                : BLUR_FAST == (blurBits & BLUR_FAST) ? "UI_BLUR_FAST"
                                                : "UI_BLUR_OFF"
                        );

                    mat.name += identifier.ToString();
                    s_SharedMaterials[identifier] = mat;
                }

                graphic.material = s_SharedMaterials[identifier];
            }
            graphic.SetVerticesDirty();
        }
Exemple #7
0
 partial void SetToneMode(ToneMode mode);
Exemple #8
0
 public void SetToneMode(ToneMode mode)
 {
 }
Exemple #9
0
        /// <summary>
        /// Get shared material for identifier.
        /// </summary>
        /// <param name="isMaterialDirty">If set to true material dirty.</param>
        public static Material GetSharedMaterial(Shader shader, ToneMode toneMode, ColorMode colorMode, BlurMode blurMode, bool nullDefault = true)
        {
            // Update material if needed.
            const int TONE_SHIFT     = 0;
            const int TONE_GRAYSCALE = (int)ToneMode.Grayscale;
            const int TONE_SEPIA     = (int)ToneMode.Sepia;
            const int TONE_NEGA      = (int)ToneMode.Nega;
            const int TONE_PIXEL     = (int)ToneMode.Pixel;
            const int TONE_MONO      = (int)ToneMode.Mono;
            const int TONE_CUTOFF    = (int)ToneMode.Cutoff;

            const int COLOR_SHIFT = 3;
            const int COLOR_SET   = (int)ColorMode.Set;
            const int COLOR_ADD   = (int)ColorMode.Add;
            const int COLOR_SUB   = (int)ColorMode.Sub;

            const int BLUR_SHIFT  = 5;
            const int BLUR_FAST   = (int)BlurMode.Fast;
            const int BLUR_MEDIUM = (int)BlurMode.Medium;
            const int BLUR_DETAIL = (int)BlurMode.Detail;

            // Calculate shader keyword identifier from effect modes.
            int identifier = ((int)toneMode << TONE_SHIFT)
                             | ((int)colorMode << COLOR_SHIFT)
                             | ((int)blurMode << BLUR_SHIFT);

            // When all effect modes are disable(None), graphic uses default material.
            if (nullDefault && identifier == 0)
            {
                return(null);
            }

            Material[] materials;

            if (!s_SharedMaterials.TryGetValue(shader, out materials))
            {
                materials = new Material[128];
                s_SharedMaterials.Add(shader, materials);
            }

            // Generate and cache new material by given identifier.
            if (!materials[identifier])
            {
                if (!materials[0])
                {
                    materials[0]       = new Material(shader);
                    materials[0].name += identifier.ToString();
                }
                if (identifier == 0)
                {
                    return(materials[0]);
                }

                Material mat = new Material(materials[0]);

                // Bits for tone effect.
                int toneBits = identifier >> TONE_SHIFT;
                mat.EnableKeyword(
                    TONE_CUTOFF == (toneBits & TONE_CUTOFF) ? "UI_TONE_CUTOFF"
                                        : TONE_MONO == (toneBits & TONE_MONO) ? "UI_TONE_MONO"
                                        : TONE_PIXEL == (toneBits & TONE_PIXEL) ? "UI_TONE_PIXEL"
                                        : TONE_NEGA == (toneBits & TONE_NEGA) ? "UI_TONE_NEGA"
                                        : TONE_SEPIA == (toneBits & TONE_SEPIA) ? "UI_TONE_SEPIA"
                                        : TONE_GRAYSCALE == (toneBits & TONE_GRAYSCALE) ? "UI_TONE_GRAYSCALE"
                                        : "UI_TONE_OFF"
                    );

                // Bits for color effect.
                int colorBits = identifier >> COLOR_SHIFT;
                mat.EnableKeyword(
                    COLOR_SUB == (colorBits & COLOR_SUB) ? "UI_COLOR_SUB"
                                        : COLOR_ADD == (colorBits & COLOR_ADD) ? "UI_COLOR_ADD"
                                        : COLOR_SET == (colorBits & COLOR_SET) ? "UI_COLOR_SET"
                                        : "UI_COLOR_OFF"
                    );

                // Bits for blur effect.
                int blurBits = identifier >> BLUR_SHIFT;
                mat.EnableKeyword(
                    BLUR_DETAIL == (blurBits & BLUR_DETAIL) ? "UI_BLUR_DETAIL"
                                        : BLUR_MEDIUM == (blurBits & BLUR_MEDIUM) ? "UI_BLUR_MEDIUM"
                                        : BLUR_FAST == (blurBits & BLUR_FAST) ? "UI_BLUR_FAST"
                                        : "UI_BLUR_OFF"
                    );

                mat.name += identifier.ToString();
                materials[identifier] = mat;
            }
            return(materials[identifier]);
        }
Exemple #10
0
 private string SetToneMode(ToneMode mode)
 {
     return("");
 }