博客
关于我
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/

你可能感兴趣的文章
NFS的常用挂载参数
查看>>
NFS网络文件系统
查看>>
nft文件传输_利用remoting实现文件传输-.NET教程,远程及网络应用
查看>>
NFV商用可行新华三vBRAS方案实践验证
查看>>
ng build --aot --prod生成文件报错
查看>>
ng 指令的自定义、使用
查看>>
nghttp3使用指南
查看>>
Nginx
查看>>
nginx + etcd 动态负载均衡实践(三)—— 基于nginx-upsync-module实现
查看>>
nginx + etcd 动态负载均衡实践(二)—— 组件安装
查看>>
nginx + etcd 动态负载均衡实践(四)—— 基于confd实现
查看>>
Nginx + Spring Boot 实现负载均衡
查看>>
Nginx + uWSGI + Flask + Vhost
查看>>
Nginx - Header详解
查看>>
Nginx - 反向代理、负载均衡、动静分离、底层原理(案例实战分析)
查看>>
nginx 1.24.0 安装nginx最新稳定版
查看>>
nginx 301 永久重定向
查看>>
nginx css,js合并插件,淘宝nginx合并js,css插件
查看>>
Nginx gateway集群和动态网关
查看>>
Nginx Location配置总结
查看>>