private static List <SpRect> CompileSources(List <SpSource> sources) { var rects = new List <SpRect>(); for (var i = sources.Count - 1; i >= 0; i--) { var source = sources[i]; var sourceTexture = source.Texture; if (sourceTexture != null) { var sourcePath = source.Path; var sourcePixels = default(SpPixels); var sourceSprites = source.Sprites; var sourceImporter = SpHelper.GetAssetImporter <TextureImporter>(sourcePath); if (sourceImporter != null) { // Make the texture temporarily readable, or directly read pixels if (sourceImporter.isReadable == false) { sourceImporter.isReadable = true; SpHelper.ReimportAsset(sourcePath); { sourcePixels = new SpPixels(sourceTexture); } sourceImporter.isReadable = false; SpHelper.ReimportAsset(sourcePath); } else { sourcePixels = new SpPixels(sourceTexture); } // Add sprites or whole texture if (sourceSprites.Count > 0) { for (var j = 0; j < sourceSprites.Count; j++) { var sourceSprite = sourceSprites[j]; CompileRect(rects, source, sourcePixels.GetSubset(sourceSprite.rect), sourceSprite.name, sourceSprite); } } else { CompileRect(rects, source, sourcePixels, sourceTexture.name); } continue; } } sources.RemoveAt(i); } rects.Sort((a, b) => Mathf.Max(b.W, b.H) - Mathf.Max(a.W, a.H)); return(rects); }