Exemplo n.º 1
0
        private void InjectAndroidManifest(string projectPath)
        {
            var manifestPath = string.Format("{0}/src/main/AndroidManifest.xml", projectPath);

            if (!File.Exists(manifestPath))
            {
                throw new FileNotFoundException(string.Format("'{0}' doesn't exist.", manifestPath));
            }

            XmlDocument manifestDoc = new XmlDocument();

            manifestDoc.Load(manifestPath);

            InjectReceivers(manifestPath, manifestDoc);

            var settings = NotificationSettingsManager.Initialize().AndroidNotificationSettingsFlat;

            var useCustomActivity = (bool)settings.Find(i => i.key == "UnityNotificationAndroidUseCustomActivity").val;

            if (useCustomActivity)
            {
                var customActivity = (string)settings.Find(i => i.key == "UnityNotificationAndroidCustomActivityString").val;
                AppendAndroidMetadataField(manifestPath, manifestDoc, "custom_notification_android_activity", customActivity);
            }

            var enableRescheduleOnRestart = (bool)settings.Find(i => i.key == "UnityNotificationAndroidRescheduleOnDeviceRestart").val;

            if (enableRescheduleOnRestart)
            {
                AppendAndroidMetadataField(manifestPath, manifestDoc, "reschedule_notifications_on_restart", "true");
                AppendAndroidPermissionField(manifestPath, manifestDoc, "android.permission.RECEIVE_BOOT_COMPLETED");
            }

            manifestDoc.Save(manifestPath);
        }
            /// <summary>
            /// Remove all images from notification settings.
            /// </summary>
            public static void ClearDrawableResources()
            {
                var manager = NotificationSettingsManager.Initialize();

                manager.ClearDrawableResources();
#if UNITY_2020_2_OR_NEWER
                SettingsService.RepaintAllSettingsWindow();
#endif
            }
            /// <summary>
            /// Remove icon with given identifier from notification settings.
            /// </summary>
            /// <param name="id">ID of the image to remove</param>
            public static void RemoveDrawableResource(string id)
            {
                var manager = NotificationSettingsManager.Initialize();

                manager.RemoveDrawableResourceById(id);
#if UNITY_2020_2_OR_NEWER
                SettingsService.RepaintAllSettingsWindow();
#endif
            }
            /// <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
            }
        DrawableResourceData GetElementData(int index)
        {
            var res = NotificationSettingsManager.Initialize().TrackedResourceAssets;

            if (index < res.Count)
            {
                return(res[index]);
            }
            return(null);
        }
Exemplo n.º 6
0
        private static void SetSettingValue <T>(BuildTargetGroup target, string key, T value)
        {
            var manager = NotificationSettingsManager.Initialize();

            NotificationSetting setting = GetSetting(target, key);

            if (setting != null)
            {
                setting.Value = value;
                manager.SaveSetting(setting, target);
            }
        }
        static SettingsProvider CreateMobileNotificationsSettingsProvider()
        {
            var settingsAsset = NotificationSettingsManager.Initialize();

            if (settingsAsset != null)
            {
                var provider = AssetSettingsProvider.CreateProviderFromObject("Project/Mobile Notifications", settingsAsset);
                provider.label = "Mobile Notifications";
                return(provider);
            }

            return(null);
        }
Exemplo n.º 8
0
        private static NotificationSetting GetSetting(BuildTargetGroup target, string key)
        {
            var manager = NotificationSettingsManager.Initialize();

            NotificationSetting setting = null;

            if (target == BuildTargetGroup.Android)
            {
                setting = manager.AndroidNotificationSettingsFlat.Find(i => i.Key == key);
            }
            else if (target == BuildTargetGroup.iOS)
            {
                setting = manager.iOSNotificationSettingsFlat.Find(i => i.Key == key);
            }

            return(setting);
        }
