Example #1
0
 public override void Collect()
 {
     goCollector.go = AssetDatabase.LoadAssetAtPath <GameObject>(path);
     goCollector.Collect();
     sprites = new UnityEngine.UI.Sprite[goCollector.sprites.Length];
     Array.Copy(goCollector.sprites, sprites, sprites.Length);
 }
Example #2
0
        /// <summary>
        /// Info String drawn at the bottom of the Preview
        /// </summary>

        public override string GetInfoString()
        {
            Image image = target as Image;
            Sprite sprite = image.sprite;

            int x = (sprite != null) ? Mathf.RoundToInt(sprite.rect.width) : 0;
            int y = (sprite != null) ? Mathf.RoundToInt(sprite.rect.height) : 0;

            return string.Format("Image Size: {0}x{1}", x, y);
        }
Example #3
0
 public static UnityEngine.Sprite GetUnitySprite(UnityEngine.UI.Sprite sprite)
 {
     return(sprite.sprite);
 }
Example #4
0
 public static bool CheckSpriteIsNull(UnityEngine.UI.Sprite sprite)
 {
     return(sprite == null || sprite.type != UnityEngine.UI.Sprite.Type.Sprite);
 }
Example #5
0
            public override void Collect()
            {
                var state = comp.spriteState;

                sprites = new UnityEngine.UI.Sprite[] { state.highlightedSprite, state.pressedSprite, state.disabledSprite };
            }
Example #6
0
 public override void Collect()
 {
     sprites = new UnityEngine.UI.Sprite[] { comp.sprite };
 }
Example #7
0
        private static void MapAtlas2Sprite(string targetFolder, List <UnityEngine.UI.Sprite> sprites)
        {
            var atlasRaw2AtlasFolder  = new Dictionary <string, string>();
            var atlasRaw2AtlasSprites = new Dictionary <string, Dictionary <string, string> >();

            foreach (var sprite in sprites)
            {
                if (sprite != null && sprite.type == UnityEngine.UI.Sprite.Type.Atlas)
                {
                    var path = AssetDatabase.GetAssetPath(sprite.atlasRaw);
                    if (!string.IsNullOrEmpty(path))
                    {
                        atlasRaw2AtlasFolder[path]  = Path.Combine(targetFolder, Path.GetFileName(Path.GetDirectoryName(path)));
                        atlasRaw2AtlasSprites[path] = new Dictionary <string, string>();
                    }
                }
            }
            foreach (var pair in atlasRaw2AtlasFolder)
            {
                var atlasPath     = pair.Key;
                var targetPath    = pair.Value;
                var atlasFolder   = Path.GetDirectoryName(atlasPath);
                var atlasTag      = Path.GetFileName(atlasFolder);
                var atlasRaw      = AssetDatabase.LoadAssetAtPath <AtlasRaw>(atlasPath);
                var spriteRaws    = atlasRaw.bins.SelectMany(i => i.sprites).ToArray();
                var exportSprites = AtlasPacker.Export(atlasRaw, spriteRaws, targetPath);
                for (int i = 0; i < exportSprites.Length; i++)
                {
                    atlasRaw2AtlasSprites[atlasPath][spriteRaws[i].name] = exportSprites[i];
                    var maxTextureSize = PackUtil.Scale2POT((int)Mathf.Max(spriteRaws[i].rect.width, spriteRaws[i].rect.height));
                    var binRaw         = atlasRaw.bins[spriteRaws[i].bin];
                    var compressed     = (PackQuality)binRaw.quality != PackQuality.Full;
                    var tranparency    = PackUtil.CheckAtlasBinTranparency(binRaw);
                    var importer       = (TextureImporter)AssetImporter.GetAtPath(exportSprites[i]);
                    importer.textureType         = TextureImporterType.Sprite;
                    importer.spritePivot         = spriteRaws[i].pivot;
                    importer.spriteBorder        = spriteRaws[i].border;
                    importer.spritePackingTag    = atlasTag;
                    importer.isReadable          = false;
                    importer.maxTextureSize      = maxTextureSize;
                    importer.mipmapEnabled       = false;
                    importer.wrapMode            = TextureWrapMode.Clamp;
                    importer.npotScale           = TextureImporterNPOTScale.None;
                    importer.textureCompression  = TextureImporterCompression.Uncompressed;
                    importer.alphaIsTransparency = true;
                    if (compressed)
                    {
                        importer.SetPlatformTextureSettings(new TextureImporterPlatformSettings()
                        {
                            name               = "Standalone",
                            overridden         = true,
                            maxTextureSize     = maxTextureSize,
                            compressionQuality = (int)TextureCompressionQuality.Normal,
                            format             = TextureImporterFormat.DXT5,
                        });
                        importer.SetPlatformTextureSettings(new TextureImporterPlatformSettings()
                        {
                            name               = "iPhone",
                            overridden         = true,
                            maxTextureSize     = maxTextureSize,
                            compressionQuality = (int)TextureCompressionQuality.Normal,
                            format             = tranparency ? TextureImporterFormat.RGBA16 : TextureImporterFormat.RGB16,
                        });
                        importer.SetPlatformTextureSettings(new TextureImporterPlatformSettings()
                        {
                            name               = "Android",
                            overridden         = true,
                            maxTextureSize     = maxTextureSize,
                            compressionQuality = (int)TextureCompressionQuality.Normal,
                            format             = tranparency ? TextureImporterFormat.ETC2_RGBA8 : TextureImporterFormat.ETC2_RGB4,
                        });
                    }
                    else
                    {
                        importer.SetPlatformTextureSettings(new TextureImporterPlatformSettings()
                        {
                            name       = "Standalone",
                            overridden = false,
                        });
                        importer.SetPlatformTextureSettings(new TextureImporterPlatformSettings()
                        {
                            name       = "iPhone",
                            overridden = false,
                        });
                        importer.SetPlatformTextureSettings(new TextureImporterPlatformSettings()
                        {
                            name       = "Android",
                            overridden = false,
                        });
                    }
                    importer.SaveAndReimport();
                }
            }
            for (int i = 0; i < sprites.Count; i++)
            {
                var sprite = sprites[i];
                if (sprite != null && sprite.type == UnityEngine.UI.Sprite.Type.Atlas)
                {
                    var atlasPath = AssetDatabase.GetAssetPath(sprite.atlasRaw);
                    if (atlasRaw2AtlasSprites.ContainsKey(atlasPath))
                    {
                        var atlasSprites = atlasRaw2AtlasSprites[atlasPath];
                        if (atlasSprites.ContainsKey(sprites[i].spriteName))
                        {
                            var spritePath  = atlasSprites[sprites[i].spriteName];
                            var unitySprite = AssetDatabase.LoadAssetAtPath <UnityEngine.Sprite>(spritePath);
                            sprites[i] = new UnityEngine.UI.Sprite(unitySprite);
                        }
                    }
                }
            }
        }
