예제 #1
0
    public static void Convert()
    {
        MadUndo.LegacyRegisterSceneUndo("Convert to Atlas");

        var allSprites = GameObject.FindObjectsOfType(typeof(MadSprite)) as MadSprite[];

        var texturedSprites =
            from sprite in allSprites
            where sprite.inputType == MadSprite.InputType.SingleTexture && sprite.texture != null
            select sprite;

        var textures =
            from sprite in texturedSprites
            select sprite.texture;

        textures = textures.Distinct();

        var atlas = MadAtlasBuilder.CreateAtlas(textures.ToArray());

        if (atlas == null)
        {
            EditorUtility.DisplayDialog("Convert", "Conversion cancelled!", "OK");
            return;
        }

        foreach (var sprite in texturedSprites)
        {
            sprite.inputType    = MadSprite.InputType.TextureAtlas;
            sprite.textureAtlas = atlas;
            string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sprite.texture));
            sprite.textureAtlasSpriteGUID = guid;

            EditorUtility.SetDirty(sprite);
        }

        EditorUtility.DisplayDialog("Convert", "Conversion done! Please save your scene!", "OK");
    }
예제 #2
0
 static void CreateAtlas() {
     MadAtlasBuilder.CreateAtlas();
 }