[FairyGUI][Unity]FGUI资源打包AssetBundle
参考资料3
将发布后的文件打包为两个AssetBundle,即定义文件和资源各打包为一个bundle(desc_bundle+res_bundle)。这样做的好处是一般UI的更新都是修改元件位置什么的,不涉及图片资源的更新,那么只需要重新打包和推送desc_bundle就行了,不需要让玩家更新通常体积比较大的res_bundle,节省流量。打包程序由开发者按照自己熟悉的方式自行实现。以demo为例,请遵循以下规则打包:
- demo_fui.bytes单独打包为desc_bundle;
- 其他资源(demo_atlas0.png等),打包到res_bundle。
用到上述规则,包分为2个包,test"+"_desc"和"test"+"_res"两个AB包。
Assets\Resources\common文件夹的内容是 FGUI 编辑器 里面common发布后的内容。
只有
Assets\Resources\common\common_fui.bytes文件的AssetBundle通过下面这些代码自动设置为fairygui/common_desc
Assets\Resources\common除了common_fui.bytes文件以外AssetBundle通过下面这些代码自动设置为fairygui/common_res
用到Unity AssetBundle Browser tool ,参考资料1,2
在FGUI编辑器中,对已经完成的 模块,进行 发布。会在目标 打出几个文件,.byte和.png。
简化Unity AssetBundle Browser tool打包的速度
Window-AssetBundleBrowser,打开ABB的窗口。
把要打包的归类,直接添加 文件夹,并对文件夹的名字设置ab包的名字
在Project中,选中要打包的文件夹,在Inspector视图,设置AssetBundle名字
下文有自动 设置 文件assetbundleName的脚本BuildAssetBundle_.cs
ABB中添加文件夹
打包成功后用AssetStudioGUI进行查看
这是 uigeneral.prefab预制体,挂载了FGUI的UIPanel脚本和FairyUIAdpter脚本的详情。这样,说明打包正常。
打开在Unity-Resource-common的发布后的文件,与FGUI编辑器的对应 模块 的文件是否一致。
用AS打开Unity打包后的文件,与上面的文件是否一致。一致,说明正常。
打包AB包的一些错误
使用Unity AssetBundle Browser tool,打包AB包失败,的一些报错。
硬盘空间不足。
删除一些 不能识别的ab包的名字
AssetBundles-Configure
动态设置Unity项目内文件的AssetBundle
BuildAssetBundle_.cs
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public class BuildAssetBundle_
{/// <summary>/// 包名,FGUI的AB包名/// </summary>public static Dictionary<string, string> dict_ = new Dictionary<string, string>(){{ "common","fairygui/common"},//fairygui包名。在Unity中文件的assetBundle前缀名{ "main","fairygui/main"},};[MenuItem("Assets/变量文件夹设置AB包名字 ")]static void BuildAllAndroidAssetBundles(){List<string> strs = new List<string>(dict_.Keys);for (int i=0;i < strs.Count ;i++){setAB(strs[i], dict_[strs[i]]);}}//private static void setAB(string fileName,string fileABName){string abName = fileABName;//"fairygui/common";//父文件夹名字string fguiPackageName = fileName;//"common";//文件夹名字string descAB = "_desc";//fairygui/common_descstring resAB = "_res";//fairygui/common_res//string dir = "E:/ui/test/Assets/Resources";
//"AssetBundles/Android";//E:\ui\test\Assets\Resources\bulidint i = 0;string[] arrStrAudioPath = Directory.GetFiles(Application.dataPath + "/Resources/" + fguiPackageName, "*", SearchOption.AllDirectories);//循环遍历每一个路径,单独加载foreach (string strAudioPath in arrStrAudioPath){if (System.IO.Path.GetExtension(strAudioPath) != ".meta"){//替换路径中的反斜杠为正斜杠 string strTempPath = strAudioPath.Replace(@"\", "/");Debug.Log(strAudioPath);//截取我们需要的路径strTempPath = strTempPath.Substring(strTempPath.IndexOf("Assets"));//根据路径加载资源UnityEngine.Object objAudio = AssetDatabase.LoadAssetAtPath(@strTempPath, typeof(UnityEngine.Object));if (System.IO.Path.GetExtension(strAudioPath) == ".bytes"){DoSetAssetBundleName(abName + descAB, objAudio);}else if (System.IO.Path.GetExtension(strAudioPath) != ".bytes"&& System.IO.Path.GetExtension(strAudioPath) != ".cs"){DoSetAssetBundleName(abName + resAB, objAudio);}}//}//}/// <summary>/// 修改bundle名字/// </summary>/// <param name="abname">AssetBundleName的命名规则</param>/// <param name="path">遍历的文件的文件路径</param>static void DoSetAssetBundleName(string abname, UnityEngine.Object obj){Debug.Log(obj.name);var importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(obj));importer.assetBundleName = abname;//importer.assetBundleVariant = "bundle";}//public static string getFileSuffix(string fileName){return fileName.Substring(fileName.LastIndexOf("."));//例如:abc.png 截取后:.png}public static string getFilesFirst(string fileName){int num = getFileSuffix(fileName).Length;if (num < fileName.Length){num = fileName.Length - num;}return fileName.Substring(0, fileName.LastIndexOf("."));//例如:abc.png 截取后:.png}
}
FairyGUI,UNITY项目示例打包文件BuildAssetBundles
Assets\FairyGUI-unity-master\Assets\Examples\Editor\BuildAssetBundles.cs
对单一的 文件进行打包。
using UnityEngine;
using UnityEditor;
using System.IO;public class BuildAssetBundles
{[MenuItem("Window/Build FairyGUI Example Bundles")]public static void Builde(){
#if (UNITY_5 || UNITY_5_3_OR_NEWER)for (int i = 0; i < 10; i++){AssetImporter.GetAtPath("Assets/FairyGUI/Examples/Resources/Icons/i" + i + ".png").assetBundleName = "fairygui-examples/i" + i + ".ab";}AssetImporter.GetAtPath("Assets/FairyGUI/Examples/Resources/UI/BundleUsage_fui.bytes").assetBundleName = "fairygui-examples/bundleusage.ab";AssetImporter.GetAtPath("Assets/FairyGUI/Examples/Resources/UI/BundleUsage_atlas0.png").assetBundleName = "fairygui-examples/bundleusage.ab";BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, BuildAssetBundleOptions.None, BuildTarget.Android);
#elsefor (int i = 0; i < 10; i++){Object obj = AssetDatabase.LoadAssetAtPath("Assets/FairyGUI/Examples/Resources/Icons/i"+i+".png", typeof(Object));BuildPipeline.BuildAssetBundle(obj, null, Path.Combine(Application.streamingAssetsPath, "fairygui-examples/i" + i + ".ab"), BuildAssetBundleOptions.CollectDependencies, BuildTarget.Android);}Object mainAsset = AssetDatabase.LoadAssetAtPath("Assets/FairyGUI/Examples/Resources/UI/BundleUsage_fui.bytes", typeof(Object));Object[] assets = new Object[] { AssetDatabase.LoadAssetAtPath("Assets/FairyGUI/Examples/Resources/UI/BundleUsage_atlas0.png", typeof(Object))};BuildPipeline.BuildAssetBundle(mainAsset, assets, Path.Combine(Application.streamingAssetsPath, "fairygui-examples/bundleusage.ab"), BuildAssetBundleOptions.CollectDependencies, BuildTarget.Android);AssetDatabase.Refresh();
#endif}
}
相关资料:
1.[Unity][FairyGUI]www本地加载AssetBundle资源
2.[FairyGUI][Unity]加载FGUI打包成AB包的资源
3.
参考资料:
1.第1.9篇 使用 Unity AssetBundle Browser tool (AssetBundle系列完结)
2.Unity3d的AssetBundle打包——AssetBundle Browser(简单实现资源复用)
3.显示UI面板
# 加载UI包
4.
[FairyGUI][Unity]FGUI资源打包AssetBundle相关推荐
- 资源打包Assetbundle .
在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制成预设Prefab,打包成场景.今天我们来一起学习官方推荐的Assetbundle,它是Unity(Pro ...
- Unity最新版打包AssetBundle和加载的方法
一.设置assetBundleName 二.构建AssetBundle包 三.上传AssetBundle到服务器 四.把AssetBundle放到本地 五.操作AssetBundle 六.完整例子 七 ...
- [FairyGUI][Unity]加载FGUI打包成AB包的资源
参考资料3 将发布后的文件打包为两个AssetBundle,即定义文件和资源各打包为一个bundle(desc_bundle+res_bundle).这样做的好处是一般UI的更新都是修改元件位置什么的 ...
- Unity3D手游开发日记(10) - 资源打包的一些思考
Unity的资源打包,如果要做完美,其实是很复杂的.那么为什么资源要打包呢,因为我们要做资源更新.没办法啊. 在我看来,完美的资源打包至少有以下几个方面要处理好: 1) 资源分类设计合理.控制包粒度, ...
- Unity资源打包之Assetbundle
本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.net/janeky/article/details ...
- Unity资源打包(一):AssetBundle使用-2020更新
正所谓:自古套路得人心,学会AssetBundle开发,成就更精简游戏包. 欢迎关注公众号:雷潮课堂 ###AssetBundle打包 一.课程内容 1-1游戏套路 1-2什么是AssetBundle ...
- Unity打包AssetBundle自动分析资源依赖关系(包括UGUI图集打包)
https://blog.csdn.net/u012740992/article/details/79371986 怎么分析资源的依赖关系呢,并设置AssetBundleName呢? 我们检测资源之间 ...
- 实力封装:Unity打包AssetBundle(大结局)
→→前情提要:让用户选择要打包的文件←← 大结局:更多选择 Unity打包AssetBundle从入门到放弃系列终于要迎来大结局了[小哥哥表示实在写不动了o(╥﹏╥)o]... 经过上一次的教程,其实 ...
- combotree 可以异步加载吗_Unity AssetBundle 资源打包,加载,本地缓存方式,安卓,PC本地加载路径问题...
AssetBundle的定义和作用: 1,AssetBundle是一个压缩包包含模型.贴图.预制体.声音.甚至整个场景,可以在游戏运行的时候被加载. 2,AssetBundle自身保存着互相的依赖关系 ...
最新文章
- 程序员神级跳槽攻略:什么时候该跳?做什么准备?到哪里找工作?
- 【计算摄影】计算机如何学会欣赏照片的美感?
- LeetCode: Maximum Product Subarray
- Codeforces 1322D Reality Show (DP)
- MMS发送的无线网络连接协议分析
- (转载)Linux编程获取本机IP地址的三种方法
- HTML渲染过程详解
- text-indent的用法
- 一步一步跟我学习hadoop(5)----hadoop Map/Reduce教程(2)
- 伪指令 ENTRY 与 END
- 北京地区2009年春运火车票购买指南(V2.5)
- html如何给图片加链接
- linux 修改 bcast,Linux下修改MAC地址
- 【神经网络】变分自编码大杂烩
- [LOJ575]不等关系
- 数字后端基本概念介绍Blockage Link
- 改变ubuntu终端显示语言(桌面系统是中文,终端提示是英文)
- 字体图标的svg导入及寻找
- Electron学习笔记(五) 通过Addon(n-api)实现可扩展接口
- java jtextarea清空_Java:JTextArea类