public void AddPackage(string type) { if (!Define.IsUseAddressable) { if (!Define.IsAsync) { UIPackage uiPackage = UIPackage.AddPackage($"{FUI_PACKAGE_DIR}/{type}"); packages.Add(type, uiPackage); } else { string uiBundleDesName = AssetBundleHelper.StringToAB($"{type}_fui"); string uiBundleResName = AssetBundleHelper.StringToAB(type); ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); resourcesComponent.LoadBundle(uiBundleDesName); resourcesComponent.LoadBundle(uiBundleResName); // AssetBundle desAssetBundle = resourcesComponent.GetAssetBundle(uiBundleDesName); // AssetBundle resAssetBundle = resourcesComponent.GetAssetBundle(uiBundleResName); // UIPackage uiPackage = UIPackage.AddPackage(desAssetBundle, resAssetBundle); // packages.Add(type, uiPackage); } } else { // 使用addressable if (!Define.IsAsync) { UIPackage uiPackage = UIPackage.AddPackage($"{FUI_PACKAGE_DIR}/{type}"); packages.Add(type, uiPackage); } else { // string uiBundleDesName = AssetBundleHelper.StringToAB($"{type}_fui"); // string uiBundleResName = AssetBundleHelper.StringToAB(type); // ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>(); // resourcesComponent.LoadBundle(uiBundleDesName); // resourcesComponent.LoadBundle(uiBundleResName); // AssetBundle desAssetBundle = resourcesComponent.GetAssetBundle(uiBundleDesName); // AssetBundle resAssetBundle = resourcesComponent.GetAssetBundle(uiBundleResName); // UIPackage uiPackage = UIPackage.AddPackage(desAssetBundle, resAssetBundle); // packages.Add(type, uiPackage); } } }
public void RemovePackage(string type) { UIPackage package; if (packages.TryGetValue(type, out package)) { var p = UIPackage.GetByName(package.name); if (p != null) { UIPackage.RemovePackage(package.name); } packages.Remove(package.name); } if (Define.IsAsync) { string uiBundleDesName = AssetBundleHelper.StringToAB($"{type}_fui"); string uiBundleResName = AssetBundleHelper.StringToAB(type); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleDesName); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleResName); } }
public async Task AddPackageAsync(string packageName) { if (Define.IsUseAddressable) { // TextAsset descPkg = null; // Texture resTexturePkg = null; await Game.Scene.GetComponent <AdsResComponent>().LoadFairyGUIPackage(packageName); // await Game.Scene.GetComponent<AdsResComponent>().LoadAssetListAsyncByLabel<Object>( // $"{FUI_NAME_PREFIX}_{packageName}", null, onCompleteAssetList => // { // for (int i = 0; i < onCompleteAssetList.Count; i++) // { // var asset = onCompleteAssetList[i]; // var isTextAsset = asset is TextAsset; // var isTexture2D = asset is Texture; // // if (isTextAsset) // { // descPkg = asset as TextAsset; // } // else if (isTexture2D) // { // resTexturePkg = asset as Texture; // } // } // }); // UIPackage.AddPackage(descPkg.bytes, packageName, (name, extension, type, item) => // { // if (type == typeof(Texture)) // { // item.owner.SetItemAsset(item, resTexturePkg, DestroyMethod.Custom); // } // }); } else { if (!Define.IsAsync) { await Task.CompletedTask; UIPackage uiPackage = UIPackage.AddPackage($"{FUI_PACKAGE_DIR}/{packageName}"); packages.Add(packageName, uiPackage); } else { string uiBundleDesName = AssetBundleHelper.StringToAB($"{packageName}_fui"); string uiBundleResName = AssetBundleHelper.StringToAB(packageName); ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); await resourcesComponent.LoadBundleAsync(uiBundleDesName); await resourcesComponent.LoadBundleAsync(uiBundleResName); // AssetBundle desAssetBundle = resourcesComponent.GetAssetBundle(uiBundleDesName); // AssetBundle resAssetBundle = resourcesComponent.GetAssetBundle(uiBundleResName); // packages.Add(type, uiPackage); } } }