网站首页 全球最实用的IT互联网站!

人工智能P2P分享Wind搜索发布信息网站地图标签大全

当前位置:诺佳网 > 软件工程 > 其他技术区 > 游戏开发 >

便捷打包Instant Asset脚本

时间:2025-12-19 16:33

人气:

作者:admin

标签:

导读:使用说明 将脚本放在Assets/Editor目录下 在需要打包同一个table的资源要放在同一个文件夹下,在Project中选中要打table的文件夹,右键-gt;Build-gt;Instant Assets 脚本 using System.Collections; using S...

使用说明

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

脚本


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!");
        }
    }

}

上一篇:

下一篇:没有了

温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
  • 便捷打包Instant Asset脚本

    便捷打包Instant Asset脚本

    使用说明 将脚本放在Assets/Editor目录下 在需要打包同一个table的资源要放在同一...
  • Tuanjie InstantAsset

    Tuanjie InstantAsset

    InstantAsset InstantAsset 是一套全新的资产解决方案,旨在提升开发者的开发和运行...
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信