public bool TryGetOverride(Material material, out MaterialPropertyOverrideList propertyOverrideList)
 {
     return(m_MaterialToOverrideList.TryGetValue(material, out propertyOverrideList));
 }
        /// Populates the list of renders and available overrides.
        public void Populate()
        {
            // Renderer list

            var newShaders   = new HashSet <Shader>();
            var newMaterials = new HashSet <Material>();

            s_ChildRenderers.Clear();
            GetComponentsInChildren(false, s_ChildRenderers);

            foreach (var renderer in s_ChildRenderers)
            {
                foreach (var sharedMaterial in renderer.sharedMaterials)
                {
                    if (sharedMaterial)
                    {
                        newShaders.Add(sharedMaterial.shader);
                        newMaterials.Add(sharedMaterial);
                    }
                }
            }

            m_Renderers = s_ChildRenderers.ToArray();

            // Shader overrides

            m_ShaderToOverrideList.Clear();

            foreach (var shader in newShaders)
            {
                ShaderPropertyOverrideList overrideList = null;

                if (m_ShaderPropertyOverrides != null && m_ShaderPropertyOverrides.Length > 0)
                {
                    overrideList = Array.Find(m_ShaderPropertyOverrides, x => x != null && x.shader == shader);
                }

                if (overrideList == null)
                {
                    overrideList = new ShaderPropertyOverrideList();
                    var shaderPropertyInfos = ShaderPropertyInfoCache.GetShaderPropertyInfoList(shader);
                    overrideList.Initialize(shader, ShaderPropertyInfoCache.CreatePropertyValues(shaderPropertyInfos));
                }

                m_ShaderToOverrideList.Add(shader, overrideList);
            }


            m_Shaders = newShaders.ToArray();
            Array.Sort(m_Shaders, (a, b) => string.CompareOrdinal(a.name, b.name)); // For the inspector
            m_ShaderPropertyOverrides = m_ShaderToOverrideList.Values.ToArray();

            // Material overrides

            m_MaterialToOverrideList.Clear();

            foreach (var material in newMaterials)
            {
                MaterialPropertyOverrideList overrideList = null;

                if (m_MaterialPropertyOverrides != null && m_MaterialPropertyOverrides.Length > 0)
                {
                    overrideList = Array.Find(m_MaterialPropertyOverrides, x => x != null && x.material == material);
                }

                if (overrideList == null)
                {
                    overrideList = new MaterialPropertyOverrideList();
                    var shaderPropertyInfos = ShaderPropertyInfoCache.GetShaderPropertyInfoList(material.shader);
                    overrideList.Initialize(material, ShaderPropertyInfoCache.CreatePropertyValues(shaderPropertyInfos));
                }

                m_MaterialToOverrideList.Add(material, overrideList);
            }

            m_Materials = newMaterials.ToArray();
            Array.Sort(m_Materials, (a, b) => string.CompareOrdinal(a.name, b.name)); // For the inspector
            m_MaterialPropertyOverrides = m_MaterialToOverrideList.Values.ToArray();

            RefreshOverrideCache();
        }