Skip to content

Commit 66cb83f

Browse files
committed
- add package
1 parent d90f90c commit 66cb83f

23 files changed

+613
-7
lines changed

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/NotificationChanelEditor.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using VirtueSky.Notifications;
4+
5+
6+
namespace VirtueSky.NotificationsEditor
7+
{
8+
[CustomEditor(typeof(NotificationChanel), true)]
9+
public class NotificationChanelEditor : Editor
10+
{
11+
private SerializedProperty identifier;
12+
private SerializedProperty minute;
13+
private SerializedProperty repeat;
14+
private SerializedProperty datas;
15+
private SerializedProperty bigPicture;
16+
private SerializedProperty namePicture;
17+
private SerializedProperty overrideIcon;
18+
private SerializedProperty smallIcon;
19+
private SerializedProperty largeIcon;
20+
21+
private void Init()
22+
{
23+
identifier = serializedObject.FindProperty("identifier");
24+
minute = serializedObject.FindProperty("minute");
25+
repeat = serializedObject.FindProperty("repeat");
26+
datas = serializedObject.FindProperty("datas");
27+
bigPicture = serializedObject.FindProperty("bigPicture");
28+
namePicture = serializedObject.FindProperty("namePicture");
29+
overrideIcon = serializedObject.FindProperty("overrideIcon");
30+
smallIcon = serializedObject.FindProperty("smallIcon");
31+
largeIcon = serializedObject.FindProperty("largeIcon");
32+
}
33+
34+
public override void OnInspectorGUI()
35+
{
36+
serializedObject.Update();
37+
Init();
38+
GUILayout.Label("Notification Chanel Data", new GUIStyle(EditorStyles.boldLabel)
39+
{
40+
fontSize = 15
41+
});
42+
GUILayout.Space(5);
43+
EditorGUILayout.PropertyField(identifier);
44+
EditorGUILayout.PropertyField(minute);
45+
EditorGUILayout.PropertyField(repeat);
46+
EditorGUILayout.PropertyField(datas);
47+
EditorGUILayout.PropertyField(bigPicture);
48+
if (bigPicture.boolValue)
49+
{
50+
EditorGUILayout.HelpBox("File big picture must be place in folder StreamingAsset, Name Picture must contains file extension ex .jpg", MessageType.Info);
51+
EditorGUILayout.PropertyField(namePicture);
52+
}
53+
54+
EditorGUILayout.PropertyField(overrideIcon);
55+
if (overrideIcon.boolValue)
56+
{
57+
EditorGUILayout.PropertyField(smallIcon);
58+
EditorGUILayout.PropertyField(largeIcon);
59+
}
60+
61+
EditorUtility.SetDirty(target);
62+
serializedObject.ApplyModifiedProperties();
63+
}
64+
}
65+
}

Editor/NotificationChanelEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "UnityCommon.Notification.Editor",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:dbb824b00e9e88c4aac8daf3dd48da54"
6+
],
7+
"includePlatforms": [
8+
"Editor"
9+
],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": false,
13+
"precompiledReferences": [],
14+
"autoReferenced": true,
15+
"defineConstraints": [],
16+
"versionDefines": [],
17+
"noEngineReferences": false
18+
}

Editor/UnityCommon.Notification.Editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1+
<p align="left">
2+
<a>
3+
<img alt="Made With Unity" src="https://img.shields.io/badge/made%20with-Unity-57b9d3.svg?logo=Unity">
4+
</a>
5+
<a>
6+
<img alt="License" src="https://img.shields.io/github/license/wolf-org/notification-unity?logo=github">
7+
</a>
8+
<a>
9+
<img alt="Last Commit" src="https://img.shields.io/github/last-commit/wolf-org/notification-unity?logo=Mapbox&color=orange">
10+
</a>
11+
<a>
12+
<img alt="Repo Size" src="https://img.shields.io/github/repo-size/wolf-org/notification-unity?logo=VirtualBox">
13+
</a>
14+
<a>
15+
<img alt="Last Release" src="https://img.shields.io/github/v/release/wolf-org/notification-unity?include_prereleases&logo=Dropbox&color=yellow">
16+
</a>
17+
</p>
18+
19+
## What
20+
21+
Support scheduling local one-time or repeatable notifications for Unity games (Android and iOS)
22+
123
## How To Install
224

325
### Add the line below to `Packages/manifest.json`
426

5-
for version `x.x.x`
27+
for version `1.0.0`
628
```csharp
7-
"com.virtuesky._package_name_":"https://github.com/VirtueSky/_package_name_.git#x.x.x",
29+
"com.wolf-org.notifications":"https://github.com/wolf-org/notification-unity.git#1.0.0",
830
```
31+
dependency `com.unity.mobile.notifications-2.3.2` and `com.cysharp.unitask-2.5.5`
32+
```csharp
33+
"com.unity.mobile.notifications": "2.3.2",
34+
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.5.5",
35+
```
36+
37+
## Use
38+
39+
- Add define symbol `VIRTUESKY_NOTIFICATION`
40+
-

