private void ReplacePartShaders(Part part)
        {
            var model = part.transform.Find("model");

            if (!model)
            {
                return;
            }

            Dictionary <MeshRenderer, Shader> MeshRendererLibrary = new Dictionary <MeshRenderer, Shader>();

            foreach (MeshRenderer mr in model.GetComponentsInChildren <MeshRenderer>())
            {
                Material mat;
                if (Materials.TryGetValue(mr.material.shader.name, out mat))
                {
                    if (!MeshRendererLibrary.ContainsKey(mr))
                    {
                        MeshRendererLibrary.Add(mr, mr.material.shader);
                    }
                    mr.material.shader = mat.shader;
                }
                else
                {
                    MonoBehaviour.print("[Warning] " + this.GetType().Name + "No replacement for " + mr.material.shader + " in " + part + "/*/" + mr);
                }
            }
            if (!PartShaderLibrary.ContainsKey(part))
            {
                PartShaderLibrary.Add(part, MeshRendererLibrary);
            }
        }
Exemple #2
0
        private void ReplacePartShaders(Part part)
        {
            var model = part.transform.Find("model");

            if (!model)
            {
                return;
            }

            Dictionary <MeshRenderer, Shader> MeshRendererLibrary = new Dictionary <MeshRenderer, Shader>();

            foreach (MeshRenderer mr in model.GetComponentsInChildren <MeshRenderer>())
            {
                Material mat;

                Materials.TryGetValue(mr.material.shader.name, out mat);
                if (mat)
                {
                    if (!MeshRendererLibrary.ContainsKey(mr))
                    {
                        MeshRendererLibrary.Add(mr, mr.material.shader);
                    }
                    mr.material.shader = mat.shader;
                }
                else
                {
                    log.warn(string.Format("LoadShaders {0} No replacement for {1} in {2}/*/{3}", this.GetType().Name, mr.material.shader, part, mr));
                }
                if (!PartShaderLibrary.ContainsKey(part))
                {
                    PartShaderLibrary.Add(part, MeshRendererLibrary);
                }
                if (!PartShaderLibrary.ContainsKey(part))
                {
                    PartShaderLibrary.Add(part, MeshRendererLibrary);
                }
            }
        }