Forest_Client/Forest/Assets/Scripts/Gameplay/Debug/SROptions.Notification.cs

55 lines
2.1 KiB
C#
Raw Normal View History

2024-07-16 15:19:52 +08:00
using System.ComponentModel;
using System;
#if UNITY_ANDROID
2024-07-16 15:48:42 +08:00
using Unity.Notifications.Android;
#endif
2024-07-16 15:19:52 +08:00
public partial class SROptions
{
[Category("通知相关"), DisplayName("通知id")]
public int NotificationID { get; set; }
2024-07-19 14:39:40 +08:00
[Category("通知相关"), DisplayName("初始化通知")]
2024-07-19 14:23:24 +08:00
public void InitNotification()
{
Notification.Init();
}
2024-07-16 15:19:52 +08:00
[Category("通知相关"), DisplayName("发送通知")]
public void SendNotification()
{
#if UNITY_ANDROID
2024-07-19 14:39:40 +08:00
DateTime dateTime = DateTime.Now.AddSeconds(10f);
2024-07-19 15:41:34 +08:00
NotificationID = Notification.Android.SetNotification("通知", "测试通知", dateTime, "small", "large", "测试", true);
2024-07-19 14:50:32 +08:00
DebugUtil.Log($"发送安卓测试通知,通知id:{NotificationID},时间:{dateTime},测试版本1");
2024-07-19 15:41:34 +08:00
#elif UNITY_IOS
Notification.IOS.SetNotification("1", "通知","测试通知");
DebugUtil.Log($"发送IOS测试通知,通知id:{NotificationID},时间:{DateTime.Now.AddSeconds(10f)},测试版本1");
2024-07-16 15:19:52 +08:00
#endif
}
[Category("通知相关"), DisplayName("取消指定id通知")]
public void CancelNotification()
{
#if UNITY_ANDROID
2024-07-16 15:48:42 +08:00
Notification.Android.CancelNotification(NotificationID);
2024-07-16 15:19:52 +08:00
DebugUtil.Log($"取消安卓测试通知,通知id{NotificationID}");
2024-07-16 15:48:42 +08:00
#endif
}
[Category("通知相关"), DisplayName("获取指定id通知状态")]
public void GetNotificationStatus()
{
#if UNITY_ANDROID
NotificationStatus notificationStatus = Notification.Android.GetNotificationStatus(NotificationID);
string content = notificationStatus switch
{
NotificationStatus.Unavailable => "无法确定指定通知的状态。仅支持 Android Marshmallow (6.0) 及以上版本。",
NotificationStatus.Scheduled => $"id为{NotificationID}的通知已排定但尚未送达。",
NotificationStatus.Delivered => $"id为{NotificationID}的通知已发送(显示在状态栏中)。",
_ => $"找不到指定id为{NotificationID}的通知。",
};
DebugUtil.Log(content);
2024-07-16 15:19:52 +08:00
#endif
}
}