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

你可能感兴趣的文章
Open-Sora代码详细解读(2):时空3D VAE
查看>>
Open-Source Service Discovery
查看>>
open-vm-tools-dkms : 依赖: open-vm-tools (>= 2:9.4.0-1280544-5ubuntu3) 但是它将不会被安装
查看>>
open3d-Dll缺失,未找到指定模块解决
查看>>
openai Midjourney代理服务 gpt大模型第三方api平台汇总 支持国内外各种大模型 持续更新中...
查看>>
OpenAll:Android打开组件新姿势【仅供用于学习了解ButterKnife框架基本原理】
查看>>
OpenASR 项目使用教程
查看>>
Openbox-桌面图标设置
查看>>
opencart出现no such file or dictionary
查看>>
OpenCV 3.1 imwrite()函数写入异常问题解决方法
查看>>
OpenCV 4.1.0版drawContours
查看>>
Opencv cv2.putText 函数详解
查看>>
opencv glob 内存溢出异常
查看>>
opencv Hog Demo
查看>>
opencv Hog学习总结
查看>>
opencv Mat push_back
查看>>
opencv putText中文乱码
查看>>
OpenCV Python围绕特定点将图像旋转X度
查看>>