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

你可能感兴趣的文章
PHP扩展安装
查看>>
PHP扩展数据库连接参数说明详解
查看>>
php把get参数放入数组_php怎么将数组转为url参数?
查看>>
PHP投票小程序
查看>>
php拆分数组不改变key值
查看>>
php接口返回数据 用echo 还是return?
查看>>
php接口返回状态,大家一般怎么规范接口返回内容
查看>>
php接收formdata上传的多个文件,使用formData()上传多个文件
查看>>
PHP操作csv文件导入+导出
查看>>
php操作mysql用select_php如何操作mysql获取select 结果
查看>>
PHP操作符与控制结构
查看>>
PHP支付宝SDK使用,电脑网页支付
查看>>
php支付宝手机网页支付类实例
查看>>
PHP改变数组key值的方法
查看>>
php教程之php空白页的原因及解决方法
查看>>
PHP数据库操作
查看>>
PHP数据文件过大,导致PHP加速器eaccelerator在PHP5.2版本下崩溃
查看>>
RabbitMQ - 死信、TTL原理、延迟队列安装和配置
查看>>
PHP数据访问的多重查询(租房子查询)
查看>>
RabbitMQ - 如保证消息的可靠性?(消息确认、消息持久化、失败重试机制)
查看>>