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

你可能感兴趣的文章
python 文件类型检测 linux和windows都可以用
查看>>
Python多处理池,加入;不等待继续?
查看>>
Python多处理帮助在条件下退出
查看>>
Python 无法安装包
查看>>
python 日历小部件 - 返回用户选择的日期
查看>>
Python 日志管理封装
查看>>
python 时间函数小总结
查看>>
Python 是否优化尾递归?
查看>>
Python 更新set
查看>>
Python 最强 IDE 详细使用指南!
查看>>
Python 有一个不可变的列表吗?
查看>>
Python 机器学习入门之 pandas 的使用
查看>>
Python 机器学习实战
查看>>
python 杀死子进程_subprocess.popen.kill杀死所有子进程
查看>>
Python 条件语句与循环结构详解
查看>>
Python 条件运算符解决方法如何工作?
查看>>
python 枚举类型
查看>>
Python 查询 Mongodb数据库
查看>>
python 查询Neo4j多节点的多层关系
查看>>
Python多处理导致许多僵尸进程
查看>>