FGUIUtils.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using FairyGUI;
  2. using System;
  3. using XGame.Framework.Asset;
  4. using XGame.Framework.UI;
  5. namespace XGame.Framework.FGUI
  6. {
  7. public static class FguiUtils
  8. {
  9. /// <summary>
  10. /// 包名转ui的描述文件名(Description file data)
  11. /// fgui的ui数据保存在pkgName_fui.bytes文件里
  12. /// </summary>
  13. /// <param name="pkgName"></param>
  14. /// <returns></returns>
  15. public static string ToDescFileName(string pkgName)
  16. {
  17. return $"{pkgName}_fui";
  18. }
  19. /// <summary>
  20. /// 包名+资源名转ui路径
  21. /// </summary>
  22. /// <param name="pkgName"></param>
  23. /// <param name="resName"></param>
  24. /// <returns></returns>
  25. public static string ToUrl(string pkgName, string resName)
  26. {
  27. return $"ui://{pkgName}/{resName}";
  28. }
  29. /// <summary>
  30. /// 加载Nested并设置父节点
  31. /// </summary>
  32. /// <param name="assetModule"></param>
  33. /// <param name="nestedKey"></param>
  34. /// <param name="parent"></param>
  35. /// <returns></returns>
  36. public static IAssetLoadAsync<INestedView> LoadFguiNested(this IUIAssetModule assetModule, UIKey nestedKey, GComponent parent)
  37. {
  38. if (assetModule is FguiAssetModule fguiImpl)
  39. {
  40. return fguiImpl.LoadNested(nestedKey, parent);
  41. }
  42. Log.Error($"IUIAssetModule 为空. NestedKey:{nestedKey}");
  43. return null;
  44. }
  45. public static IGListItemHandle CreateListItem(this IUIViewAdapter viewAdapter, Type viewType, GObject gObj)
  46. {
  47. if (viewAdapter == null)
  48. return null;
  49. var view = viewAdapter.CreateNested(viewType, new FguiNested(gObj.asCom), false);
  50. return view as IGListItemHandle;
  51. }
  52. }
  53. }