1.AssetDatabase.FindAssets 使用搜索过滤器字符串搜索资产数据库。
AssetDatabase.GUIDToAssetPath
string[] sdirs = { "Assets/Game/Prefabs/UI" };
var asstIds = AssetDatabase.FindAssets("t:Prefab", sdirs);/*这个方法的第一个参数是 通过什么进行搜索,可以是name 名字 也可以通过标签 标签的话 需要用“l:”进行搜索(好像没有效果) 也可以通过类型 添加” t:“ 第二个参数其实就是路径,限制查找的路径*/
for (int i = 0; i < asstIds.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(asstIds[i]);//将得到的GUID转化为物体的完整路径
var pfb = AssetDatabase.LoadAssetAtPath<GameObject>(path);//返回给定路径assetPath处的类型类型的第一个资产对象。
//var pfb = PrefabUtility.LoadPrefabContents(path);
}
2.AssetDatabase.GetAssetPath 返回相对于存储资产的项目文件夹的路径名
Transform[] SelectionAsset = Selection.GetTransforms(SelectionMode.Unfiltered);
if (SelectionAsset.Length > 0)
{
string path = AssetDatabase.GetAssetPath(SelectionAsset[0]);
}
3.AssetDatabase.GetDependencies 给定pathName,返回它依赖的所有资产的列表(多用于assetBundle)
4.AssetDatabase.CreateFolder (parentFolder : String, newFolderName : String) : String 新建一个文件夹。Parameters参数
-
parentFolder
the name of the parent folder // 父文件夹的名字
-
newFolderName
the name of the new folder // 新文件夹的名字
if(!Directory.Exists(path + "/" + subPath))
{
string guid = AssetDatabase.CreateFolder("Assets", "My Folder");
string newFolderPath = AssetDatabase.GUIDToAssetPath(guid)
}