博客
关于我
unity3d打包和包的使用
阅读量:650 次
发布时间:2019-03-15

本文共 1372 字,大约阅读时间需要 4 分钟。

AssetBundle打包指南

步骤一:在Assets文件夹中创建两个新文件夹,分别命名为Editor和streamingAssets。             步骤二:选择需要打包的文件并进行打包操作。             以下是完整的代码示例:
using UnityEngine;using UnityEditor;using System.Collections;

public class AssetBundle : MonoBehaviour{[MenuItem("Custom Editor/Create AssetBundles Main")]static void CreateAssetBundlesMain(){Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);foreach (Object obj in SelectedAsset){string sourcePath = AssetDatabase.GetAssetPath(obj);string targetPath = Application.dataPath + "/StreamingAssets" + obj.name + ".assetbundle";

if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies))        {            Debug.Log(obj.name + " success");        }        else         {            Debug.Log(obj.name + " failure");        }    }}

}

如何从AssetBundle加载预设

使用以下代码可以实现从AssetBundle中加载预设的功能: using UnityEngine;using System.Collections;public class LoadAB : MonoBehaviour {    public void Start()    {        StartCoroutine(LoadBundle("file://"+Application.streamingAssetsPath+"/"+"StreamingAssetsNew Prefab.assetbundle"));    }    private IEnumerator LoadBundle(string path)    {        WWW load = new WWW(path);        yield return load;        GameObject obj = GameObject.Instantiate(load.assetBundle.mainAsset) as GameObject;        load.assetBundle.Unload(false);    }}

转载地址:http://oxelz.baihongyu.com/

你可能感兴趣的文章
Redis从库不能同步报Can’t save in background: fork: Cannot allocate memory错误
查看>>
Redis从入门到精通|干货篇
查看>>
php.ini maxfileuploads,细说PHP高洛峰文件上传类源文件
查看>>
php.ini中常见的配置信息选项
查看>>
php.ini配置中有10处设置不当,会使网站存在安全问题
查看>>
php/jsp/asp的区别
查看>>
php20个主流框架
查看>>
php301到https,虚拟主机设置自动301跳转到HTTPS
查看>>
php5 apache 配置
查看>>
php5 升级 php7 版本遇到的问题处理方法总结
查看>>
PHP5.3.3安装Mcrypt扩展
查看>>
PHP5.4 + IIS + Win2008 R2 配置
查看>>
PHP5.4 pfsocketopen函数判断sock是否存活的bug(由memcached引起)
查看>>
Redis从入门到精通
查看>>
PHP5.6.x编译报错:Don't know how to define struct flock on this system, set --enable-opcache=no
查看>>
php5ts.dll 下载_php5ts.dll下载
查看>>
php7
查看>>
PHP7 新特性
查看>>