1
- # PubNub Unity SDK (V4 )
1
+ # PubNub Unity SDK (V6 )
2
2
3
3
[ ![ Build Status] ( https://travis-ci.com/pubnub/unity.svg?branch=master )] ( https://travis-ci.com/pubnub/unity ) [ ![ Build status] ( https://ci.appveyor.com/api/projects/status/1p3494pnt6rgqdsm/branch/master?svg=true )] ( https://ci.appveyor.com/project/PubNub/unity )
4
4
@@ -12,83 +12,92 @@ You will need the publish and subscribe keys to authenticate your app. Get your
12
12
13
13
## Configure PubNub
14
14
15
- 1 . Download the PubNub Unity package from [ this repository] ( https://github.com/pubnub/unity/releases/download/v6.0.6 /PubNub.unitypackage ) .
15
+ 1 . Download the PubNub Unity package from [ this repository] ( https://github.com/pubnub/unity/releases/download/v6.0.5 /PubNub.unitypackage ) .
16
16
17
- 2 . Import it to your Unity project by going to Assets - > Import Package - > Custom Package.
17
+ 2 . Import the package to your Unity project by going to Assets > Import Package > Custom Package.
18
18
19
19
3 . Configure your keys:
20
20
21
21
``` csharp
22
+ using PubNubAPI ;
22
23
PNConfiguration pnConfiguration = new PNConfiguration ();
23
24
pnConfiguration .SubscribeKey = " my_subkey" ;
24
25
pnConfiguration .PublishKey = " my_pubkey" ;
25
26
pnConfiguration .SecretKey = " my_secretkey" ;
26
27
pnConfiguration .LogVerbosity = PNLogVerbosity .BODY ;
27
- pnConfiguration .UUID = " myUniqueUUID " ;
28
+ pnConfiguration .UserId = " myUniqueUserId " ;
28
29
```
29
30
31
+ 4 . If your Unity application contains existing [Assembly Definitions ](https :// docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html), you might receive [CS0246 compiler errors](https://support.unity.com/hc/en-us/articles/206116726-What-is-CS0246-), as the `PubNubAPI` namespace may not be recognized. You will need to create an assembly definition to use the `PubNubAPI` in your application.
32
+ 1 . Navigate to the Assets > PubNub folder in the Project window .
33
+ 2 . Right - click the PubNub folder and create an [Assembly Definition ](https :// docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html) by selecting Create > Assembly Definition. Assign a name to the asset (such as PubNub) and leave the default settings.
34
+ 3 . Navigate to the folder that you wish to use the `PubNubAPI ` namespace . Click on the Assembly Definition file .
35
+ 4 . In the Inspector window , add the ** PubNub ** Assembly Definition you created earlier to the list of Assembly Definition References section by clicking on the **+** icon .
36
+ 5 . Scroll down in the Inspector window , and click Apply . The `PubNubAPI ` namespace should now be visible in your application .
37
+ 6 . You may receive more compiler errors when trying to use the `PubNubAPI ` namespace . These come from the PubNub > Editor folder , and contain test files . Delete the entire PubNub > Editor folder and allow the Unity editor to recompile changes .
38
+
30
39
## Add event listeners
31
40
32
41
```csharp
33
42
pubnub .SubscribeCallback += SubscribeCallbackHandler ;
34
43
35
44
// Handler
36
45
void SubscribeCallbackHandler (object sender , EventArgs e ) {
37
- SubscribeEventEventArgs mea = e as SubscribeEventEventArgs ;
38
-
39
- if (mea .Status != null ) {
40
- switch (mea .Status .Category ) {
41
- case PNStatusCategory .PNUnexpectedDisconnectCategory :
42
- case PNStatusCategory .PNTimeoutCategory :
43
- // handle publish
44
- break ;
45
- }
46
- }
47
- if (mea .MessageResult != null ) {
48
- Debug .Log (" Channel" + mea .MessageResult .Channel );
49
- Debug .Log (" Payload" + mea .MessageResult .Payload );
50
- Debug .Log (" Publisher Id: " + mea .MessageResult .IssuingClientId );
51
- }
52
- if (mea .PresenceEventResult != null ) {
53
- Debug .Log (" SubscribeCallback in presence" + mea .PresenceEventResult .Channel + mea .PresenceEventResult .Occupancy + mea .PresenceEventResult .Event );
54
- }
55
- if (mea .SignalEventResult != null ) {
56
- Debug .Log (" SubscribeCallback in SignalEventResult" + mea .SignalEventResult .Channel + mea .SignalEventResult .Payload );
57
- }
58
- if (mea .UserEventResult != null ) {
59
- Debug .Log (mea .UserEventResult .Name );
60
- Debug .Log (mea .UserEventResult .Email );
61
- Debug .Log (mea .UserEventResult .ExternalID );
62
- Debug .Log (mea .UserEventResult .ProfileURL );
63
- Debug .Log (mea .UserEventResult . UserID );
64
- Debug .Log (mea .UserEventResult .ETag );
65
- Debug .Log (mea .UserEventResult .ObjectsEvent );
66
- }
67
- if (mea .SpaceEventResult != null ) {
68
- Debug .Log (mea .SpaceEventResult .Name );
69
- Debug .Log (mea .SpaceEventResult .Description );
70
- Debug .Log (mea .SpaceEventResult . SpaceID );
71
- Debug .Log (mea .SpaceEventResult .ETag );
72
- Debug .Log (mea .SpaceEventResult .ObjectsEvent );
73
- }
74
- if (mea .MembershipEventResult != null ) {
75
- Debug .Log (mea .MembershipEventResult .UserID );
76
- Debug .Log (mea .MembershipEventResult .Description );
77
- Debug .Log (mea .MembershipEventResult .SpaceID );
78
- Debug .Log (mea .MembershipEventResult .ObjectsEvent );
79
- }
80
- if (mea .MessageActionsEventResult != null ) {
81
- Debug .Log (mea .MessageActionsEventResult .Channel );
82
- if (mea .MessageActionsEventResult .Data != null ){
83
- Debug .Log (mea .MessageActionsEventResult .Data .ActionTimetoken );
84
- Debug .Log (mea .MessageActionsEventResult .Data .ActionType );
85
- Debug .Log (mea .MessageActionsEventResult .Data .ActionValue );
86
- Debug .Log (mea .MessageActionsEventResult .Data .MessageTimetoken );
87
- Debug .Log (mea .MessageActionsEventResult .Data .UUID );
88
- }
89
- Debug .Log (mea .MessageActionsEventResult .MessageActionsEvent );
90
- Debug .Log (mea .MessageActionsEventResult .Subscription );
91
- }
46
+ SubscribeEventEventArgs mea = e as SubscribeEventEventArgs ;
47
+
48
+ if (mea .Status != null ) {
49
+ switch (mea .Status .Category ) {
50
+ case PNStatusCategory .PNUnexpectedDisconnectCategory :
51
+ case PNStatusCategory .PNTimeoutCategory :
52
+ // handle publish
53
+ break ;
54
+ }
55
+ }
56
+ if (mea .MessageResult != null ) {
57
+ Debug .Log (" Channel" + mea .MessageResult .Channel );
58
+ Debug .Log (" Payload" + mea .MessageResult .Payload );
59
+ Debug .Log (" Publisher Id: " + mea .MessageResult .IssuingClientId );
60
+ }
61
+ if (mea .PresenceEventResult != null ) {
62
+ Debug .Log (" SubscribeCallback in presence" + mea .PresenceEventResult .Channel + mea .PresenceEventResult .Occupancy + mea .PresenceEventResult .Event );
63
+ }
64
+ if (mea .SignalEventResult != null ) {
65
+ Debug .Log (" SubscribeCallback in SignalEventResult" + mea .SignalEventResult .Channel + mea .SignalEventResult .Payload );
66
+ }
67
+ if (mea .UUIDEventResult != null ) {
68
+ Debug .Log (mea .UUIDEventResult .Name );
69
+ Debug .Log (mea .UUIDEventResult .Email );
70
+ Debug .Log (mea .UUIDEventResult .ExternalID );
71
+ Debug .Log (mea .UUIDEventResult .ProfileURL );
72
+ Debug .Log (mea .UUIDEventResult . UUID );
73
+ Debug .Log (mea .UUIDEventResult .ETag );
74
+ Debug .Log (mea .UUIDEventResult .ObjectsEvent );
75
+ }
76
+ if (mea .ChannelEventResult != null ) {
77
+ Debug .Log (mea .ChannelEventResult .Name );
78
+ Debug .Log (mea .ChannelEventResult .Description );
79
+ Debug .Log (mea .ChannelEventResult . ChannelID );
80
+ Debug .Log (mea .ChannelEventResult .ETag );
81
+ Debug .Log (mea .ChannelEventResult .ObjectsEvent );
82
+ }
83
+ if (mea .MembershipEventResult != null ) {
84
+ Debug .Log (mea .MembershipEventResult .UUID );
85
+ Debug .Log (mea .MembershipEventResult .Description );
86
+ Debug .Log (mea .MembershipEventResult .ChannelID );
87
+ Debug .Log (mea .MembershipEventResult .ObjectsEvent );
88
+ }
89
+ if (mea .MessageActionsEventResult != null ) {
90
+ Debug .Log (mea .MessageActionsEventResult .Channel );
91
+ if (mea .MessageActionsEventResult .Data != null ){
92
+ Debug .Log (mea .MessageActionsEventResult .Data .ActionTimetoken );
93
+ Debug .Log (mea .MessageActionsEventResult .Data .ActionType );
94
+ Debug .Log (mea .MessageActionsEventResult .Data .ActionValue );
95
+ Debug .Log (mea .MessageActionsEventResult .Data .MessageTimetoken );
96
+ Debug .Log (mea .MessageActionsEventResult .Data .UUID );
97
+ }
98
+ Debug .Log (mea .MessageActionsEventResult .MessageActionsEvent );
99
+ Debug .Log (mea .MessageActionsEventResult .Subscription );
100
+ }
92
101
}
93
102
```
94
103
@@ -98,7 +107,7 @@ void SubscribeCallbackHandler(object sender, EventArgs e) {
98
107
pubnub .Publish ()
99
108
.Channel (" channel1" )
100
109
.Message (" test message" )
101
- .Async ((result , status ) => {
110
+ .Async ((result , status ) => {
102
111
if (! status .Error ) {
103
112
Debug .Log (string .Format (" Publish Timetoken: {0}" , result .Timetoken ));
104
113
} else {
@@ -116,9 +125,8 @@ pubnub.Subscribe()
116
125
117
126
## Documentation
118
127
119
- * [ Build your first realtime Unity app with PubNub] ( https://www.pubnub.com/docs/platform/quickstarts/unity )
120
- * [ API reference for Unity] ( https://www.pubnub.com/docs/unity3d-c-sharp/pubnub-c-sharp-sdk )
128
+ * [API reference for Unity ](https :// www.pubnub.com/docs/sdks/unity)
121
129
122
130
## Support
123
131
124
- If you
** need help
** or have a
** general question
** , contact
[email protected] .
132
+ If you ** need help ** or have a ** general question ** , contact support @pubnub .com .
0 commit comments