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

你可能感兴趣的文章
pythonweb网站开发基础创建django项目
查看>>
pythonweb网站开发基础添加应用
查看>>
Python_015 多线程
查看>>
python_73_pickle序列化(接72)
查看>>
python_code_418
查看>>
python_day10 协程 GEVENT
查看>>
python_day1作业
查看>>
Python接口自动化测试必备基础之http协议详解!
查看>>
python_IDE开发环境使用_建立Python源文件---python工作笔记011
查看>>
Python_web框架解析
查看>>
Python__Enter__/__Exit__vs__init__(或__new__)/__del__
查看>>
python_对象的基本组成和内存示意图---python工作笔记016
查看>>
python_开发环境介绍_交互模式使用_IDE介绍和使用---python工作笔记010
查看>>
python_引用的本质_栈内存和堆内存_内存示意图---python工作笔记017
查看>>
python_标识符_帮助系统的使用_命名规则---python工作笔记018
查看>>
python_海龟绘图_坐标系问题_画笔各种方法---python工作笔记013
查看>>
python_海龟绘图_画出奥运五环图---python工作笔记014
查看>>
Python_生产者消费者模型、管道、数据共享、进程池
查看>>
python_程序格式_缩进_行注释_段注释---python工作笔记012
查看>>
python_程序的构成---python工作笔记015
查看>>