博客
关于我
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缃戠珯,www.wfzwz.com
查看>>
php缓存查询函数
查看>>
php编写TCP服务端和客户端程序
查看>>
php编码规范
查看>>
PHP编码规范-PSR1、psr2 /psr3 psr4
查看>>
PHP编程效率的20个要点
查看>>
PHP网页缓存技术优点及代码
查看>>
PHP自动化测试(一)make test 和 phpt
查看>>
php自定义函数: 文件大小转换成智能形式
查看>>
php英语单词,php常用英语单词,快速学习php编程英语(6)
查看>>
R3.4.0安装包时报错“需要TRUE/FALSE值的地方不可以用缺少值”,需升级到R3.5.0
查看>>
PHP获取curl传输进度
查看>>
PHP获取IP所在地区(转)
查看>>
PHP获取IP的方法对比
查看>>
php获取json里面内容
查看>>
R2的版本由来
查看>>
PHP获取图片宽度高度、大小尺寸、图片类型、用于布局的img属性
查看>>
PHP获取当前文件的绝对路径
查看>>
PHP获取当前时间、时间戳的各种格式写法汇总
查看>>
PHP获取当前页面的完整URL
查看>>