internal Dictionary <string, byte[]> GenerateDrawableResourcesForExport()
        {
            var icons = new Dictionary <string, byte[]>();

            foreach (var res in TrackedResourceAssets)
            {
                if (!res.Verify())
                {
                    Debug.LogWarning(string.Format("Failed exporting: '{0}' Android notification icon because:\n {1} ", res.Id,
                                                   DrawableResourceData.GenerateErrorString(res.Errors))
                                     );
                    continue;
                }

                var textXhdpi = TextureAssetUtils.ProcessAndResizeTextureForType(res.Asset, res.Type, ImageSize.XHDPI);
                var textHdpi  = TextureAssetUtils.ProcessAndResizeTextureForType(res.Asset, res.Type, ImageSize.HDPI);
                var textMdpi  = TextureAssetUtils.ProcessAndResizeTextureForType(res.Asset, res.Type, ImageSize.MDPI);
                var textLdpi  = TextureAssetUtils.ProcessAndResizeTextureForType(res.Asset, res.Type, ImageSize.LDPI);

                icons[string.Format("drawable-xhdpi-v11/{0}.png", res.Id)] = textXhdpi.EncodeToPNG();
                icons[string.Format("drawable-hdpi-v11/{0}.png", res.Id)]  = textHdpi.EncodeToPNG();
                icons[string.Format("drawable-mdpi-v11/{0}.png", res.Id)]  = textMdpi.EncodeToPNG();
                icons[string.Format("drawable-ldpi-v11/{0}.png", res.Id)]  = textLdpi.EncodeToPNG();

                if (res.Type == NotificationIconType.LargeIcon)
                {
                    var textXxhdpi = TextureAssetUtils.ProcessAndResizeTextureForType(res.Asset, res.Type, ImageSize.XXHDPI);
                    icons[string.Format("drawable-xxhdpi-v11/{0}.png", res.Id)] = textXxhdpi.EncodeToPNG();
                }
            }

            return(icons);
        }
        public void Verify()
        {
            List <string> errors;

            isValid     = TextureAssetUtils.VerifyTextureByType(Asset, Type, out errors);
            this.errors = errors;
        }
        public bool Verify()
        {
            List <string> errors;

            isValid     = TextureAssetUtils.VerifyTextureByType(Asset, Type, out errors);
            this.errors = errors;
            return(isValid);
        }
        public Texture2D GetPreviewTexture(bool update)
        {
            if (Asset == null)
            {
                return(null);
            }

            if (isValid && (previewTexture == null || update))
            {
                previewTexture = TextureAssetUtils.ProcessTextureForType(Asset, Type);
            }

            return(previewTexture);
        }
Example #5
0
        internal Dictionary <string, byte[]> GenerateDrawableResourcesForExport()
        {
            var icons = new Dictionary <string, byte[]>();

            foreach (var res in TrackedResourceAssets)
            {
                if (!res.Verify())
                {
                    Debug.LogWarning(string.Format("Failed exporting: '{0}' AndroidSettings notification icon because:\n {1} ", res.Id,
                                                   DrawableResourceData.GenerateErrorString(res.Errors))
                                     );
                    continue;
                }

                var texture = TextureAssetUtils.ProcessTextureForType(res.Asset, res.Type);

                var scale = res.Type == NotificationIconType.SmallIcon ? 0.375f : 1;

                var textXhdpi = TextureAssetUtils.ScaleTexture(texture, (int)(128 * scale), (int)(128 * scale));
                var textHdpi  = TextureAssetUtils.ScaleTexture(texture, (int)(96 * scale), (int)(96 * scale));
                var textMdpi  = TextureAssetUtils.ScaleTexture(texture, (int)(64 * scale), (int)(64 * scale));
                var textLdpi  = TextureAssetUtils.ScaleTexture(texture, (int)(48 * scale), (int)(48 * scale));

                icons[string.Format("drawable-xhdpi-v11/{0}.png", res.Id)] = textXhdpi.EncodeToPNG();
                icons[string.Format("drawable-hdpi-v11/{0}.png", res.Id)]  = textHdpi.EncodeToPNG();
                icons[string.Format("drawable-mdpi-v11/{0}.png", res.Id)]  = textMdpi.EncodeToPNG();
                icons[string.Format("drawable-ldpi-v11/{0}.png", res.Id)]  = textLdpi.EncodeToPNG();

                if (res.Type == NotificationIconType.LargeIcon)
                {
                    var textXxhdpi = TextureAssetUtils.ScaleTexture(texture, (int)(192 * scale), (int)(192 * scale));
                    icons[string.Format("drawable-xxhdpi-v11/{0}.png", res.Id)] = textXxhdpi.EncodeToPNG();
                }
            }

            return(icons);
        }
        public static Texture2D ProcessAndResizeTextureForType(Texture2D texture, NotificationIconType type, ImageSize size)
        {
            var width  = 0;
            var height = 0;
            var scale  = type == NotificationIconType.SmallIcon ? 0.375f : 1;

            if (size == ImageSize.XXHDPI)
            {
                width  = (int)(192 * scale);
                height = (int)(192 * scale);
            }
            else if (size == ImageSize.XHDPI)
            {
                width  = (int)(128 * scale);
                height = (int)(128 * scale);
            }
            else if (size == ImageSize.HDPI)
            {
                width  = (int)(96 * scale);
                height = (int)(96 * scale);
            }
            else if (size == ImageSize.MDPI)
            {
                width  = (int)(64 * scale);
                height = (int)(64 * scale);
            }
            else if (size == ImageSize.LDPI)
            {
                width  = (int)(48 * scale);
                height = (int)(48 * scale);
            }

            var downscaled = TextureAssetUtils.ScaleTexture(texture, width, height);

            return(TextureAssetUtils.ProcessTextureForType(downscaled, type));
        }
Example #7
0
 public bool Verify()
 {
     m_IsValid = TextureAssetUtils.VerifyTextureByType(Asset, Type, out m_Errors);
     return(m_IsValid);
 }