コード例 #1
0
        public static void applyToModelDatabase()
        {
            ConfigNode[] textureNodes = GameDatabase.Instance.GetConfigNodes("SSTU_SHADER");
            ConfigNode   textureNode;

            ShaderProperty[] props;
            int    len = textureNodes.Length;
            string name, shader, diff, nrm, spec, glow, ao;

            string[] excludeMeshes, meshes;
            for (int i = 0; i < len; i++)
            {
                textureNode   = textureNodes[i];
                name          = textureNode.GetStringValue("name");
                shader        = textureNode.GetStringValue("shader");
                diff          = textureNode.GetStringValue("diffuse");
                nrm           = textureNode.GetStringValue("normal");
                spec          = textureNode.GetStringValue("specular");
                glow          = textureNode.GetStringValue("emissive");
                ao            = textureNode.GetStringValue("occlusion");
                excludeMeshes = textureNode.GetStringValues("excludeMesh");
                meshes        = textureNode.GetStringValues("mesh");
                props         = ShaderProperty.parse(textureNode);

                GameObject go = GameDatabase.Instance.GetModelPrefab(name);
                if (go == null)
                {
                    MonoBehaviour.print("ERROR: Could not locate game object for model: " + name + ".  Could not update shader or textures for model");
                    continue;
                }
                MonoBehaviour.print("Updating shader for model: " + name);
                updateModelMaterial(go.transform, excludeMeshes, meshes, shader, diff, nrm, spec, glow, ao, props);
            }
        }
コード例 #2
0
 public static ShaderProperty[] parse(ConfigNode node)
 {
     ShaderProperty[] props;
     ConfigNode[] propNodes = node.GetNodes("PROPERTY");
     int len = propNodes.Length;
     props = new ShaderProperty[len];
     for (int i = 0; i < len; i++)
     {
         props[i] = new ShaderProperty(propNodes[i]);
     }
     return props;
 }
コード例 #3
0
        public static ShaderProperty[] parse(ConfigNode node)
        {
            ShaderProperty[] props;
            ConfigNode[]     propNodes = node.GetNodes("PROPERTY");
            int len = propNodes.Length;

            props = new ShaderProperty[len];
            for (int i = 0; i < len; i++)
            {
                props[i] = new ShaderProperty(propNodes[i]);
            }
            return(props);
        }
コード例 #4
0
 public static void updateRenderer(Renderer rend, string shader, string diffuse, string normal, string specular, string emissive, string occlusion, ShaderProperty[] props)
 {
     Material m = rend.material;
     if (!String.IsNullOrEmpty(shader) && shader != m.shader.name) { m.shader = SSTUDatabase.getShader(shader); }
     if (!String.IsNullOrEmpty(diffuse)) { m.mainTexture = GameDatabase.Instance.GetTexture(diffuse, false); }
     if (!String.IsNullOrEmpty(normal)) { m.SetTexture("_BumpMap", GameDatabase.Instance.GetTexture(normal, true)); }
     if (!String.IsNullOrEmpty(specular)) { m.SetTexture("_SpecMap", GameDatabase.Instance.GetTexture(specular, false)); }
     if (!String.IsNullOrEmpty(emissive)) { m.SetTexture("_Emissive", GameDatabase.Instance.GetTexture(emissive, false)); }
     if (!String.IsNullOrEmpty(occlusion)) { m.SetTexture("_AOMap", GameDatabase.Instance.GetTexture(occlusion, false)); }
     updateMaterialProperties(m, props);
 }
コード例 #5
0
 public static void updateModelMaterial(Transform root, string[] excludeMeshes, string[] meshes, string shader, string diffuse, string normal, string specular, string emissive, string occlusion, ShaderProperty[] props)
 {
     //black-list, do everything not specified in excludeMeshes array
     if (excludeMeshes != null && excludeMeshes.Length > 0)
     {
         //TODO
     }
     else if (meshes == null || meshes.Length <= 0)//no validation, do them all
     {
         Renderer[] rends = root.GetComponentsInChildren<Renderer>(true);
         int len = rends.Length;
         for (int i = 0; i < len; i++)
         {
             updateRenderer(rends[i], shader, diffuse, normal, specular, emissive, occlusion, props);
         }
     }
     else//white-list, only do what is specified by meshes array
     {
         int len = meshes.Length;
         Transform tr;
         Renderer r;
         for (int i = 0; i < len; i++)
         {
             tr = root.FindRecursive(meshes[i]);
             if (tr == null) { continue; }
             r = tr.GetComponent<Renderer>();
             if (r == null) { continue; }
             updateRenderer(r, shader, diffuse, normal, specular, emissive, occlusion, props);
         }
     }
 }
コード例 #6
0
 public static void updateMaterialProperties(Material m, ShaderProperty[] props)
 {
     if (m == null || props == null || props.Length == 0) { return; }
     int len = props.Length;
     for (int i = 0; i < len; i++)
     {
         props[i].apply(m);
     }
 }