Hi guys, I am importing some sprites which I want to pack using unity's sprite packer. But As soon as I mention the packing tag and apply the settings, the compression (RGBA PVRTC 4bit) changes to ARGB 32 bit. I want to maintain the compression as I am building for iOS, but it reverts to the true colour settings when I use a packing tag. Is this by design or bug? If by design, how would I specify the compression for packed sprite atlas?? Thanks, Rohan
check out the code for the custom packer policy http://docs.unity3d.com/Manual/SpritePacker.html i got this working to set all to argb32 but you could set compression too Code (CSharp): using System; using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEditor.Sprites; using UnityEngine; class CustomPackerPolicy : IPackerPolicy { protected class Entry { public Sprite sprite; public AtlasSettings settings; public string atlasName; public SpritePackingMode packingMode; public int anisoLevel; } private const uint kDefaultPaddingPower = 2; public virtual int GetVersion() { return 1; } protected virtual string TagPrefix { get { return "[TIGHT]"; } } protected virtual bool AllowTightWhenTagged { get { return true; } } public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs) { List<Entry> entries = new List<Entry>(); foreach (int instanceID in textureImporterInstanceIDs) { TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter; TextureFormat format; ColorSpace space; int quality; ti.ReadTextureImportInstructions(target, out format, out space, out quality); TextureImporterSettings tis = new TextureImporterSettings(); ti.ReadTextureSettings(tis); Sprite[] sprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath).Select(x => x as Sprite).Where(x => x != null).ToArray(); foreach (Sprite sprite in sprites) { Entry entry = new Entry(); entry.sprite = sprite; entry.settings.format = TextureFormat.RGBA32; entry.settings.colorSpace = space; entry.settings.compressionQuality = quality; entry.settings.filterMode = Enum.IsDefined(typeof(FilterMode), ti.filterMode) ? ti.filterMode : FilterMode.Bilinear; entry.settings.maxWidth = 2048; entry.settings.maxHeight = 2048; entry.settings.generateMipMaps = ti.mipmapEnabled; if (ti.mipmapEnabled) entry.settings.paddingPower = kDefaultPaddingPower; entry.atlasName = ParseAtlasName(ti.spritePackingTag); entry.packingMode = GetPackingMode(ti.spritePackingTag, tis.spriteMeshType); entry.anisoLevel = ti.anisoLevel; entries.Add(entry); } Resources.UnloadAsset(ti); } var atlasGroups = from e in entries group e by e.atlasName; foreach (var atlasGroup in atlasGroups) { int page = 0; var settingsGroups = from t in atlasGroup group t by t.settings; foreach (var settingsGroup in settingsGroups) { string atlasName = atlasGroup.Key; if (settingsGroups.Count() > 1) atlasName += string.Format(" (Group {0})", page); AtlasSettings settings = settingsGroup.Key; settings.anisoLevel = 1; if (settings.generateMipMaps) foreach (Entry entry in settingsGroup) if (entry.anisoLevel > settings.anisoLevel) settings.anisoLevel = entry.anisoLevel; job.AddAtlas(atlasName, settings); foreach (Entry entry in settingsGroup) { job.AssignToAtlas(atlasName, entry.sprite, entry.packingMode, SpritePackingRotation.None); } ++page; } } } protected bool IsTagPrefixed(string packingTag) { packingTag = packingTag.Trim(); if (packingTag.Length < TagPrefix.Length) return false; return (packingTag.Substring(0, TagPrefix.Length) == TagPrefix); } private string ParseAtlasName(string packingTag) { string name = packingTag.Trim(); if (IsTagPrefixed(name)) name = name.Substring(TagPrefix.Length).Trim(); return (name.Length == 0) ? "(unnamed)" : name; } private SpritePackingMode GetPackingMode(string packingTag, SpriteMeshType meshType) { if (meshType == SpriteMeshType.Tight) if (IsTagPrefixed(packingTag) == AllowTightWhenTagged) return SpritePackingMode.Tight; return SpritePackingMode.Rectangle; } }
I am getting this: Assets/SpritePacker/CustomPackerPolicy.cs(7,7): error CS0535: `CustomPackerPolicy' does not implement interface member `UnityEditor.Sprites.IPackerPolicy.AllowSequentialPacking.get' Needs something else? Unity 2018.2.0f2
https://github.com/Unity-Technologi...tor/Mono/Sprites/DefaultSpritePackerPolicy.cs this just returns false "Specifies whether sequential processing of atlas tags is enabled. If enabled, sprite packing tags are processed one by one to reduce memory usage."