1
NGUI 3 Support / Multiple import when modifying an atlas
« on: March 24, 2016, 04:21:03 PM »
I'm in the process of fixing some paint points for our artists and a few of the issues revolve around updating the NGUI atlas. We've started using crunch compression for our atlas because the quality is acceptable and the size is excellent (2 MB for a 4k atlas, versus 64 MB truecolor and 16 MB compressed). However, the crunch process takes a while, about 80 seconds on some machines.
The problem is that this longer import time is greatly exacerbated by NGUI. When deleting a sprite from the atlas, for example, the atlas is reimported 5 times. I looked into a bit and it looks like the general flow is:
It seems only one of these reimports is actually necessary. Do you think you'd be able to optimize this? It appears you can work with raw texture data without marking the texture readable. If so, you can use GetRawTextureData, create a temp texture in memory, and LoadRawTextureData to get the atlas in memory for modifications. Then overwrite the file on disk (which shouldn't require the original file being readable either), and reimport once at the very end.
The problem is that this longer import time is greatly exacerbated by NGUI. When deleting a sprite from the atlas, for example, the atlas is reimported 5 times. I looked into a bit and it looks like the general flow is:
- Make atlas readable and extract sprites
- Make atlas non-readable
- Make atlas readable so it can be encoded to PNG
- Overwrite the atlas file on disk and refresh assets
- Make atlas non-readable
It seems only one of these reimports is actually necessary. Do you think you'd be able to optimize this? It appears you can work with raw texture data without marking the texture readable. If so, you can use GetRawTextureData, create a temp texture in memory, and LoadRawTextureData to get the atlas in memory for modifications. Then overwrite the file on disk (which shouldn't require the original file being readable either), and reimport once at the very end.
- Importing 'Assets/GUI/Atlas/GUIAtlas.png'
- 0. AtlasProcessor.OnPreprocessTexture() at Assets/GUI/Editor/AtlasProcessor.cs:10
- 1. UnityEditor.AssetDatabase.ImportAsset()
- 2. NGUIEditorTools.MakeTextureReadable() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:457
- 3. NGUIEditorTools.ImportTexture() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:512
- 4. NGUIEditorTools.ImportTexture() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:532
- 5. UIAtlasMaker.ExtractSprites() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:493
- 6. UIAtlasMaker.OnGUI() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:1013
- Importing 'Assets/GUI/Atlas/GUIAtlas.png'
- 0. AtlasProcessor.OnPreprocessTexture() at Assets/GUI/Editor/AtlasProcessor.cs:10
- 1. UnityEditor.AssetDatabase.ImportAsset()
- 2. NGUIEditorTools.MakeTextureAnAtlas() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:499
- 3. NGUIEditorTools.ImportTexture() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:513
- 4. NGUIEditorTools.ImportTexture() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:532
- 5. UIAtlasMaker.ExtractSprites() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:530
- 6. UIAtlasMaker.OnGUI() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:1013
- Importing 'Assets/GUI/Atlas/GUIAtlas.png'
- 0. AtlasProcessor.OnPreprocessTexture() at Assets/GUI/Editor/AtlasProcessor.cs:10
- 1. UnityEditor.AssetDatabase.ImportAsset()
- 2. NGUIEditorTools.MakeTextureReadable() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:457
- 3. NGUIEditorTools.ImportTexture() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:512
- 4. UIAtlasMaker.UpdateTexture() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:570
- 5. UIAtlasMaker.UpdateAtlas() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:689
- 6. UIAtlasMaker.OnGUI() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:1027
- Importing 'Assets/GUI/Atlas/GUIAtlas.png'
- 0. AtlasProcessor.OnPreprocessTexture() at Assets/GUI/Editor/AtlasProcessor.cs:10
- 1. UnityEditor.AssetDatabase.Refresh()
- 2. UIAtlasMaker.UpdateTexture() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:582
- 3. UIAtlasMaker.UpdateAtlas() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:689
- 4. UIAtlasMaker.OnGUI() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:1027
- Importing 'Assets/GUI/Atlas/GUIAtlas.png'
- 0. AtlasProcessor.OnPreprocessTexture() at Assets/GUI/Editor/AtlasProcessor.cs:10
- 1. UnityEditor.AssetDatabase.ImportAsset()
- 2. NGUIEditorTools.MakeTextureAnAtlas() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:499
- 3. NGUIEditorTools.ImportTexture() at Assets/Plugins/NGUI/Scripts/Editor/NGUIEditorTools.cs:513
- 4. UIAtlasMaker.UpdateTexture() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:583
- 5. UIAtlasMaker.UpdateAtlas() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:689
- 6. UIAtlasMaker.OnGUI() at Assets/Plugins/NGUI/Scripts/Editor/UIAtlasMaker.cs:1027