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

你可能感兴趣的文章
OC 内存管理黄金法则
查看>>
oc57--Category 分类
查看>>
occi库在oracle官网的下载针对vs2008
查看>>
OceanBase 安装使用详细说明
查看>>
OceanBase详解及如何通过MySQL的lib库进行连接
查看>>
ocp最新题库之052新题带答案整理-36题
查看>>
OCP题库升级,新版的052考试题及答案整理-18
查看>>
OCR:文字识别(最详细教程)
查看>>
OCR使用总结
查看>>
OCR识别:身份证信息加密传输
查看>>
octave错误-error: ‘squareThisNumber‘ undefined near line 1 column 1
查看>>
Octotree Chrome插件离线安装
查看>>
OCTO作为美团的高性能服务通信框架,究竟能不能称得上是杀手锏呢?
查看>>
OC中关于给NSString 赋 nil和@""的区别
查看>>
OC字符串方法汇总
查看>>
OC学习6——面相对象的三大特性
查看>>
OC点语法介绍和使用以及@property关键字
查看>>
oc知道经纬度求位置
查看>>
OC高效率52之提供“全能初始化”方法
查看>>
oc--习题
查看>>