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

你可能感兴趣的文章
Palo Alto Networks Expedition 未授权SQL注入漏洞复现(CVE-2024-9465)
查看>>
Palo Alto Networks Expedition 远程命令执行漏洞(CVE-2024-9463)
查看>>
Palo Alto Networks PAN-OS身份认证绕过导致RCE漏洞复现(CVE-2024-0012)
查看>>
Panalog 日志审计系统 libres_syn_delete.php 前台RCE漏洞复现
查看>>
Springboot中@SuppressWarnings注解详细解析
查看>>
Panalog 日志审计系统 sprog_deletevent.php SQL 注入漏洞复现
查看>>
Panalog 日志审计系统 sprog_upstatus.php SQL 注入漏洞复现(XVE-2024-5232)
查看>>
Panalog 日志审计系统 前台RCE漏洞复现
查看>>
PANDA VALUE_COUNTS包含GROUP BY之前的所有值
查看>>
pandas - 如何将所有列从对象转换为浮点类型
查看>>
Pandas - 有条件的删除重复项
查看>>
pandas -按连续日期时间段分组
查看>>
pandas -更改重新采样的时间序列的开始和结束日期
查看>>
SpringBoot+Vue+Redis前后端分离家具商城平台系统(源码+论文初稿直接运行《精品毕设》)15主要设计:用户登录、注册、商城分类、商品浏览、查看、购物车、订单、支付、以及后台的管理
查看>>
pandas :to_excel() float_format
查看>>
pandas :加入有条件的数据框
查看>>
pandas :将多列汇总为一列,没有最后一列
查看>>
pandas :将时间戳转换为 datetime.date
查看>>
pandas :将行取消堆叠到新列中
查看>>
pandas :设置编号.最大行数
查看>>