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);
        }
Exemplo n.º 2
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);
        }
        static void DrawIconTextureSlot(Rect elementRect, int row, DrawableResourceData data, ImageSize size, NotificationIconType newType, string newId, UnityEngine.Object target)
        {
            Rect  elementContentRect = GetContentRect(elementRect, 6f, 12f);
            float errorMsgWidth      = elementRect.width - kSlotSize * 3;

            var textureRect = new Rect(elementContentRect.width - (kMaxPreviewSize * 2 - kIconSpacing * 5),
                                       elementContentRect.y + kIconSpacing * row + kSlotSize * row, kMaxPreviewSize, kSlotSize);

            var errorBoxRect = GetContentRect(
                new Rect(elementContentRect.x,
                         elementContentRect.y + kIconSpacing * row + kSlotSize * row, errorMsgWidth, kSlotSize),
                4f, 4f);

            Rect previewTextureRect = new Rect(elementContentRect.width - (kMaxPreviewSize - kIconSpacing * 5),
                                               elementContentRect.y + kIconSpacing * row + kSlotSize * row, kMaxPreviewSize, kSlotSize);

            Texture2D assetTexture = null;

            if (size == ImageSize.XXHDPI)
            {
                assetTexture = data.AssetXXHDPI;
            }

            if (size == ImageSize.XHDPI)
            {
                assetTexture = data.AssetXHDPI;
            }

            if (size == ImageSize.HDPI)
            {
                assetTexture = data.AssetHDPI;
            }

            if (size == ImageSize.MDPI)
            {
                assetTexture = data.AssetMDPI;
            }

            if (size == ImageSize.LDPI)
            {
                assetTexture = data.AssetLDPI;
            }


            var newAsset = (Texture2D)EditorGUI.ObjectField(
                textureRect,
                assetTexture,
                typeof(Texture2D),
                false);

            // ---

            bool updatePreviewTexture = (newId != data.Id || newType != data.Type || newAsset != data.Asset);

            if (updatePreviewTexture)
            {
                Undo.RegisterCompleteObjectUndo(target, "Update icon data.");
                data.Id    = newId;
                data.Type  = newType;
                data.Asset = newAsset;

                if (size == ImageSize.XXHDPI)
                {
                    data.AssetXXHDPI = newAsset;
                }

                if (size == ImageSize.XHDPI)
                {
                    data.AssetXHDPI = newAsset;
                }

                if (size == ImageSize.HDPI)
                {
                    data.AssetHDPI = newAsset;
                }

                if (size == ImageSize.MDPI)
                {
                    data.AssetMDPI = newAsset;
                }

                if (size == ImageSize.LDPI)
                {
                    data.AssetLDPI = newAsset;
                }

                data.previewTexture = data.GetPreviewTexture(updatePreviewTexture);

                data.Clean();
                data.Verify();
            }

            // TODO Allocates a lot of memory for some reason, cache.


            if (data.Asset != null && !data.Verify())
            {
                EditorGUI.HelpBox(
                    errorBoxRect,
                    "Specified texture can't be used because: \n" + (errorMsgWidth > 145
                                                ? DrawableResourceData.GenerateErrorString(data.Errors)
                                                : "...expand to see more..."),
                    MessageType.Error
                    );

                if (data.Type == NotificationIconType.SmallIcon)
                {
                    GUIStyle helpBoxMessageTextStyle = new GUIStyle(GUI.skin.label);
                    helpBoxMessageTextStyle.fontSize  = 8;
                    helpBoxMessageTextStyle.wordWrap  = true;
                    helpBoxMessageTextStyle.alignment = TextAnchor.MiddleCenter;
                    GUI.Box(previewTextureRect, "Preview not available. \n Make sure the texture is readable!", helpBoxMessageTextStyle);
                }
            }
            else
            {
                if (data.previewTexture != null)
                {
                    GUIStyle previewLabelTextStyle = new GUIStyle(GUI.skin.label);
                    previewLabelTextStyle.fontSize  = 8;
                    previewLabelTextStyle.wordWrap  = true;
                    previewLabelTextStyle.alignment = TextAnchor.UpperCenter;

                    EditorGUI.LabelField(previewTextureRect, "Preview", previewLabelTextStyle);

                    Rect previewTextureRectPadded = GetContentRect(previewTextureRect, 6f, 6f);
                    previewTextureRectPadded.y += 8;

                    data.previewTexture.alphaIsTransparency = false;
                    GUI.DrawTexture(previewTextureRectPadded, data.previewTexture);
                }
            }
        }
