批量设置AssetBundleName

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;

public class ChangeName : MonoBehaviour {

//    public string versionDir;
//    public string abName;

    void Start () 
    {
        for(int i = 0;i< 27;i++)
        {
            string path = "RES/com/face/prefab/0_"+i;
            string abname = "face0_" + i;
            SetVersionDirAssetName (path,abname);
        }
    }
    
    public void SetVersionDirAssetName(string versionDir,string abName)
    {
        var fullPath = Application.dataPath + "/" + versionDir + "/";
        var relativeLen = versionDir.Length + 8; // Assets 长度
        if (Directory.Exists(fullPath))
        {
            EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 0f);
            var dir = new DirectoryInfo(fullPath);
            var files = dir.GetFiles("*", SearchOption.AllDirectories);
            for (var i = 0; i < files.Length; ++i)
            {
                var fileInfo = files[i];
                EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 1f * i / files.Length);
                if (!fileInfo.Name.EndsWith(".meta"))
                {
                    var basePath = fileInfo.FullName.Substring(fullPath.Length - relativeLen).Replace('\\', '/');
                    var importer = AssetImporter.GetAtPath(basePath);
                    if (importer && importer.assetBundleName != versionDir)
                    {
                        importer.assetBundleName = abName;
                    }
                }
            }
            EditorUtility.ClearProgressBar();
        }
    }
}

 

posted on 2016-03-03 18:10  602147629  阅读(1155)  评论(0编辑  收藏  举报