public SimpleNotification(NotificationOptions options, NotificationIconType type) : base(options) { InitializeComponent(); string icoKey = ""; switch (type) { case NotificationIconType.Info: icoKey = "InfoIco"; break; case NotificationIconType.Warn: icoKey = "WarnIco"; break; case NotificationIconType.Error: icoKey = "ErrorIco"; break; case NotificationIconType.Lock: icoKey = "LockIco"; break; } Icon.Content = this.TryFindResource(icoKey); this.PreviewKeyDown += HandleEsc; }
public void Notify(string title, string message, NotificationIconType iconType, bool keepInCentral = true) => Notify(i => { i.Title = title; i.Message = message; i.IconType = iconType; i.IsKeepInCentral = keepInCentral; });
public static bool VerifyTextureByType(Texture2D texture, NotificationIconType type, out List <string> errors) { errors = new List <string>(); if (texture == null) { errors.Add("no valid texture is assigned"); return(false); } var needsAlpha = true; var minSize = 48; if (type == NotificationIconType.LargeIcon) { needsAlpha = false; minSize = 192; } var isSquare = texture.width == texture.height; var isLargeEnough = texture.width >= minSize; var hasAlpha = true;// texture.format == TextureFormat.Alpha8; string assetPath = AssetDatabase.GetAssetPath(texture); var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter; var isReadable = importer != null && importer.isReadable; if (!isReadable) { errors.Add("Read/Write is not enabled in the texture importer"); } if (!isLargeEnough) { errors.Add(string.Format("it must be atleast {0}x{1} pixels (while it's {2}x{3})", minSize, minSize, texture.width, texture.height )); } if (!isSquare) { errors.Add(string.Format("it must have the same width and height (while it's {0}x{1})", texture.width, texture.height )); } if (!hasAlpha && needsAlpha) { errors.Add(string.Format("contain an alpha channel")); } return(isReadable && isSquare && isLargeEnough && (!needsAlpha || hasAlpha)); }
/// <summary> /// Add image to notification settings. /// </summary> /// <param name="id">Image identifier</param> /// <param name="image">Image texture, must be obtained from asset database</param> /// <param name="type">Image type</param> public static void AddDrawableResource(string id, Texture2D image, NotificationIconType type) { var manager = NotificationSettingsManager.Initialize(); manager.AddDrawableResource(id, image, type); #if UNITY_2020_2_OR_NEWER SettingsService.RepaintAllSettingsWindow(); #endif }
internal void RegisterDrawableResource(string id, Texture2D image, NotificationIconType type) { var drawableResource = new DrawableResourceData(); drawableResource.Id = id; drawableResource.Type = type; drawableResource.Asset = image; TrackedResourceAssets.Add(drawableResource); }
public void AddDrawableResource(string id, Texture2D image, NotificationIconType type) { var drawableResource = new DrawableResourceData(); drawableResource.Id = id; drawableResource.Type = type; drawableResource.Asset = image; DrawableResources.Add(drawableResource); SaveSettings(); }
public NotificationViewModel(string text, string title = null, int timeout = 5000, NotificationIconType iconType = NotificationIconType.None, string customIconTypeClass = "", bool addToCookie = true) { Text = text; Title = title; Timeout = timeout; IconType = iconType; CustomIconTypeClass = customIconTypeClass; Icon = GetHtmlForIconType(); if (addToCookie) { this.AddToCookie(); } }
public static Texture2D ProcessTextureForType(Texture2D sourceTexture, NotificationIconType type) { if (sourceTexture == null) { return(null); } string assetPath = AssetDatabase.GetAssetPath(sourceTexture); var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter; if (importer != null && !importer.isReadable) { return(null); } var textureFormat = type == NotificationIconType.LargeIcon ? sourceTexture.format : TextureFormat.RGBA32; Texture2D texture; if (type == NotificationIconType.SmallIcon) { texture = new Texture2D(sourceTexture.width, sourceTexture.height, TextureFormat.RGBA32, true, false); for (var i = 0; i < sourceTexture.mipmapCount; i++) { var c_0 = sourceTexture.GetPixels(i); var c_1 = texture.GetPixels(i); for (var i1 = 0; i1 < c_0.Length; i1++) { var a = c_0[i1].r + c_0[i1].g + c_0[i1].b; c_1[i1].r = c_1[i1].g = c_1[i1].b = a > 127 ? 0 : 1; c_1[i1].a = c_0[i1].a; } texture.SetPixels(c_1, i); sourceTexture.filterMode = FilterMode.Point; } texture.Apply(); } else { texture = new Texture2D(sourceTexture.width, sourceTexture.height, TextureFormat.RGBA32, true); texture.SetPixels(sourceTexture.GetPixels()); texture.Apply(); } return(texture); }
public void AddDrawableResource(string id, Texture2D image, NotificationIconType type) { /* commenting out for now, since you can have same Id's in editor * foreach (var drawable in DrawableResources) * { * if (drawable.Id == id) * { * Debug.LogWarning("Drawable with Id"+id+" already exists, please assign another Id"); * return; * } * } */ var drawableResource = new DrawableResourceData(); drawableResource.Id = id; drawableResource.Type = type; drawableResource.Asset = image; DrawableResources.Add(drawableResource); SaveSettings(); }
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)); }
public void SendPictureNotificationToAll(string body, NotificationPicType pic, int flash, NotificationIconType iconType, string sender, string subject) { //Crash with new LocalPlayerArgument()! SendNativeCallToAll(0x202709F4C58A0424, "STRING"); SendNativeCallToAll(0x6C188BE134E074AA, body); SendNativeCallToAll(0x1CCD9A37359072CF, pic.ToString(), pic.ToString(), flash, (int)iconType, sender, subject); SendNativeCallToAll(0xF020C96915705B3A, false, true); }
/// <summary> /// Retrieves the icon texture from the existing notification icons. /// </summary> /// <param name="iconType"> /// The icon type /// </param> /// <returns> /// The <see cref="Texture" />. /// </returns> public static Texture GetIcon(NotificationIconType iconType) { Texture texture; return(IconTextures.TryGetValue(iconType, out texture) ? texture : null); }
/// <summary> /// Retrieves the icon texture from the existing notification icons. /// </summary> /// <param name="iconType"> /// The icon type /// </param> /// <returns> /// The <see cref="Texture" />. /// </returns> public static Texture GetIcon(NotificationIconType iconType) { Texture texture; return IconTextures.TryGetValue(iconType, out texture) ? texture : null; }
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); } } }
public static void AddToCookie(string text, string title = null, int timeout = 5000, NotificationIconType iconType = NotificationIconType.None, string customIconTypeClass = "") { new NotificationViewModel(text, title, timeout, iconType, customIconTypeClass); }
public DrawableResourceData(string id, NotificationIconType type) { Id = id; Type = type; }
public void ShowNotification(string notificationId, string title, string message, NotificationIconType notificationType, NotificationOptions options) { Screen screen = GetCurrentScreen(); if (string.IsNullOrWhiteSpace(notificationId)) { notificationId = DEFAULT_NOTIFICATION_ID; } SimpleNotification notification = new SimpleNotification(options ?? new NotificationOptions(), notificationType) { DataContext = new SimpleNotificationViewModel { Title = title, Message = message, ObservableId = notificationId, } }; if (notification.Options.IsReplace) { var matchingNotificationViews = GetNotifications().Where(n => (n.DataContext as SimpleNotificationViewModel)?.ObservableId == notificationId); foreach (var notificationView in matchingNotificationViews) { if (notificationView.DataContext is SimpleNotificationViewModel matchingNotificationViewModel) { //Close old notification when: //1) Notification with matching ID is found but this ID is not the default //2) Notification with default ID and matching content is found if (matchingNotificationViewModel.ObservableId == notificationId) { if (matchingNotificationViewModel.ObservableId != DEFAULT_NOTIFICATION_ID) { notificationView.Close(); } else if (matchingNotificationViewModel.Message == message && matchingNotificationViewModel.Title == title) { notificationView.Close(); } } } } } // Do not create notifications without content if (string.IsNullOrWhiteSpace(message)) { return; } AddNotification(screen, notification); }