Exemplo n.º 4
0
        void DrawIconDataElement(Rect rect, int index, bool selected, bool focused)
        {
            var drawableResourceDataRef = m_ResourceAssets.GetArrayElementAtIndex(index);
            var elementRect             = rect;

            int slotHeight = kSlotSize;

            if (drawableResourceDataRef != null)
            {
                var idProperty    = drawableResourceDataRef.FindPropertyRelative("Id");
                var typeProperty  = drawableResourceDataRef.FindPropertyRelative("Type");
                var assetProperty = drawableResourceDataRef.FindPropertyRelative("Asset");

                float width = Mathf.Min(elementRect.width,
                                        EditorGUIUtility.labelWidth + 4 + kSlotSize + kIconSpacing + kMaxPreviewSize);

                float idPropWidth    = Mathf.Min(kMaxPreviewSize, width - kSlotSize - kIconSpacing);
                float typePropWidth  = Mathf.Min(kMaxPreviewSize, width - kSlotSize - kIconSpacing);
                float assetPropWidth = kMaxPreviewSize;
                float errorMsgWidth  = elementRect.width - kPadding * 2;               //(elementRect.width - (assetPropWidth * 2 + kIconSpacing *2 )) - (elementRect.x + kSlotSize + typePropWidth);

                Rect elementContentRect = GetContentRect(elementRect, 6f, 12f);

                Rect previewTextureRect = new Rect(elementContentRect.width - (assetPropWidth - kIconSpacing * 5),
                                                   elementContentRect.y - 6, assetPropWidth, slotHeight);

                Rect textureRect =
                    new Rect(elementContentRect.width - (assetPropWidth * 2 - kIconSpacing * 5),
                             elementContentRect.y, assetPropWidth, slotHeight);


                Rect errorBoxRect = GetContentRect(
                    new Rect(elementContentRect.x,
                             elementContentRect.y + kSlotSize, errorMsgWidth, slotHeight),
                    4f, 4f);

                EditorGUI.LabelField(
                    new Rect(elementContentRect.x, elementContentRect.y, idPropWidth, 20),
                    "Identifier"
                    );

                EditorGUI.LabelField(
                    new Rect(elementContentRect.x, elementContentRect.y + 25, idPropWidth, 20),
                    "Type"
                    );

                EditorGUI.BeginChangeCheck();

                var data = GetElementData(index);

                var newId = EditorGUI.TextField(
                    new Rect(elementContentRect.x + kSlotSize, elementContentRect.y, idPropWidth, 20),
                    data.Id);

                var newType = (NotificationIconType)EditorGUI.EnumPopup(
                    new Rect(elementContentRect.x + kSlotSize, elementContentRect.y + 25, typePropWidth, 20),
                    (NotificationIconType)(int)data.Type
                    );

                var newAsset = (Texture2D)EditorGUI.ObjectField(
                    textureRect,
                    data.Asset,
                    typeof(Texture2D),
                    false);

                bool updatePreviewTexture = (newId != data.Id || newType != data.Type || newAsset != data.Asset);

                if (updatePreviewTexture)
                {
                    Undo.RegisterCompleteObjectUndo(target, "Update icon data.");
                    data.Id    = newId;
                    data.Type  = newType;
                    data.Asset = newAsset;
                    data.Clean();
                    data.Verify();
                }

                Texture2D previewTexture = data.GetPreviewTexture(updatePreviewTexture);

                if (previewTexture != null)
                {
                    GUIStyle previewLabelTextStyle = new GUIStyle(GUI.skin.label);
                    previewLabelTextStyle.fontSize  = 8;
                    previewLabelTextStyle.wordWrap  = true;
                    previewLabelTextStyle.alignment = TextAnchor.UpperCenter;

                    EditorGUI.LabelField(previewTextureRect, "Preview", previewLabelTextStyle);

                    Rect previewTextureRectPadded = GetContentRect(previewTextureRect, 6f, 6f);
                    previewTextureRectPadded.y += 8;

                    previewTexture.alphaIsTransparency = false;
                    GUI.DrawTexture(previewTextureRectPadded, previewTexture);
                }

                if (data.Asset != null && !data.IsValid)
                {
                    EditorGUI.HelpBox(
                        errorBoxRect,
                        "Specified texture can't be used because: \n" + (errorMsgWidth > 145
                                                        ? DrawableResourceData.GenerateErrorString(data.Errors)
                                                        : "...expand to see more..."),
                        MessageType.Error
                        );

                    if (data.Type == NotificationIconType.SmallIcon)
                    {
                        GUIStyle helpBoxMessageTextStyle = new GUIStyle(GUI.skin.label);
                        helpBoxMessageTextStyle.fontSize  = 8;
                        helpBoxMessageTextStyle.wordWrap  = true;
                        helpBoxMessageTextStyle.alignment = TextAnchor.MiddleCenter;
                        GUI.Box(previewTextureRect, "Preview not available. \n Make sure fthe texture is readable!", helpBoxMessageTextStyle);
                    }
                }
            }
        }