首页 > 编程知识 正文

fgui,cxw 258-c6q90fgui

时间:2023-05-05 09:49:53 阅读:276642 作者:4321

参考资料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包。

使用的时候在FGUI面板 初始化的时候加载 依赖的FGUI AB包。

FGUIAssetBundleManager.addFGUIAB("common");

如果要用到多个 依赖包,就在 初始化的时候 加载 多个 依赖包。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using UnityEngine;using System.IO;using FairyGUI;class FGUIAssetBundleManager{ /// <summary> /// 使用FGUI包的名字,当前 打开 的FGUI面板 的数量,如果<=0就 移除 面板。 /// </summary> public static Dictionary<string, int> dict_ab = new Dictionary<string, int>(); public static Dictionary<string, string> dict_ = new Dictionary<string, string>() { { "common","fairygui/common"}, }; public static void addFGUIAB(string name) { AssetBundle dAB = null; AssetBundle rAB = null; getFGUIAB(name,out dAB,out rAB); if (dAB != null && rAB != null && getABDict(name) == 0) { UIPackage.AddPackage(dAB, rAB); Debug.Log("加载FGUI AB add:"+dAB+"??"+rAB); addABDict(name); } }// private static void getFGUIAB(string abName,out AssetBundle descAB,out AssetBundle resAB ) { string path = Application.streamingAssetsPath + "/Android/fairygui"; //E:uiAwaken - 副本AssetsStreamingAssetsAndroidfairygui string abPath = path + "/" + abName; string desc = "_desc"; string res = "_res"; string descPath = abPath + desc; string resPath = abPath + res; Debug.Log("加载FGUI AB getFGUIAB 1:" + descPath + "??" + resPath); if (File.Exists(descPath) && getABDict(abName) == 0) { descAB = AssetBundle.LoadFromFile(abPath + desc); } else { descAB = null; } if (File.Exists(resPath) && getABDict(abName) == 0) { resAB = AssetBundle.LoadFromFile(abPath + res); } else { resAB = null; } Debug.Log("加载FGUI AB getFGUIAB 2:" + descAB + "??" + resAB); }// /// <summary> /// 加载FGUI依赖包 /// </summary> /// <param name="name">FGUI包名</param> public static void addABDict(string name) { if (dict_ab.ContainsKey(name)) { dict_ab[name]++; }// else { dict_ab.Add(name,1); }// }// /// <summary> /// 获得 对应 FGUI依赖包 的 使用面板数量 /// </summary> /// <param name="name">FGUI包名</param> /// <returns>当前使用改 FGUI依赖 的面板数量</returns> public static int getABDict(string name) { int b = 0; if (dict_ab.ContainsKey(name)) { b = dict_ab[name]; } return b; }// /// <summary> /// 移除FGUI依赖包 /// </summary> /// <param name="name">FGUI包名</param> public static void removeAB(string name) { if (dict_ab.ContainsKey(name)) { dict_ab[name]--; if (dict_ab[name] <= 0) { UIPackage.RemovePackage(name); } } }}//

相关资料:

1.[Unity][FairyGUI]加载依赖关系包图片资源丢失

2.[FairyGUI][Unity]FGUI资源打包AssetBundle

3.显示UI面板

4.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。