예제 #1
0
        static void CollectShadersOnObject(GameObject obj, List <ShaderInfo> list, string id)
        {
            if (obj == null)
            {
                return;
            }

            var renderers = obj.GetComponentsInChildren <Renderer>();

            foreach (var r in renderers)
            {
                var objName = id + "/" + GetObjectFullName(r.gameObject);
                var mats    = r.sharedMaterials;
                for (int i = 0; i < mats.Length; i++)
                {
                    var m = mats[i];
                    if (m == null || m.shader == null)
                    {
                        continue;
                    }
                    var name = m.shader.name;
                    var item = list.Find(x => { return(x.shaderName == name); });
                    if (item == null)
                    {
                        item = new ShaderInfo(name);
                        list.Add(item);
                    }
                    item.materials.Add(new MaterialInfo(objName, i, m.name));
                }
            }
        }
예제 #2
0
        public static List <ShaderInfo> Read(string file)
        {
            var list = new List <ShaderInfo>();

            var settings = new Settings(file);

            foreach (var s in settings)
            {
                var sections = settings.GetItem <Section[]>(s.Key) as Section[];
                if (sections == null)
                {
                    continue;
                }

                var shader = new ShaderInfo();
                shader.name = s.Key;

                foreach (var uniformItem in sections)
                {
                    var uniform = new UniformInfo();
                    uniform.name = uniformItem.GetItem <string>("name");
                    var typeName = uniformItem.GetItem <string>("type");
                    try
                    {
                        uniform.type = (UniformType)Enum.Parse(typeof(UniformType), typeName, true);
                        shader.uniforms.Add(uniform);
                    }
                    catch (Exception e)
                    {
                        Console.Out.WriteLine("Shader " + shader.name + ": Can't read uniform type " + typeName);
                    }
                }

                list.Add(shader);
            }

            return(list);
        }