找回密码
 立即注册

便捷打包Instant Asset脚本

岑韬哎 2025-12-19 21:55

使用说明

  1. 将脚本放在Assets/Editor目录下
  2. 在需要打包同一个table的资源要放在同一个文件夹下,在Project中选中要打table的文件夹,右键->Build->Instant Assets

脚本

[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]
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

路过

雷人

握手

鲜花

鸡蛋
文章点评
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。