README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/NotificationAndroid.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#if UNITY_ANDROID && VIRTUESKY_NOTIFICATION
2+
using System;
3+
using System.Collections.Generic;
4+
using Unity.Notifications.Android;
5+
6+
namespace VirtueSky.Notifications
7+
{
8+
internal static class NotificationAndroid
9+
{
10+
private static readonly Dictionary<string, bool> ChannelRegistered = new Dictionary<string, bool>();
11+
12+
private static void RegisterNotificationChannel(string identifier, string name, string description)
13+
{
14+
ChannelRegistered.TryGetValue(identifier, out bool registered);
15+
if (registered) return;
16+
17+
AndroidNotificationCenter.RegisterNotificationChannel(new AndroidNotificationChannel
18+
{
19+
Id = identifier, Name = name, Importance = Importance.High, Description = description
20+
});
21+
ChannelRegistered.Add(identifier, true);
22+
}
23+
24+
internal static void Schedule(
25+
string identifier,
26+
string title,
27+
string text,
28+
TimeSpan timeOffset,
29+
string largeIcon = null,
30+
string channelName = "Nova",
31+
string channelDescription = "Newsletter Announcement",
32+
string smallIcon = "icon_0",
33+
BigPictureStyle? bigPictureStyle = null,
34+
bool repeat = false)
35+
{
36+
RegisterNotificationChannel(identifier, channelName, channelDescription);
37+
38+
var notification = new AndroidNotification()
39+
{
40+
Title = title,
41+
Text = text,
42+
FireTime = DateTime.Now + timeOffset,
43+
Group = identifier,
44+
GroupSummary = true,
45+
ShouldAutoCancel = true,
46+
BigPicture = bigPictureStyle,
47+
};
48+
49+
if (repeat) notification.RepeatInterval = timeOffset;
50+
51+
if (largeIcon != null) notification.LargeIcon = largeIcon;
52+
if (smallIcon != null) notification.SmallIcon = smallIcon;
53+
54+
AndroidNotificationCenter.SendNotification(notification, identifier);
55+
}
56+
57+
internal static void CancelAllScheduled()
58+
{
59+
AndroidNotificationCenter.CancelAllScheduledNotifications();
60+
}
61+
}
62+
}
63+
#endif

Runtime/NotificationAndroid.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/NotificationChanel.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.IO;
3+
using UnityEngine;
4+
5+
namespace VirtueSky.Notifications
6+
{
7+
[CreateAssetMenu(fileName = "notification_channel_data.asset",
8+
menuName = "Unity-Common/Notification Channel")]
9+
public class NotificationChanel : ScriptableObject
10+
{
11+
[Serializable]
12+
public class NotificationData
13+
{
14+
public string title;
15+
public string message;
16+
17+
public NotificationData(string title, string message)
18+
{
19+
this.title = title;
20+
this.message = message;
21+
}
22+
}
23+
24+
[SerializeField] private string identifier;
25+
26+
[SerializeField] private int minute;
27+
28+
[SerializeField] private bool repeat;
29+
[SerializeField] private NotificationData[] datas;
30+
31+
[Tooltip("File big picture must be place in folder StreamingAsset, Name Picture must contains file extension ex .jpg"), SerializeField]
32+
internal bool bigPicture;
33+
34+
[SerializeField] internal string namePicture;
35+
36+
[SerializeField] internal bool overrideIcon;
37+
[SerializeField] internal string smallIcon = "icon_0";
38+
[SerializeField] internal string largeIcon = "icon_1";
39+
40+
41+
public void Send()
42+
{
43+
if (!Application.isMobilePlatform) return;
44+
if (datas.Length == 0) return;
45+
var data = datas[UnityEngine.Random.Range(0, datas.Length)];
46+
47+
string pathPicture = Path.Combine(Application.persistentDataPath, namePicture);
48+
NotificationConsole.Send(identifier,
49+
data.title,
50+
data.message,
51+
smallIcon: smallIcon,
52+
largeIcon: largeIcon,
53+
bigPicture: bigPicture,
54+
namePicture: pathPicture);
55+
}
56+
57+
public void Schedule()
58+
{
59+
if (!Application.isMobilePlatform) return;
60+
if (datas.Length == 0) return;
61+
var data = datas[UnityEngine.Random.Range(0, datas.Length)];
62+
63+
string pathPicture = Path.Combine(Application.persistentDataPath, namePicture);
64+
65+
NotificationConsole.Schedule(identifier,
66+
data.title,
67+
data.message,
68+
TimeSpan.FromMinutes(minute),
69+
smallIcon: smallIcon,
70+
largeIcon: largeIcon,
71+
bigPicture: bigPicture,
72+
namePicture: pathPicture,
73+
repeat: repeat);
74+
}
75+
76+
public void CancelAllScheduled()
77+
{
78+
if (!Application.isMobilePlatform) return;
79+
NotificationConsole.CancelAllScheduled();
80+
}
81+
82+
public void ClearBadgeCounterIOS()
83+
{
84+
if (!Application.isMobilePlatform) return;
85+
NotificationConsole.ClearBadgeCounterIOS();
86+
}
87+
}
88+
}

Runtime/NotificationChanel.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)