Esempio n. 1
0
        internal NMaterial Get()
        {
            NMaterial material;

            if (this._shared)
            {
                material = this._materials.Peek();
            }
            else
            {
                if (this._materials.Count == 0)
                {
                    material = new NMaterial(this._shader)
                    {
                        keywordFlag = this._keywordFlag, pool = this
                    };
                    if (this._keywords != null)
                    {
                        material.shaderKeywords = this._keywords;
                    }
                }
                else
                {
                    material = this._materials.Pop();
                }
            }
            return(material);
        }
Esempio n. 2
0
        internal static NMaterial SetBlendMode(NMaterial currentMaterial, BlendMode blendMode)
        {
            KeywordFlag keywordFlag = currentMaterial.keywordFlag;

            if ((keywordFlag & BLENDMODE_TO_FLAGS[blendMode]) > 0)
            {
                return(currentMaterial);
            }

            currentMaterial.pool.Release(currentMaterial);

            int flag = ( int )keywordFlag;

            flag &= ~0x1fe0;

            keywordFlag  = ( KeywordFlag )flag;
            keywordFlag |= BLENDMODE_TO_FLAGS[blendMode];

            MaterialPool pool;

            CACHED_MATERIALS.TryGetValue(keywordFlag, out pool);
            if (pool == null)
            {
                pool = new MaterialPool(Shader.Find("UI/Default UI"), currentMaterial.shaderKeywords, keywordFlag);
                CACHED_MATERIALS[keywordFlag] = pool;
            }
            NMaterial material = pool.Get();

            CopyProperties(currentMaterial, material);
            return(material);
        }
Esempio n. 3
0
        internal void Release(NMaterial material)
        {
            if (this._shared || material.pool != this)
            {
                return;
            }

            this._materials.Push(material);
        }
Esempio n. 4
0
        internal MaterialPool(Shader shader, string[] keywords, MaterialManager.KeywordFlag keywordFlag)
        {
            this._shader      = shader;
            this._keywords    = keywords;
            this._keywordFlag = keywordFlag;

            NMaterial material = this.Get();

            this.Release(material);

            this._shared = MaterialManager.IsShared(this._keywordFlag);
        }
Esempio n. 5
0
        private static NMaterial GetMaterial(NMaterial currentMaterial, string keyword, bool enable)
        {
            KeywordFlag keywordFlag = currentMaterial.keywordFlag;

            if (enable)
            {
                if ((keywordFlag & KEYWORD_TO_FLAGS[keyword]) > 0)
                {
                    return(currentMaterial);
                }
                keywordFlag |= KEYWORD_TO_FLAGS[keyword];
            }
            else
            {
                if ((keywordFlag & KEYWORD_TO_FLAGS[keyword]) == 0)
                {
                    return(currentMaterial);
                }
                keywordFlag &= ~KEYWORD_TO_FLAGS[keyword];
            }

            currentMaterial.pool.Release(currentMaterial);

            MaterialPool pool;

            CACHED_MATERIALS.TryGetValue(keywordFlag, out pool);
            if (pool == null)
            {
                string[] keywords    = currentMaterial.shaderKeywords;
                string[] newKeywords = new string[keywords.Length + 1];
                Array.Copy(keywords, newKeywords, keywords.Length);
                newKeywords[keywords.Length] = keyword;
                pool = new MaterialPool(Shader.Find("UI/Default UI"), newKeywords, keywordFlag);
                CACHED_MATERIALS[keywordFlag] = pool;
            }
            NMaterial material = pool.Get();

            CopyProperties(currentMaterial, material);
            return(material);
        }
Esempio n. 6
0
 internal static NMaterial DsiableBlurFilter(NMaterial currentMaterial)
 {
     return(GetMaterial(currentMaterial, "BLUR_FILTER", false));
 }
Esempio n. 7
0
 internal static NMaterial DisableColorFilter(NMaterial currentMaterial)
 {
     return(GetMaterial(currentMaterial, "COLOR_FILTER", false));
 }
Esempio n. 8
0
 internal static NMaterial DisableGrayed(NMaterial currentMaterial)
 {
     return(GetMaterial(currentMaterial, "GRAYED", false));
 }
Esempio n. 9
0
 internal static NMaterial EnableGrayed(NMaterial currentMaterial)
 {
     return(GetMaterial(currentMaterial, "GRAYED", true));
 }
Esempio n. 10
0
 internal static NMaterial DisableMaskTexture(NMaterial currentMaterial)
 {
     return(GetMaterial(currentMaterial, "MASK_TEX", false));
 }
Esempio n. 11
0
 internal static NMaterial EnableMaskTexture(NMaterial currentMaterial)
 {
     return(GetMaterial(currentMaterial, "MASK_TEX", true));
 }
Esempio n. 12
0
 internal static NMaterial DisableAlphaTexture(NMaterial currentMaterial)
 {
     return(GetMaterial(currentMaterial, "ALPHA_TEX", false));
 }
Esempio n. 13
0
        private static void CopyProperties(NMaterial source, NMaterial destination)
        {
            if (source.HasProperty("_ClipRect"))
            {
                destination.SetVector("_ClipRect", source.GetVector("_ClipRect"));
            }

            if (source.HasProperty("_Color"))
            {
                destination.SetColor("_Color", source.GetColor("_Color"));
            }
            if (source.HasProperty("_ColorMask"))
            {
                destination.SetFloat("_ColorMask", source.GetFloat("_ColorMask"));
            }

            if (source.HasProperty("_BlendSrcFactor"))
            {
                destination.SetFloat("_BlendSrcFactor", source.GetFloat("_BlendSrcFactor"));
            }
            if (source.HasProperty("_BlendDstFactor"))
            {
                destination.SetFloat("_BlendDstFactor", source.GetFloat("_BlendDstFactor"));
            }

            if (source.HasProperty("_UseAlphaTexture"))
            {
                destination.SetFloat("_UseAlphaTexture", source.GetFloat("_UseAlphaTexture"));
            }

            if (source.HasProperty("_UseUIAlphaClip"))
            {
                destination.SetFloat("_UseUIAlphaClip", source.GetFloat("_UseUIAlphaClip"));
            }

            if (source.HasProperty("_UseGrayed"))
            {
                destination.SetFloat("_UseGrayed", source.GetFloat("_UseGrayed"));
            }

            if (source.HasProperty("_UseColorFilter"))
            {
                destination.SetFloat("_UseColorFilter", source.GetFloat("_UseColorFilter"));
            }
            if (source.HasProperty("_ColorOffset"))
            {
                destination.SetVector("_ColorOffset", source.GetVector("_ColorOffset"));
            }
            if (source.HasProperty("_ColorMatrix"))
            {
                destination.SetMatrix("_ColorMatrix", source.GetMatrix("_ColorMatrix"));
            }

            if (source.HasProperty("_UseBlurFilter"))
            {
                destination.SetFloat("_UseBlurFilter", source.GetFloat("_UseBlurFilter"));
            }
            if (source.HasProperty("_BlurSize"))
            {
                destination.SetFloat("_BlurSize", source.GetFloat("_BlurSize"));
            }
        }