5.x中批量设置选定文件夹对应的AssetBundle名称

来源:互联网 发布:sql 没有权限 编辑:程序博客网 时间:2024/06/16 06:35
一个工批量设置选定文件夹下的预设根据预设的名称产生对应的AssetBundle名称并进行设置。

[C#] 纯文本查看 复制代码
?
 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
usingUnityEngine;
usingUnityEngine;
usingSystem.Collections;
//
usingUnityEditor;
usingSystem.IO;
 
publicclass AutoSetObjAssetBundleNames : AssetPostprocessor
{
    [MenuItem("Assets/Asset AB For Name")]
    staticvoid SetAssetBundleNames()
    {
        Excute(true);
    }
 
    [MenuItem("Assets/Asset AB For Null")]
    staticvoid ClearAssetBundleNames()
    {
        Excute(false);
    }
 
    publicstatic void Excute(boolisAssetBundleName)
    {
        Object[] obj = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        for(inti = 0; i < obj.Length; i++)
        {
            stringpath = AssetDatabase.GetAssetPath(obj[i]);
            AssetImporter atPath = AssetImporter.GetAtPath(path);
            if(atPath != null)
            {
                if(isAssetBundleName && Path.GetExtension(path).Equals(".prefab"))
                {
                    atPath.assetBundleName = obj[i].name;
                }
                  elseif(Path.GetExtension(path).Equals(".prefab"))
                {
                    atPath.assetBundleName = "";
                }
            }
        }
    }
 
    publicstatic void OnPostprocessAssetbundleNameChanged(stringassetPath, stringpreviousAssetBundleName, stringnewAssetBundleName)
    {
        Debug.Log("Asset " + assetPath + " has been moved from assetBundle " + previousAssetBundleName + " to assetBundle " + newAssetBundleName + ".");
    }
}


此脚本放到Editor文件夹下就可以啦!其实读者可以根据自己的需要扩展一下,然后可以根据配置文件进行修改设置。ok!小工具代码很简单,Enjoy Job!
原创粉丝点击