Exemplo n.º 9
0
        private void Initialize()
        {
            label             = "Mobile Notifications";
            m_SettingsManager = NotificationSettingsManager.Initialize();

            // These two are for ReorderableList.
            m_SettingsManagerObject = new SerializedObject(m_SettingsManager);
            m_DrawableResources     = m_SettingsManagerObject.FindProperty("DrawableResources");

            // ReorderableList is only used to draw the drawable resources for Android settings.
            InitReorderableList();

            Undo.undoRedoPerformed += () =>
            {
                m_SettingsManagerObject.UpdateIfRequiredOrScript();
                Repaint();
            };
        }
Exemplo n.º 10
0
        private void CopyNotificationResources(string projectPath)
        {
            // The projectPath points to the the parent folder instead of the actual project path.
            if (!Directory.Exists(Path.Combine(projectPath, "src")))
            {
                projectPath = Path.Combine(projectPath, PlayerSettings.productName);
            }

            // Get the icons set in the UnityNotificationEditorManager and write them to the res folder, then we can use the icons as res.
            var icons = NotificationSettingsManager.Initialize().GenerateDrawableResourcesForExport();

            foreach (var icon in icons)
            {
                var fileInfo = new FileInfo(string.Format("{0}/src/main/res/{1}", projectPath, icon.Key));
                if (fileInfo.Directory != null)
                {
                    fileInfo.Directory.Create();
                    File.WriteAllBytes(fileInfo.FullName, icon.Value);
                }
            }
        }
        void OnEnable()
        {
            manager = NotificationSettingsManager.Initialize();
            manager.CustomEditor = this;

            if (target == null)
            {
                return;
            }

            m_Target = new SerializedObject(target);

            m_ResourceAssets = serializedObject.FindProperty("TrackedResourceAssets");

            m_ReorderableList = new ReorderableList(serializedObject, m_ResourceAssets, false, true, true, true);
            m_ReorderableList.elementHeight = kSlotSize + kIconSpacing;

            m_ReorderableList.showDefaultBackground = false;

            m_ReorderableList.drawHeaderCallback = (rect) =>
            {
                if (Event.current.type == EventType.Repaint)
                {
                    var headerBackground = new GUIStyle("RL Header");

                    var paddedRect = GetContentRect(rect,
                                                    1f,
                                                    (ReorderableList.Defaults.padding + 2f) * -1);

                    headerBackground.Draw(
                        paddedRect,
                        false, false, false, false);

                    var labelRect = GetContentRect(paddedRect, 0f, 3f);

                    GUI.Label(labelRect, "Notification Icons", EditorStyles.label);
                }
            };
            m_ReorderableList.onAddCallback = (list) =>
            {
                AddIconDataElement(list);
            };

            m_ReorderableList.onRemoveCallback = (list) =>
            {
                RemoveIconDataElement(list);
            };

            m_ReorderableList.onCanAddCallback = (list) =>
                                                 CanAddCallbackDelegate(list);

            m_ReorderableList.drawElementBackgroundCallback = (rect, index, active, focused) =>
            {
                if (!(Event.current.type == EventType.Repaint))
                {
                    return;
                }

                var evenRow = new GUIStyle("CN EntryBackEven");
                var oddRow  = new GUIStyle("CN EntryBackOdd");

                var bg = index % 2 == 0 ? evenRow : oddRow;
                bg.Draw(rect, false, false, false, false);
                ReorderableList.defaultBehaviours.DrawElementBackground(rect, index, active, focused, true);
            };


            m_ReorderableList.drawElementCallback = (rect, index, selected, focused) =>
                                                    DrawIconDataElement(rect, index, selected, focused);

            m_ReorderableList.elementHeightCallback = index =>
            {
                var data = GetElementData(index);
                if (data == null)
                {
                    return(kSlotSize);
                }
                return(m_ReorderableList.elementHeight +
                       (data.Asset != null && !data.IsValid ? kSlotSize : 0));
            };

            Undo.undoRedoPerformed += UpdateEditorStateOnUndo;
        }