Example #8
0
        private static void MapSprite2Atlas(string targetFolder, PackSetting setting, List <UnityEngine.UI.Sprite> sprites)
        {
            var spritePaths = new List <string>();

            foreach (var sprite in sprites)
            {
                if (sprite != null && sprite.type == UnityEngine.UI.Sprite.Type.Sprite)
                {
                    var path = AssetDatabase.GetAssetPath(sprite.sprite);
                    if (!string.IsNullOrEmpty(path) && !spritePaths.Contains(path))
                    {
                        spritePaths.Add(path);
                    }
                }
            }
            var pathSpriteMap = new Dictionary <string, UnityEngine.UI.Sprite>();
            var spriteGroups  = spritePaths.GroupBy(path =>
            {
                var importer = AssetImporter.GetAtPath(path) as TextureImporter;
                return(importer.spritePackingTag);
            });

            foreach (var group in spriteGroups)
            {
                var groupPaths   = group.ToArray();
                var groupNames   = Util.MapSpritePath2SpriteNameInAtlas(groupPaths);
                var groupSprites = new PackAssetSprite[groupPaths.Length];
                for (int i = 0; i < groupPaths.Length; i++)
                {
                    groupSprites[i] = new PackAssetSprite(groupPaths[i])
                    {
                        name = groupNames[i]
                    };
                    groupSprites[i].quality = PackUtil.CheckTextureCompressed(groupPaths[i]) ? PackQuality.AlphaSplit : PackQuality.Full;
                }
                var groupTag    = string.IsNullOrEmpty(group.Key) ? EmptyTagName : group.Key;
                var groupFolder = Path.Combine(targetFolder, groupTag);
                if (!Directory.Exists(groupFolder))
                {
                    Directory.CreateDirectory(groupFolder);
                }
                var atlasRaw = AtlasPacker.Pack(groupFolder, groupSprites, setting);
                for (int i = 0; i < groupPaths.Length; i++)
                {
                    pathSpriteMap[groupPaths[i]] = new UnityEngine.UI.Sprite(atlasRaw, groupNames[i]);
                }
            }
            ;
            for (int i = 0; i < sprites.Count; i++)
            {
                var sprite = sprites[i];
                if (sprite != null && sprite.type == UnityEngine.UI.Sprite.Type.Sprite)
                {
                    var path = AssetDatabase.GetAssetPath(sprite.sprite);
                    if (!string.IsNullOrEmpty(path))
                    {
                        sprites[i] = pathSpriteMap[path];
                    }
                }
            }
        }