Unity打包AssetBundle

这篇博客介绍了如何在Unity中进行AssetBundle的打包和管理,包括清除AssetBundleName、创建AssetBundle、设置文件夹到AssetBundle、打包 AssetBundle以及清理AssetBundleName的方法。通过这些操作,可以帮助优化游戏资源的加载和更新。
摘要由CSDN通过智能技术生成

添加了AssetBundleName的文件,都会被打包到StreammingAssets。所以需要在打包前,把其他文件夹的AssetBundleName清除一下。

if (subDirs.Length == 1 && subDirs[0].Name == "Materials")  //满足这个条件,才会添加AsssetbundleName

 

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
//using Base.Common;

 

public class AssetbundleTool : MonoBehaviour {

    static string GetStreamingAssetsDir(){
        string targetPath = Application.dataPath + "/StreamingAssets/";
        if (!Directory.Exists (targetPath)) {
            Directory.CreateDirectory(targetPath);
        }
        return targetPath;
    }

    //[MenuItem("EditorTool/Create AssetBunldes Main")]
    //static void CreateAssetBunldesMain()
    //{
    //    //获取在Project视图中选择的所有游戏对象
    //    Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
    //    string streamingAssetDir = GetStreamingAssetsDir();
    //    //遍历所有的游戏对象
    //    foreach (Object obj in SelectedAsset)
    //    {
    //        string sourcePath = AssetDatabase.GetAssetPath(obj);
    //        //本地测试:建议最后将Assetbundle放在StreamingAssets文件夹下,如果没有就创建一个,因为移动平台下只能读取这个路径
    //        //StreamingAssets是只读路径,不能写入
    //        //服务器下载:就不需要放在这里,服务器上客户端用www类进行下载。
    //        Debug.Log("dataPaht:" + Application.dataPath);
    //        string targetPath = streamingAssetDir + obj.name + ".assetbundle";
    //        if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies))
    //        {
    //            Debug.Log(obj.name + "资源打包成功");
    //        }
    //        else
    //        {
    //            Debug.Log(obj.name + "资源打包失败");
    //        }
    //    }
    //    //刷新编辑器
    //    AssetDatabase.Refresh();
    //}

    //[MenuItem("EditorTool/Create AssetBunldes ALL")]
    //static void CreateAssetBunldesALL ()
    //{

    //    Caching.CleanCache ();
    //    string Path = GetStreamingAssetsDir()+"ALL.assetbundle";
    //    Object[] SelectedAsset = Selection.GetFiltered (typeof(Object), SelectionMode.DeepAssets);
    //    foreach (Object obj in SelectedAsset) {
    //        Debug.Log ("Create AssetBunldes name :" + obj);
    //    }
    //    //这里注意第二个参数就行
    //    if (BuildPipeline.BuildAssetBundle (null, SelectedAsset, Path, BuildAssetBundleOptions.CollectDependencies)) {
    //      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值