TextureImportInstructions?

Hi guys,
I want to create a new Packer Policy to be sure I don’t have any atlases bigger than 1024.

In the documentation, there is the code for the DefaultSpritePolicy and there is a part saying :
TextureImportInstructions ins = new TextureImportInstructions();
ti.ReadTextureImportInstructions(ins, target);

I have an error with TextureImportInstructions, it looks like it doesn’t exist anymore in Unity 5, is it possible? I can’t find anything about the SpritePolicy, it looks like everybody else are just using the Default one.

Thanks!

Ok, for anyone who’s still struggling with this, the solution is pretty simple, but as of now undocumented.

Replace

foreach (int instanceID in textureImporterInstanceIDs)
        {
            TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;

            TextureImportInstructions ins = new TextureImportInstructions();
            ti.ReadTextureImportInstructions(ins, target);

            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 = ins.desiredFormat;
                entry.settings.usageMode = ins.usageMode;
                entry.settings.colorSpace = ins.colorSpace;
                entry.settings.compressionQuality = ins.compressionQuality;
                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);
        }

with

foreach (int instanceID in textureImporterInstanceIDs)
        {
            TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;

            TextureFormat textureFormat;
            ColorSpace colorSpace;
            int compressionQuality;
            ti.ReadTextureImportInstructions(target, out textureFormat, out colorSpace, out compressionQuality);
          
            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;
                entry.settings.colorSpace = colorSpace;
                entry.settings.compressionQuality = compressionQuality;
                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);
        }

The ReadTextureImportInstructions method still exists, but doesn’t take TextureImportInstructions (as that class no longer exists), so I substituted the target supplied by OnGroupAtlases instead. Also, usageMode is a property that vanished, so I omitted that line. The above seems to work identically to the defaultPackingPolicy when selected in the Sprite Packer window.

1 Like