Пример #1
0
        /// <summary>
        /// Create notifications for the host system in realtime game mode.
        /// </summary>
        private void CreateRealtimeModeNotifications()
        {
            List <HostNotification> notifications = MissionManager.Instance.GenerateHostNotifications();
            int remainingTicksPayday = GameTime.GameTime.Instance.RemainingTicksTillPayday();

            notifications.Append(new HostNotification("Payday arrives soon!", "",
                                                      (int)Math.Max(remainingTicksPayday * GameTime.GameTime.Instance.RealtimeMinutesPerTick, 60)));
            if (EmployeeManager.Instance.AllEmployeesIdle())
            {
                notifications.Append(new HostNotification("Your employees don't have anything to do.", "",
                                                          120));
            }

            foreach (var notification in notifications)
            {
                IGameNotification n = NotificationsManager.CreateNotification();
                n.Title     = notification.Title;
                n.Body      = notification.Body;
                n.SmallIcon = "small";
                n.LargeIcon = "large";
                DateTime date = DateTime.Now;
                n.DeliveryTime = date.Add(new TimeSpan(0, notification.Delay, 0));
                NotificationsManager.ScheduleNotification(n);
            }
        }
Пример #2
0
    public void SendNotification(string title, string body, DateTime deliveryTime, int?badgeNumber = null, bool reschedule = false, string channelId = null, string smallIcon = null, string largeIcon = null)
    {
        IGameNotification notification = manager.CreateNotification();

        if (notification == null)
        {
            return;
        }
        notification.Title = title;
        notification.Body  = body;
        notification.Group =
            !string.IsNullOrEmpty(channelId) ? channelId : NOTIFICATION_CHANNEL_ID;
        notification.DeliveryTime = deliveryTime;
        notification.SmallIcon    = smallIcon;
        notification.LargeIcon    = largeIcon;
        if (badgeNumber != null)
        {
            notification.BadgeNumber = badgeNumber;
        }
        PendingNotification notificationToDisplay = manager.ScheduleNotification(notification);

        notificationToDisplay.Reschedule = reschedule;
        //
        Debug.Log($"Queued notification for unactivity with ID \"{notification.Id}\" at time {deliveryTime:dd.MM.yyyy HH:mm:ss}");
    }
