Esempio n. 1
0
    static void BatchCreateMaterial()
    {
        Shader shader = Shader.Find("Standard");

        Object[]        textures = Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
        List <Material> mList    = new List <Material>();

        foreach (Texture2D texture in textures)
        {
            string path = AssetDatabase.GetAssetPath(texture);

            int    endIndex = path.LastIndexOf('.');
            string key      = path.Substring(0, endIndex);
            endIndex = key.LastIndexOf('/');

            Material material = null;

            string   materialPath = key + ".mat";
            FileInfo fi           = new FileInfo(materialPath);
            if (!fi.Exists)
            {
                EditorTools.CreateFolder(key.Substring(0, endIndex));

                material             = new Material(shader);
                material.mainTexture = texture;
                AssetDatabase.CreateAsset(material, materialPath);

                mList.Add(material);
            }
        }

        Selection.objects = mList.ToArray();
    }