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); }
internal static NMaterial GetDefaultMaterial() { NMaterial material; MaterialPool pool; const KeywordFlag keywordFlag = KeywordFlag.OverlayNormal; CACHED_MATERIALS.TryGetValue(keywordFlag, out pool); if (pool == null) { pool = new MaterialPool(Shader.Find("UI/Default UI"), null, keywordFlag); material = pool.Get(); material.ApplyBlendMode(BlendMode.Normal); pool.Release(material); CACHED_MATERIALS[keywordFlag] = pool; } material = pool.Get(); return(material); }
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); }
internal static bool IsShared(KeywordFlag keywordFlag) { return((keywordFlag & KeywordFlag.ColorFilter) == 0); }