Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to add secondary textures settings to Sprite Atlas through C#?

Discussion in 'Scripting' started by carcasanchez, Sep 7, 2021.

  1. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    Hello!
    I have an automated system (Unity 2020.2.0f1) where I pick a bunch of separated sprites with a secondary Normal Map, and I add them to a generated SpriteAtlas asset. Works good, but the normal map needs to have the sRGB option uncheked.
    In the editor, this is done through the Secondary Settings panel:
    upload_2021-9-7_11-43-6.png

    However, since this is an editor script, I need to add this secondary settings through C#, but I don't find any method nor documentation to do this.
    What I do right now is:
    Code (CSharp):
    1. atlas.Add(spriteFiles.ToArray());
    2.  
    3. //This texture settings are only for the primary texture. Is there a way of doing the same to the secondary Normal Map?
    4.         SpriteAtlasTextureSettings newTextSettings = new SpriteAtlasTextureSettings();
    5.         newTextSettings.filterMode = FilterMode.Point;
    6.         newTextSettings.sRGB = true;    
    7.         atlas.SetTextureSettings(newTextSettings);
    8.  
    9.         TextureImporterPlatformSettings newPlatformSettings = new TextureImporterPlatformSettings();
    10.         newPlatformSettings.textureCompression = TextureImporterCompression.Uncompressed;
    11.         atlas.SetPlatformSettings(newPlatformSettings);
    12.  
    13.          AssetDatabase.CreateAsset(atlas, atlasPath);
    14.         AssetDatabase.SaveAssets();
    Is not the biggest of the deals (the script already lifts a lot of work for me), but I would like to spare me some repetitive clicks.
     

    Attached Files:

  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    in this code you don't seem to be accessing
    SpriteAtlas
    object, but
    SpriteAtlasAsset
    .
    SpriteAtlas
    does not have
    SetTextureSettings
    and
    SetPlatformSettings
    .

    it makes sense to show your entire code, not just a misleading part of it.
     
  3. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    "atlas" is a SpriteAtlas. SetTextureSettings and SetPlatformSettings come from Sprite Atlas Extensions.
     

    Attached Files:

  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Ah ok right, it's an editor-only thing. I apologize then, this thing really has documentation all over the place.
     
  5. ChiwTheNeko

    ChiwTheNeko

    Joined:
    Mar 24, 2022
    Posts:
    107
    Did you find a solution to this? Seems the only way to do it is SpriteAtlasExtensions.SetSecondaryColorSpace() which is internal.