Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Sprite Packer Policy example doesn't work ?

Discussion in 'Documentation' started by Gruguir, Jun 29, 2015.

  1. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    In this section : http://docs.unity3d.com/Manual/SpritePacker.html
    DefaultPackerPolicy sample gives me the error :
    Assets/Standard Assets/Editor/DefaultPackerPolicySample.cs(35,25): error CS0246: The type or namespace name `TextureImportInstructions' could not be found. Are you missing a using directive or an assembly reference ?
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Hmmm... That looks odd. I think TextureImportInstructions exists as an internal API which means the code example isn't correct.
     
  3. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    thanks Graham for your prompt reply
     
  4. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    Bug reported, case 709557
     
  5. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    @Graham Dunnett i'd like to get any news on this, as my project is still stuck
     
  6. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Your bug has been passed to devs, but it's not been looked at as far as I can tell. As I said in my reply on the 29th, just assume that the code is wrong and the function isn't meant to be public. The bug might be fixed just by changing the doc page which I guess isn't what you want. :-(
     
  7. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    @Graham Dunnett hey, due too my bad english i'm not one hundred percent sure of what you mean. But as i understand it, the bug as to be fixed in the editor, not only in the documentation. If that's the case, this is a serious issue for me until it's fixed. I have to grab sprite packer atlases, and it looks like there is no other way to read/write them since Unity 5 (i also posted about that concern here).
     
  8. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    What I am saying is that the documentation page is wrong. So needs to be changed/deleted. The doc page is using some API functions that are not exposed. The way this is happening internally is changing. Think of the code as still being written/worked on. With my access to the source code, and reading about which functions/classes are actually visible, I was able to make this change and get the code to compile:

    Code (csharp):
    1.         foreach (int instanceID in textureImporterInstanceIDs)
    2.         {
    3.             TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;
    4.  
    5. //            TextureImportInstructions ins = new TextureImportInstructions();
    6. //            ti.ReadTextureImportInstructions(ins, target);
    7.  
    8.             TextureFormat df;
    9.             ColorSpace cs;
    10.             int cq;
    11.            
    12.             ti.ReadTextureImportInstructions(BuildTarget.StandaloneOSXIntel, out df, out cs, out cq);
    13.             //TextureImporterSettings tis = new TextureImporterSettings();
    14.             //ti.ReadTextureSettings(tis);
    15.  
    16. Debug.Log("Desired format: " + df);
    17. Debug.Log("Color Space: " + cs);
    18. Debug.Log("Compression Quality: " + cq);
    19.  
    20.             Sprite[] sprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath).Select(x => x as Sprite).Where(x => x != null).ToArray();
    21.             foreach (Sprite sprite in sprites)
    22.             {
    23.                 Entry entry = new Entry();
    24.                 entry.sprite = sprite;
    25. //                entry.settings.format = ins.desiredFormat;
    26.                 entry.settings.format = df;
    27. //                entry.settings.usageMode = ins.usageMode;
    28. //                entry.settings.colorSpace = ins.colorSpace;
    29.                 entry.settings.colorSpace = cs;
    30. //                entry.settings.compressionQuality = ins.compressionQuality;
    31.                 entry.settings.compressionQuality = cq;
    32.                 entry.settings.filterMode = Enum.IsDefined(typeof(FilterMode), ti.filterMode) ? ti.filterMode : FilterMode.Bilinear;
    33.                 entry.settings.maxWidth = 2048;
    34.                 entry.settings.maxHeight = 2048;
    35.                 entry.settings.generateMipMaps = ti.mipmapEnabled;
    36.                 if (ti.mipmapEnabled)
    37.                     entry.settings.paddingPower = kDefaultPaddingPower;
    38.                 entry.atlasName = ParseAtlasName(ti.spritePackingTag);
    39. //                entry.packingMode = GetPackingMode(ti.spritePackingTag, tis.spriteMeshType);
    40.                 entry.anisoLevel = ti.anisoLevel;
    41.  
    42.                 entries.Add(entry);
    43.             }
    44.  
    45.             Resources.UnloadAsset(ti);
    46.         }
    I haven't tested this code, and have almost zero knowledge of what the demo is meant for. All I am showing to you is un-documented, intended to be private, ways of modifying the user manual page example. If you try this meant-to-be-private code and it works then great. You will need to know that future versions of Unity might not support this code. If the code doesn't do what you want, then you need to assume that the approach won't work and is not supported. I would not want to swap out the user manual script example with the code I have hacked together above.
     
  9. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    @Graham Dunnett @edunity2 I've seen that the page as been updated. There is one last error :
    Although it works fine just by commenting the involved line. However, i still not understand how to make a generated atlas readable to save it to disk, that was my initial goal. (Sorry for cross-posting, but it is somewhat related, post about that concern is located here).
     
  10. duck

    duck

    Unity Technologies

    Joined:
    Oct 21, 2008
    Posts:
    358
    FYI This manual page is now fixed.
     
  11. Zanrok

    Zanrok

    Joined:
    Aug 9, 2012
    Posts:
    2
    It would appear it's not completely fixed. Many of us are still getting this error.

    error CS1501: No overload for method `ReadTextureImportInstructions' takes `4' arguments

    Any possible fix for this would be appreciated.

    Edit: It looks like the documentation is for current versions of Unity, older versions 4.6 for example do not support the script and are displaying that error.

    And on a side note....can you guys possibly put a date last updated and for what version on the documentation pages in the future so we know how up-to-date or not up-to-date they are?
     
    Last edited: Dec 10, 2015