使用说明
脚本[code]
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class CreateInstantAsset
{
[MenuItem("Assets/Build/InstantAssets")]
public static void CreateInstantAssets()
{
string[] selectedGUIDs = Selection.assetGUIDs;
Debug.Log("Ready for build, jobs = " + selectedGUIDs.Length);
for(int i = 0; i < selectedGUIDs.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(selectedGUIDs[i]);
Debug.Log("Initial build job, path = " + path);
//tableName暂时默认文件夹名
BuildInstantAsset(path);
}
}
public static void BuildInstantAsset(string path, string tableName = "")
{
string[] pathFolders = path.Split('/');
if(string.IsNullOrEmpty(tableName))
{
tableName = pathFolders[pathFolders.Length-1];
}
//构建路径
string outputPath = Application.streamingAssetsPath + "/InstantAssets/" + pathFolders[pathFolders.Length-1];
Debug.Log("start build job, outputPath = " + outputPath + "\t" + "tableName = " + tableName);
//如果没有路径则创建一个
if (!System.IO.Directory.Exists(outputPath))
{
System.IO.Directory.CreateDirectory(outputPath);
}
//定义资源名列表
InstantAssetAliasTable[] aliasTable = new InstantAssetAliasTable[]
{
//目录方式指定资源
new InstantAssetAliasTable
{
aliasTableName = tableName,
buildDirectoryPath = path, //示例,包含目录下所有资源,指定所有ScriptableObjectData
assetNames = null
}
};
//设置构建选项
InstantAssetOptions options = InstantAssetOptions.CompressionLz4HC | InstantAssetOptions.ForceRebuild;
//调用构建方法
bool success = InstantAssetEditorUtility.BuildAssetPacker(outputPath, aliasTable, options, 1024, EditorUserBuildSettings.activeBuildTarget);
if (success)
{
Debug.LogFormat("build successed!output path: {0}", outputPath);
}
else
{
Debug.LogError("build failure!");
}
}
}
[/code]来源:程序园用户自行投稿发布,如果侵权,请联系站长删除 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |

个人电脑本地私有知识库新选择:访答知识库全面解析 什么是本地私有知识库? 本地私有知识库是指安装在个人电脑上的知识管理软件,所有数据都存储在用户自己的设备上,不依赖云端服务器。这种知识库解决方案越来越受
本地知识库新选择:访答深度解析 在信息爆炸的时代,如何高效管理个人知识资产已成为许多人面临的挑战。云端知识库虽然方便,但数据隐私和安全性问题始终令人担忧。这时,本地私有知识库应运而生,成为注重数据安全