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

你可能感兴趣的文章
PMP知识要点(第九章)
查看>>
PNETLab 镜像包官方下载太慢?不急,最新版本PNET_4.2.10分享!
查看>>
pnpm : 无法加载文件...
查看>>
pnpm 如何安装指定版本
查看>>
pnpm的设计与npm的对比
查看>>
PO VO DTO BO区别及用法
查看>>
pocoserver无限重启_Poco::TCPServer框架解析
查看>>
POCO库中文编程参考指南(4)Poco::Net::IPAddress
查看>>
Quartz基本使用(二)
查看>>
POC项目安装与使用指南
查看>>
Podman核心技术详解
查看>>
pods 终端安装 第三方框架的一些命令
查看>>
Podzielno
查看>>
PoE、PoE+、PoE++ 三款交换机如何选择?一文带你了解
查看>>
PoE三种标准:标准 PoE、PoE+、PoE++,网络工程师必知!
查看>>
POI 的使用
查看>>
poi 读取单元格为null者空字符串
查看>>
poi-tl简介与文本/表格和图片渲染
查看>>
pointnet分割自己的点云数据_PointNet解析
查看>>
POI实现Excel导入Cannot get a text value from a numeric cell
查看>>