Пример #1
0
    public static void AggregateAtlases(PackedSpriteGroup psg)
    {
        string path   = AssetDatabase.GetAssetPath(psg);
        string suffix = psg.name + StringExtensions.ASSET_SUFFIX;

        path = path.Replace(suffix, "");
        Debug.Log("root path = " + path);
        List <string>   relativePaths = new List <string>();
        List <Sprite[]> sprites       = new List <Sprite[]>();

        Texture2D[] atlases = GetAtPath <Texture2D>(path, relativePaths, sprites);

        List <PackedSpriteGroup.AtlasEntry> atlasEntries = new List <PackedSpriteGroup.AtlasEntry>();

        for (int i = 0; i < atlases.Length; ++i)
        {
            PackedSpriteGroup.AtlasEntry atlasEntry = new PackedSpriteGroup.AtlasEntry();
            atlasEntry.RelativePath = relativePaths[i];
            atlasEntry.AtlasName    = atlases[i].name;
            atlasEntry.Sprites      = sprites[i];
            atlasEntries.Add(atlasEntry);
        }
        psg.Atlases = atlasEntries.ToArray();

        EditorUtility.SetDirty(psg);
        AssetDatabase.SaveAssets();
    }
Пример #2
0
    private void aggregateInformation()
    {
        _atlases = new Dictionary <string, Dictionary <string, Texture2D> >();
        _sprites = new Dictionary <string, Dictionary <string, Sprite[]> >();

        for (int i = 0; i < this.SpriteGroups.Length; ++i)
        {
            for (int j = 0; j < this.SpriteGroups[i].Atlases.Length; ++j)
            {
                PackedSpriteGroup.AtlasEntry atlasEntry = this.SpriteGroups[i].Atlases[j];
                if (!_atlases.ContainsKey(atlasEntry.RelativePath))
                {
                    _atlases.Add(atlasEntry.RelativePath, new Dictionary <string, Texture2D>());
                }
                if (!_sprites.ContainsKey(atlasEntry.RelativePath))
                {
                    _sprites.Add(atlasEntry.RelativePath, new Dictionary <string, Sprite[]>());
                }
                _atlases[atlasEntry.RelativePath].Add(atlasEntry.AtlasName, atlasEntry.Atlas);
                _sprites[atlasEntry.RelativePath].Add(atlasEntry.AtlasName, atlasEntry.Sprites);
            }
        }
    }