Пример #3
0
        /// <summary>
        /// Schedules a notification to be delivered.
        /// </summary>
        /// <param name="notification">The notification to deliver.</param>
        public PendingNotification ScheduleNotification(IGameNotification notification)
        {
            if (!Initialized)
            {
                throw new InvalidOperationException("Must call Initialize() first.");
            }

            if (notification == null || Platform == null)
            {
                return(null);
            }

            // If we queue, don't schedule immediately.
            // Also immediately schedule non-time based deliveries (for iOS)
            if ((mode & OperatingMode.Queue) != OperatingMode.Queue ||
                notification.DeliveryTime == null)
            {
                Platform.ScheduleNotification(notification);
            }
            else if (!notification.Id.HasValue)
            {
                // Generate an ID for items that don't have one (just so they can be identified later)
                int id = Math.Abs(DateTime.Now.ToString("yyMMddHHmmssffffff").GetHashCode());
                notification.Id = id;
            }

            // Register pending notification
            var result = new PendingNotification(notification);

            PendingNotifications.Add(result);

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Queue a notification with the given parameters.
        /// </summary>
        /// <param name="title">The title for the notification.</param>
        /// <param name="body">The body text for the notification.</param>
        /// <param name="deliveryTime">The time to deliver the notification.</param>
        /// <param name="badgeNumber">The optional badge number to display on the application icon.</param>
        /// <param name="reschedule">
        /// Whether to reschedule the notification if foregrounding and the notification hasn't yet been shown.
        /// </param>
        /// <param name="channelId">Channel ID to use. If this is null/empty then it will use the default ID. For Android
        /// the channel must be registered in <see cref="GameNotificationsManager.Initialize"/>.</param>
        /// <param name="smallIcon">Notification small icon.</param>
        /// <param name="largeIcon">Notification large icon.</param>
        public void SendNotification(string title, string body, DateTime deliveryTime, int?badgeNumber = null,
                                     bool reschedule  = false, string channelId = null,
                                     string smallIcon = null, string largeIcon  = null)
        {
            IGameNotification notification = manager.CreateNotification();

            if (notification == null)
            {
                return;
            }

            notification.Title        = title;
            notification.Body         = body;
            notification.Group        = !string.IsNullOrEmpty(channelId) ? channelId : ChannelId;
            notification.DeliveryTime = deliveryTime;
            notification.SmallIcon    = smallIcon;
            notification.LargeIcon    = largeIcon;
            if (badgeNumber != null)
            {
                notification.BadgeNumber = badgeNumber;
            }

            PendingNotification notificationToDisplay = manager.ScheduleNotification(notification);

            notificationToDisplay.Reschedule = reschedule;
            updatePendingNotifications       = true;

            QueueEvent($"Queued event with ID \"{notification.Id}\" at time {deliveryTime:HH:mm}");
        }
Пример #5
0
        /// <inheritdoc />
        public IList <IGameNotification> Deserialize(IGameNotificationsPlatform platform)
        {
            if (!File.Exists(filename))
            {
                return(null);
            }

            using (var file = new FileStream(filename, FileMode.Open))
            {
                using (var reader = new BinaryReader(file))
                {
                    // Version
                    reader.ReadByte();

                    // Length
                    int numElements = reader.ReadInt32();

                    var result = new List <IGameNotification>(numElements);
                    for (var i = 0; i < numElements; ++i)
                    {
                        IGameNotification notification = platform.CreateNotification();
                        bool hasValue;

                        // ID
                        hasValue = reader.ReadBoolean();
                        if (hasValue)
                        {
                            notification.Id = reader.ReadInt32();
                        }

                        // Title
                        notification.Title = reader.ReadString();

                        // Body
                        notification.Body = reader.ReadString();

                        // Body
                        notification.Subtitle = reader.ReadString();

                        // Group
                        notification.Group = reader.ReadString();

                        // Badge
                        hasValue = reader.ReadBoolean();
                        if (hasValue)
                        {
                            notification.BadgeNumber = reader.ReadInt32();
                        }

                        // Time
                        notification.DeliveryTime = new DateTime(reader.ReadInt64(), DateTimeKind.Local);

                        result.Add(notification);
                    }

                    return(result);
                }
            }
        }
Пример #6
0
        private IEnumerator ShowDeliveryNotificationCoroutine(IGameNotification deliveredNotification)
        {
            yield return(null);

            QueueEvent($"Notification with ID \"{deliveredNotification.Id}\" shown in foreground.");

            updatePendingNotifications = true;
        }
        /// <summary>
        /// Schedule notification with app icon.
        /// </summary>
        /// <param name="smallIcon">List of build-in small icons: notification_icon_bell (default), notification_icon_clock, notification_icon_heart, notification_icon_message, notification_icon_nut, notification_icon_star, notification_icon_warning.</param>
        public void ScheduleSimple(DateTime deliveryTime, string title, string message)
        {
            IGameNotification notification = GameNotificationsManager.I.CreateNotification();

            notification.Title        = title;
            notification.Body         = message;
            notification.DeliveryTime = deliveryTime;
            notification.LargeIcon    = "icon_antura";
            GameNotificationsManager.I.ScheduleNotification(notification);
        }
    private void StartDriveNotification()
    {
        IGameNotification startNotification = notificationManager.CreateNotification();

        startNotification.Title = "Rider Reminder";
        startNotification.Body  = "Click to launch app";

        startNotification.DeliveryTime = System.DateTime.Now.AddSeconds(3f);

        notificationManager.ScheduleNotification(startNotification);
    }
    private void EndTripNotification()
    {
        IGameNotification endNotification = notificationManager.CreateNotification();

        endNotification.Title = "Rider Reminder";
        endNotification.Body  = "Check the Rear Seat";

        endNotification.DeliveryTime = System.DateTime.Now.AddSeconds(3f);

        notificationManager.ScheduleNotification(endNotification);
    }
Пример #10
0
    public void CreateNotifocation(string title, string body, DateTime delay)      //метод создания оповещения(передаться заголовок, описание и время отправления(по желанию картинка, но я не писал)
    {
        IGameNotification notification = notificationManager.CreateNotification(); //обьясляем переменную оповещения в менеджере

        if (notification != null)                                                  //если создалось
        {
            notification.Title        = title;                                     //заголовок оповещения
            notification.Body         = body;                                      //тело оповещени
            notification.DeliveryTime = delay;                                     //DateTime.Now.AddSeconds(3); время отправления
            notificationManager.ScheduleNotification(notification);                //Отправка оповещения
        }
    }
        /// <inheritdoc />
        public void Serialize(IList <PendingNotification> notifications)
        {
            using (var file = new FileStream(filename, FileMode.Create))
            {
                using (var writer = new BinaryWriter(file))
                {
                    // Write version number
                    writer.Write(Version);

                    // Write list length
                    writer.Write(notifications.Count);

                    // Write each item
                    foreach (PendingNotification notificationToSave in notifications)
                    {
                        IGameNotification notification = notificationToSave.Notification;

                        // ID
                        writer.Write(notification.Id.HasValue);
                        if (notification.Id.HasValue)
                        {
                            writer.Write(notification.Id.Value);
                        }

                        // Title
                        writer.Write(notification.Title ?? "");

                        // Body
                        writer.Write(notification.Body ?? "");

                        // Subtitle
                        writer.Write(notification.Subtitle ?? "");

                        // Group
                        writer.Write(notification.Group ?? "");

                        // Data
                        writer.Write(notification.Data ?? "");

                        // Badge
                        writer.Write(notification.BadgeNumber.HasValue);
                        if (notification.BadgeNumber.HasValue)
                        {
                            writer.Write(notification.BadgeNumber.Value);
                        }

                        // Time (must have a value)
                        writer.Write(notification.DeliveryTime.Value.Ticks);
                    }
                }
            }
        }
Пример #12
0
    private void CreateNotification(string title, string body, System.DateTime time)
    {
        IGameNotification notification = notificationsManager.CreateNotification();

        if (notification != null)
        {
            notification.Title        = title;
            notification.Body         = body;
            notification.DeliveryTime = time;
            notification.SmallIcon    = "icon_0";
            notificationsManager.ScheduleNotification(notification);
        }
    }
        /// <inheritdoc />
        public PendingNotification ScheduleNotification(IGameNotification gameNotification)
        {
#if UNITY_EDITOR
            if (!gameNotification.Id.HasValue)
            {
                // Generate an ID for items that don't have one (just so they can be identified later)
                gameNotification.Id = Math.Abs(DateTime.Now.ToString("yyMMddHHmmssffffff").GetHashCode());
            }
            return(new PendingNotification(gameNotification));
#else
            return(_monoBehaviour.ScheduleNotification(gameNotification));
#endif
        }
Пример #14
0
    public void CreateAndSentNotificationSecondVer(string title, string textOfMessage, double time) /// Рабочая версия
    {
        loadPersonInfoFromFilesScript.personNotification.Add(new LoadPersonInfoFromFilesScript.notificationObject(textOfMessage, DateTime.Now.AddSeconds(time).ToShortDateString() + " " + DateTime.Now.AddSeconds(time).ToShortTimeString()));

        IGameNotification notification = gameNotificationManager.CreateNotification();

        if (notification != null)
        {
            notification.Title        = title;
            notification.Body         = textOfMessage;
            notification.DeliveryTime = DateTime.Now.AddSeconds(time);
            gameNotificationManager.ScheduleNotification(notification);
        }
    }
Пример #15
0
        /// <inheritdoc />
        public void ScheduleNotification(IGameNotification gameNotification)
        {
            if (gameNotification == null)
            {
                throw new ArgumentNullException(nameof(gameNotification));
            }

            if (!(gameNotification is IosGameNotification iosGameNotification))
            {
                throw new InvalidOperationException(
                          "Notification provided to ScheduleNotification isn't an IosGameNotification.");
            }

            ScheduleNotification(iosGameNotification);
        }
Пример #16
0
    public void ShowNotification(string title,
                                 string body,
                                 DateTime deliveryTime)
    {
        IGameNotification notification =
            notificationsManager.CreateNotification();

        if (notification != null)
        {
            notification.Title        = title;
            notification.Body         = body;
            notification.DeliveryTime = deliveryTime;

            notificationsManager.ScheduleNotification(notification);
        }
    }
Пример #17
0
        /// <summary>
        /// Event fired by <see cref="_platform"/> when a notification is received.
        /// </summary>
        private void OnNotificationReceived(IGameNotification deliveredNotification)
        {
            // Ignore for background messages (this happens on Android sometimes)
            if (!_inForeground)
            {
                return;
            }

            // Find in pending list
            int deliveredIndex = PendingNotifications.FindIndex(
                scheduledNotification => scheduledNotification.Notification.Id == deliveredNotification.Id);

            if (deliveredIndex >= 0)
            {
                OnLocalNotificationDelivered?.Invoke(PendingNotifications[deliveredIndex]);
                PendingNotifications.RemoveAt(deliveredIndex);
            }
        }
Пример #18
0
 public void ScheduleNotification(IGameNotification gameNotification)
 {
 }
 /// <summary>
 /// Instantiate a new instance of <see cref="PendingNotification"/> from a <see cref="IGameNotification"/>.
 /// </summary>
 /// <param name="notification">The notification to create from.</param>
 public PendingNotification(IGameNotification notification)
 {
     Notification = notification ?? throw new ArgumentNullException(nameof(notification));
 }