public static void SetAssetAddress(string assetPath, string address, string groupName = "", string lable = "") { var setting = AddressableAssetSettingsDefaultObject.Settings; if (string.IsNullOrEmpty(groupName)) { groupName = FileUtil.GetParentDirName(assetPath); } var group = setting.FindGroup(groupName); if (group == null) { group = setting.CreateGroup(groupName, false, false, true, new List <AddressableAssetGroupSchema> { setting.DefaultGroup.Schemas[0], setting.DefaultGroup.Schemas[1] }, typeof(SchemaType)); } var guid = AssetDatabase.AssetPathToGUID(assetPath); if (string.IsNullOrEmpty(guid)) { Debug.LogError($"asset:{assetPath} is not exist!"); return; } var entry = setting.CreateOrMoveEntry(guid, group); if (entry == null) { Debug.LogError($"create entry fault"); return; } entry.address = address; if (string.IsNullOrEmpty(lable)) { entry.SetLabel("default", true, true); } Debug.Log($"asset:{assetPath} is added to group:{groupName}"); }
public void CreateDirAtlas(string packDir) { var atlasDir = Path.GetDirectoryName(packDir); var atlasName = "atlas_" + Path.GetFileName(packDir).ToLower(); var fullPath = atlasDir + '/' + atlasName + ".spriteatlas"; SpriteAtlas atlas; if (!File.Exists(fullPath)) { atlas = new SpriteAtlas(); SpriteAtlasPackingSettings packSetting = new SpriteAtlasPackingSettings() { blockOffset = 1, enableRotation = false, enableTightPacking = false, padding = 2, }; atlas.SetPackingSettings(packSetting); var textureSetting = new SpriteAtlasTextureSettings() { readable = false, generateMipMaps = false, sRGB = true, filterMode = FilterMode.Bilinear, }; atlas.SetTextureSettings(textureSetting); var platformSetting = new TextureImporterPlatformSettings() { maxTextureSize = 2048, format = TextureImporterFormat.Automatic, crunchedCompression = true, textureCompression = TextureImporterCompression.Compressed, compressionQuality = 50, }; atlas.SetPlatformSettings(platformSetting); AssetDatabase.CreateAsset(atlas, fullPath); } else { atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(fullPath); } if (atlas == null) { Debug.LogError($"{fullPath} is not exist"); return; } var packes = atlas.GetPackables(); atlas.Remove(packes); atlas.Add(new[] { AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(packDir) }); ImportTool.SetAssetAddress(fullPath, atlasName); AssetDatabase.SaveAssets(); // 取消图集图片的Addressable var assetes = FileUtil.GetDirAllAssetFullPath(packDir); foreach (var asset in assetes) { ImportTool.RemoveAssetAddress(asset); } }