public static void CreatConfig() { AddressablesRules rules = new AddressablesRules(); Dictionary <string, BuildAddressablesData> bundles = rules.GetBuilds(); SaveJsonManifest(FrameWorkConst.addressAssetsManifesttxt, bundles); AssetDatabase.ImportAsset(FrameWorkConst.addressAssetsManifesttxt, ImportAssetOptions.ForceUpdate); AssetDatabase.Refresh(); }
public static void AddFileToAddressables() { AddressablesRules rules = new AddressablesRules(); Dictionary <string, BuildAddressablesData> bundles = rules.GetBuilds(); AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(false); AddressableAssetGroup group = null; //清理重名group foreach (string key in bundles.Keys) { group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); if (group != null) { aaSettings.RemoveGroup(group); group = null; } } foreach (string key in bundles.Keys) { group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); if (group == null) { if (bundles[key].ResType == "online") { group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null); BundledAssetGroupSchema schema = group.AddSchema <BundledAssetGroupSchema>(); schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4; if (bundles[key].packageType == "PackSeparately") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately; } else if (bundles[key].packageType == "PackTogether") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; } else if (bundles[key].packageType == "PackTogetherByLabel") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel; } schema.BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteBuildPath); schema.LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteLoadPath); schema.UseAssetBundleCache = true; schema.UseAssetBundleCrc = true; ContentUpdateGroupSchema contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>(); contentUpdateGroupSchema.StaticContent = false; group = null; } else { group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null); BundledAssetGroupSchema schema = group.AddSchema <BundledAssetGroupSchema>(); schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.Uncompressed; if (bundles[key].packageType == "PackSeparately") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately; } else if (bundles[key].packageType == "PackTogether") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; } else if (bundles[key].packageType == "PackTogetherByLabel") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel; } if (bundles[key].canUpdate) { ContentUpdateGroupSchema contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>(); contentUpdateGroupSchema.StaticContent = false; } schema.UseAssetBundleCache = true; schema.UseAssetBundleCrc = true; group = null; } } } foreach (string key in bundles.Keys) { int count = 0; int MaxCount = bundles[key].entitys.Count; group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); foreach (string entitysKey in bundles[key].entitys.Keys) { count++; if (count % 3 == 0) { if (UnityEditor.EditorUtility.DisplayCancelableProgressBar( string.Format("Collecting... [{0}/{1}]", count, MaxCount), entitysKey, count * 1f / MaxCount)) { break; } } string guid = AssetDatabase.AssetPathToGUID(bundles[key].entitys[entitysKey]); AddressableAssetEntry entity = aaSettings.CreateOrMoveEntry(guid, group); entity.SetAddress(entitysKey); for (int i = 0; i < bundles[key].Lable.Length; i++) { aaSettings.AddLabel(bundles[key].Lable[i]); entity.SetLabel(bundles[key].Lable[i], true); } } } UnityEditor.EditorUtility.ClearProgressBar(); }