#pragma warning restore 649 public ReturnCode Run() { // TODO: Need a return value if this ever can fail Packer.RebuildAtlasCacheIfNeeded(m_Parameters.Target, true, Packer.Execution.Normal); SpriteAtlasUtility.PackAllAtlases(m_Parameters.Target); return(ReturnCode.Success); }
protected override void OnUpdate() { SpriteAtlasUtility.PackAllAtlases(UnityEditor.BuildTarget.StandaloneWindows); Entities.ForEach((UnityEngine.Sprite sprite) => DeclareReferencedAsset(sprite.texture)); }
public void Process() { if (!HasData) { return; } foreach (var sceneData in _applicationSpritesData.Data) { if (sceneData.Sprites.Count > 0) { MoveSprites(sceneData.SceneName, sceneData.Sprites); #if UNITY_2017_1_OR_NEWER CreateAtlas(sceneData.SceneName); #endif } } CreateCommonAtlas(_applicationSpritesData.CommonSprites); AssetDatabase.Refresh(); #if UNITY_2017_1_OR_NEWER SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget); #endif }
public void WhenSpriteWithAtlas_SpriteImportDataCreated(SpritePackerMode spriteMode, string spritePackingTag, bool hasReferencingSpriteAtlas, bool expectedPacked) { string sourceTexture = Path.Combine(kSourceTestAssetFolder, "SpriteTexture32x32.png"); string destTexture = Path.Combine(kTestAssetFolder, "SpriteTexture32x32.png"); AssetDatabase.CopyAsset(sourceTexture, destTexture); TextureImporter importer = AssetImporter.GetAtPath(destTexture) as TextureImporter; importer.spritePackingTag = spritePackingTag; importer.SaveAndReimport(); if (hasReferencingSpriteAtlas) { var sa = new SpriteAtlas(); var targetObjects = new UnityEngine.Object[] { AssetDatabase.LoadAssetAtPath <Texture>(destTexture) }; sa.Add(targetObjects); string saPath = Path.Combine(kTestAssetFolder, "sa.spriteAtlas"); AssetDatabase.CreateAsset(sa, saPath); AssetDatabase.Refresh(); } GUID.TryParse(AssetDatabase.AssetPathToGUID(destTexture), out GUID spriteGUID); CalculateAssetDependencyData.TaskInput input = CreateDefaultInput(); EditorSettings.spritePackerMode = spriteMode; SpriteAtlasUtility.PackAllAtlases(input.Target); input.Assets = new List <GUID>() { spriteGUID }; CalculateAssetDependencyData.RunInternal(input, out CalculateAssetDependencyData.TaskOutput output); Assert.AreEqual(expectedPacked, output.AssetResults[0].spriteData.PackedSprite); }
#pragma warning restore 649 /// <inheritdoc /> public ReturnCode Run() { // TODO: Need a return value if this ever can fail #if !UNITY_2020_1_OR_NEWER Packer.RebuildAtlasCacheIfNeeded(m_Parameters.Target, true, Packer.Execution.Normal); #endif SpriteAtlasUtility.PackAllAtlases(m_Parameters.Target); return ReturnCode.Success; }
public static void GenSpriteAtlas() { var addressGroupConfig = AssetDatabase.LoadAssetAtPath <BundleGroups>(BundleGroupConfigPath); if (addressGroupConfig) { var atlasItems = addressGroupConfig.SpriteAtlasItems; EditorUtility.DisplayProgressBar("图集", "生成图集中", 0); List <string> spriteAtlasKeys = new List <string>(); foreach (var item in atlasItems) { var assets = item.GetAllAssets(); foreach (var path in assets) { var atlasFileName = path + ".spriteatlas"; if (Directory.GetDirectories(path).Length == 0) { if (!File.Exists(atlasFileName)) { var obj = AssetDatabase.LoadMainAssetAtPath(path); if (obj) { SpriteAtlas spriteAtlas = new SpriteAtlas(); spriteAtlas.Add(new UnityEngine.Object[] { obj }); AssetDatabase.CreateAsset(spriteAtlas, atlasFileName); } } } var atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasFileName); if (atlas) { if (!spriteAtlasKeys.Contains(atlasFileName)) { spriteAtlasKeys.Add(atlasFileName); } else { Debug.LogError("重复的图集名称,解决办法:文件夹名字不重复,即使在不同的文件夹!"); } atlas.SetIncludeInBuild(false); SpriteAtlasPackingSettings settings = SpriteAtlasExtensions.GetPackingSettings(atlas); settings.enableTightPacking = false; settings.enableRotation = false; settings.padding = 2; SpriteAtlasExtensions.SetPackingSettings(atlas, settings); } } } EditorUtility.DisplayProgressBar("图集", "Packing sprite atlas", 0.7f); SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); } }
public override void Export() { #if USE_SPRITEATLAS SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget, false); #endif base.Export(); //分析依赖关系 var all = AssetBundleUtils.GetAll(); try { SetSpriteAtlasInBuild(all, false); ExportImp(); } finally { SetSpriteAtlasInBuild(all, true); } }
private void DrawSettings() { EditorGUI.BeginDisabledGroup(isRecording); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Settings", EditorStyles.toolbarDropDown); EditorGUILayout.Space(); recordOnPlay = EditorGUILayout.Toggle("Record on play", recordOnPlay); EditorGUI.BeginChangeCheck(); spriteUsageSizeThreshold = EditorGUILayout.Slider("Allowed Size Variation", spriteUsageSizeThreshold, 0, 2); if (EditorGUI.EndChangeCheck()) { SpriteAuditorUtility.SetSizeCheckThreshold(spriteUsageSizeThreshold); SpriteDatabase.SizeCheckThresholdChanged(); //TODO //SpriteDatabase.SetAllowedSizeVariation(spriteUsageSizeThreshold); } EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(!EditorPrefs.HasKey(ATLAS_AUDITOR_STORAGE_KEY)); if (GUILayout.Button("Clear Cache", EditorStyles.toolbarButton)) { ClearCache(); } if (GUILayout.Button("Pack Atlases", EditorStyles.toolbarButton)) { SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget); } if (GUILayout.Button("Refresh Atlases", EditorStyles.toolbarButton)) { AtlasCacheUtility.CacheKnowAtlases(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); }
private static void BeforeBuild() { CleanUpDeletedScenes(); KeyStore(); SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget, false); AssetDatabase.SaveAssets(); PrintAllEnviromentVariables(); WriteBuildInfoFile(); SetupBuildVersion(); SetupBuildBundleVersion(); AssetDatabase.SaveAssets(); BuildAddressable(); }
internal static void PackAllSpriteAtlases() { SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget, canCancel: false); m_SpriteAtlasTextureCache.Clear(); m_TextureSpriteAtlasCache.Clear(); var atlases = Resources.FindObjectsOfTypeAll <SpriteAtlas>(); foreach (var atlas in atlases) { var sprites = GetPackedSprites(atlas); var texture = sprites.FirstOrDefault()?.GetAtlasTexture() ?? null; if (texture && texture != null) { m_SpriteAtlasTextureCache.Add(atlas, texture); m_TextureSpriteAtlasCache.Add(texture, atlas); } } }
public static void CreateAtlases() { DeleteAtlases(); Utility.CreateDirectory(Utility.GetPluginPath(), Utility.GetAtlasesFolderName()); Dictionary <string, SpriteAtlas> atlasDictionary = GenerateAtlases(); foreach (KeyValuePair <string, SpriteAtlas> pair in atlasDictionary) { string directory = pair.Key; SpriteAtlas atlas = pair.Value; string name = directory.Replace('/', '_'); string assetPath = Utility.GetOutputPath() + "/" + name + ".spriteatlas"; AssetDatabase.CreateAsset(atlas, assetPath); } SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); }
private void PackAtlasByTarget() { SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget); }
private void DrawSettings() { EditorGUI.BeginDisabledGroup(isRecording); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Settings", EditorStyles.toolbarDropDown); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); recordOnUpdate = EditorGUILayout.Toggle("Record Automatically", recordOnUpdate); if (EditorGUI.EndChangeCheck()) { spriteFinder.SetCaptureOnUpdate(recordOnUpdate); } if (recordOnUpdate) { EditorGUI.BeginChangeCheck(); frameInterval = EditorGUILayout.IntField("Frame Interval", frameInterval); if (EditorGUI.EndChangeCheck()) { spriteFinder.SetFrameInterval(frameInterval); } } else { bool guiWasEnabled = GUI.enabled; GUI.enabled = true; if (GUILayout.Button("Capture Frame")) { spriteFinder.CaptureFrame(); } GUI.enabled = guiWasEnabled; } EditorGUI.BeginChangeCheck(); spriteUsageSizeThreshold = EditorGUILayout.Slider("Allowed Size Variation", spriteUsageSizeThreshold, 0, 2); if (EditorGUI.EndChangeCheck()) { SpriteAuditorUtility.SetSizeCheckThreshold(spriteUsageSizeThreshold); SpriteDatabase.SizeCheckThresholdChanged(); } EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(!EditorPrefs.HasKey(ATLAS_AUDITOR_STORAGE_KEY)); if (GUILayout.Button("Clear Cache", EditorStyles.toolbarButton)) { ClearCache(); } if (GUILayout.Button("Pack Atlases", EditorStyles.toolbarButton)) { SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget); } if (GUILayout.Button("Refresh Atlases", EditorStyles.toolbarButton)) { AtlasCacheUtility.CacheKnowAtlases(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); }
public static void MakeAtlas(string selectPath) { var destAtlasParentDir = "Assets/BundleResources/BuildByDir/UI/spriteatlas"; if (!Directory.Exists(destAtlasParentDir)) { Directory.CreateDirectory(destAtlasParentDir); } var dirInfo = new DirectoryInfo(selectPath); var atlasName = dirInfo.Name; if (atlasName == "english" || atlasName == "chinese") { atlasName = dirInfo.Parent.Name + "_" + atlasName; } var destAtlasDir = destAtlasParentDir + "/" + atlasName; if (!Directory.Exists(destAtlasDir)) { Directory.CreateDirectory(destAtlasDir); } var destAtlasFileName = destAtlasDir + "/" + atlasName + ".spriteatlas"; SpriteAtlas tmpAtlas = null; if (!File.Exists(destAtlasFileName)) { tmpAtlas = new SpriteAtlas(); AssetDatabase.CreateAsset(tmpAtlas, destAtlasFileName); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } else { tmpAtlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(destAtlasFileName); } if (tmpAtlas == null) { return; } tmpAtlas.Remove(tmpAtlas.GetPackables()); var selectDir = AssetDatabase.LoadAssetAtPath <Object>(selectPath); tmpAtlas.Add(new Object[] { selectDir }); ////////////////////////////////// var packageSetting = tmpAtlas.GetPackingSettings(); packageSetting.enableRotation = false; packageSetting.enableTightPacking = false; packageSetting.padding = 2; tmpAtlas.SetPackingSettings(packageSetting); ////////////////////////////////// var texSetting = tmpAtlas.GetTextureSettings(); texSetting.readable = false; texSetting.generateMipMaps = false; texSetting.sRGB = true; texSetting.filterMode = FilterMode.Bilinear; tmpAtlas.SetTextureSettings(texSetting); ////////////////////////////////// var standaloneSettings = tmpAtlas.GetPlatformSettings("Standalone"); standaloneSettings.maxTextureSize = 2048; standaloneSettings.format = TextureImporterFormat.DXT5; standaloneSettings.overridden = true; tmpAtlas.SetPlatformSettings(standaloneSettings); var androidSettings = tmpAtlas.GetPlatformSettings("Android"); androidSettings.maxTextureSize = 2048; androidSettings.format = TextureImporterFormat.ETC2_RGBA8; androidSettings.overridden = true; tmpAtlas.SetPlatformSettings(androidSettings); var iosSettings = tmpAtlas.GetPlatformSettings("iPhone"); iosSettings.maxTextureSize = 2048; iosSettings.format = TextureImporterFormat.ASTC_RGBA_6x6; iosSettings.overridden = true; tmpAtlas.SetPlatformSettings(iosSettings); /// ///////////////////////////////// SpriteAtlasUtility.PackAllAtlases(BuildTarget.StandaloneWindows64); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public static void PackingAtlas() { SetAssetConfig(true); SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(); }
/// <summary> /// 资源打包 /// </summary> public static void BuildAssetBundles(string output, bool rebuild) { // 移除所有assetBundleName string[] assetBundleNames = AssetDatabase.GetAllAssetBundleNames(); foreach (var assetBundleName in assetBundleNames) { AssetDatabase.RemoveAssetBundleName(assetBundleName, true); } // 设置图集 string dataPath = assetPath + "/data/texture"; string[] directoryPaths = Directory.GetDirectories(dataPath, "*.atlas", SearchOption.AllDirectories); foreach (var directoryPath in directoryPaths) { string relativePath = directoryPath.Replace(assetPath, "Assets"); SetSpriteAtlas(relativePath); } // 设置assetBundleName dataPath = assetPath + "/data"; string[] filePaths = Directory.GetFiles(dataPath, "*.*", SearchOption.AllDirectories); foreach (var filePath in filePaths) { string path = filePath; if (path.Contains("/Resources/") || path.Contains(@"\Resources\") || path.Contains("/resources/") || path.Contains(@"\resources\")) { continue; } string extension = Path.GetExtension(path); switch (extension) { case ".meta": case ".cs": { } continue; } if (Path.GetDirectoryName(path).EndsWith(".atlas")) { continue; } string relativePath = path.Replace(assetPath, "Assets"); var asset = AssetImporter.GetAtPath(relativePath); switch (extension) { case ".lua": { path = path.Substring(0, path.Length - ".lua".Length) + ".txt"; } break; case ".unity": { path = path.Substring(0, path.Length - ".unity".Length) + ".scene"; } break; } asset.assetBundleName = GetAssetBundleName(path); } // 打包 if (rebuild && Directory.Exists(output)) { FileUtil.DeleteFileOrDirectory(output); AssetDatabase.Refresh(); } Directory.CreateDirectory(output); AssetDatabase.Refresh(); SpriteAtlasUtility.PackAllAtlases(buildTarget); BuildPipeline.BuildAssetBundles(output, BuildAssetBundleOptions.ChunkBasedCompression, buildTarget); // 移除所有assetBundleName assetBundleNames = AssetDatabase.GetAllAssetBundleNames(); foreach (var assetBundleName in assetBundleNames) { AssetDatabase.RemoveAssetBundleName(assetBundleName, true); } // 刷新 AssetDatabase.Refresh(); }
protected override void OnUpdate() { SpriteAtlasUtility.PackAllAtlases(UnityEditor.BuildTarget.StandaloneWindows); }