34
34
public class GameControllerExample : MonoBehaviour {
35
35
36
36
private static string extraMessage ;
37
- public string email = "Email Address" ;
37
+ public string email = "Email Address" ;
38
38
39
39
void Start ( ) {
40
40
extraMessage = null ;
@@ -55,7 +55,7 @@ void Start () {
55
55
OneSignal . inFocusDisplayType = OneSignal . OSInFocusDisplayOption . Notification ;
56
56
OneSignal . permissionObserver += OneSignal_permissionObserver ;
57
57
OneSignal . subscriptionObserver += OneSignal_subscriptionObserver ;
58
- OneSignal . emailSubscriptionObserver += OneSignal_emailSubscriptionObserver ;
58
+ OneSignal . emailSubscriptionObserver += OneSignal_emailSubscriptionObserver ;
59
59
60
60
var pushState = OneSignal . GetPermissionSubscriptionState ( ) ;
61
61
Debug . Log ( "pushState.subscriptionStatus.subscribed : " + pushState . subscriptionStatus . subscribed ) ;
@@ -114,10 +114,10 @@ public static void HandleNotificationOpened(OSNotificationOpenedResult result) {
114
114
Debug . Log ( "[HandleNotificationOpened] message " + message + ", additionalData: " + Json . Serialize ( additionalData ) as string ) ;
115
115
116
116
if ( actionID != null ) {
117
- // actionSelected equals the id on the button the user pressed.
118
- // actionSelected will equal "__DEFAULT__" when the notification itself was tapped when buttons were present.
119
- extraMessage = "Pressed ButtonId: " + actionID ;
120
- }
117
+ // actionSelected equals the id on the button the user pressed.
118
+ // actionSelected will equal "__DEFAULT__" when the notification itself was tapped when buttons were present.
119
+ extraMessage = "Pressed ButtonId: " + actionID ;
120
+ }
121
121
}
122
122
123
123
// Test Menu
@@ -129,20 +129,24 @@ void OnGUI () {
129
129
GUIStyle guiBoxStyle = new GUIStyle ( "box" ) ;
130
130
guiBoxStyle . fontSize = 30 ;
131
131
132
- float itemOriginX = 50.0f ;
133
- float itemWidth = Screen . width - 120.0f ;
134
- float boxWidth = Screen . width - 20.0f ;
135
- float boxOriginY = 120.0f ;
136
- float boxHeight = 630.0f ;
137
- float itemStartY = 200.0f ;
138
- float itemHeightOffset = 90.0f ;
139
- float itemHeight = 60.0f ;
132
+ GUIStyle textFieldStyle = new GUIStyle ( "textField" ) ;
133
+ textFieldStyle . fontSize = 30 ;
134
+
140
135
141
- GUI . Box ( new Rect ( 10 , boxOriginY , boxWidth , boxHeight ) , "Test Menu" , guiBoxStyle ) ;
136
+ float itemOriginX = 50.0f ;
137
+ float itemWidth = Screen . width - 120.0f ;
138
+ float boxWidth = Screen . width - 20.0f ;
139
+ float boxOriginY = 120.0f ;
140
+ float boxHeight = 630.0f ;
141
+ float itemStartY = 200.0f ;
142
+ float itemHeightOffset = 90.0f ;
143
+ float itemHeight = 60.0f ;
142
144
143
- float count = 0.0f ;
145
+ GUI . Box ( new Rect ( 10 , boxOriginY , boxWidth , boxHeight ) , "Test Menu" , guiBoxStyle ) ;
144
146
145
- if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "SendTags" , customTextSize ) ) {
147
+ float count = 0.0f ;
148
+
149
+ if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "SendTags" , customTextSize ) ) {
146
150
// You can tags users with key value pairs like this:
147
151
OneSignal . SendTag ( "UnityTestKey" , "TestValue" ) ;
148
152
// Or use an IDictionary if you need to set more than one tag.
@@ -154,18 +158,18 @@ void OnGUI () {
154
158
// OneSignal.DeleteTags(new List<string>() {"UnityTestKey2", "UnityTestKey3" });
155
159
}
156
160
157
- count ++ ;
161
+ count ++ ;
158
162
159
- if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "GetIds" , customTextSize ) ) {
160
- OneSignal . IdsAvailable ( ( userId , pushToken ) => {
163
+ if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "GetIds" , customTextSize ) ) {
164
+ OneSignal . IdsAvailable ( ( userId , pushToken ) => {
161
165
extraMessage = "UserID:\n " + userId + "\n \n PushToken:\n " + pushToken ;
162
166
} ) ;
163
167
}
164
168
165
169
166
- count ++ ;
170
+ count ++ ;
167
171
168
- if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "TestNotification" , customTextSize ) ) {
172
+ if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "TestNotification" , customTextSize ) ) {
169
173
extraMessage = "Waiting to get a OneSignal userId. Uncomment OneSignal.SetLogLevel in the Start method if it hangs here to debug the issue." ;
170
174
OneSignal . IdsAvailable ( ( userId , pushToken ) => {
171
175
if ( pushToken != null ) {
@@ -181,52 +185,50 @@ void OnGUI () {
181
185
notification [ "send_after" ] = System . DateTime . Now . ToUniversalTime ( ) . AddSeconds ( 30 ) . ToString ( "U" ) ;
182
186
183
187
extraMessage = "Posting test notification now." ;
188
+
184
189
OneSignal . PostNotification ( notification , ( responseSuccess ) => {
185
190
extraMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n " + Json . Serialize ( responseSuccess ) ;
186
191
} , ( responseFailure ) => {
187
192
extraMessage = "Notification failed to post:\n " + Json . Serialize ( responseFailure ) ;
188
193
} ) ;
189
- }
190
- else
194
+ } else {
191
195
extraMessage = "ERROR: Device is not registered." ;
196
+ }
192
197
} ) ;
193
198
}
194
199
200
+ count ++ ;
195
201
196
- count ++ ;
197
-
198
- email = GUI . TextField ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , email , customTextSize ) ;
202
+ email = GUI . TextField ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , email , customTextSize ) ;
199
203
204
+ count ++ ;
200
205
201
- count ++ ;
206
+ if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "SetEmail" , customTextSize ) ) {
207
+ extraMessage = "Setting email to " + email ;
202
208
203
- if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "SetEmail" , customTextSize ) ) {
204
- extraMessage = "Setting email to " + email ;
205
-
206
- OneSignal . SetEmail ( email , ( ) => {
207
- Debug . Log ( "Successfully set email" ) ;
208
- } , ( error ) => {
209
- Debug . Log ( "Encountered error setting email: " + Json . Serialize ( error ) ) ;
210
- } ) ;
211
- }
212
-
213
-
214
- count ++ ;
209
+ OneSignal . SetEmail ( email , ( ) => {
210
+ Debug . Log ( "Successfully set email" ) ;
211
+ } , ( error ) => {
212
+ Debug . Log ( "Encountered error setting email: " + Json . Serialize ( error ) ) ;
213
+ } ) ;
214
+ }
215
215
216
- if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "LogoutEmail" , customTextSize ) ) {
217
- extraMessage = "Logging Out of [email protected] " ;
216
+ count ++ ;
218
217
219
- OneSignal . LogoutEmail ( ( ) => {
220
- Debug . Log ( "Successfully logged out of email" ) ;
221
- } , ( error ) => {
222
- Debug . Log ( "Encountered error logging out of email: " + Json . Serialize ( error ) ) ;
223
- } ) ;
224
- }
218
+ if ( GUI . Button ( new Rect ( itemOriginX , itemStartY + ( count * itemHeightOffset ) , itemWidth , itemHeight ) , "LogoutEmail" , customTextSize ) ) {
219
+ extraMessage = "Logging Out of [email protected] " ;
220
+
221
+ OneSignal . LogoutEmail ( ( ) => {
222
+ Debug . Log ( "Successfully logged out of email" ) ;
223
+ } , ( error ) => {
224
+ Debug . Log ( "Encountered error logging out of email: " + Json . Serialize ( error ) ) ;
225
+ } ) ;
226
+ }
225
227
226
228
if ( extraMessage != null ) {
227
229
guiBoxStyle . alignment = TextAnchor . UpperLeft ;
228
230
guiBoxStyle . wordWrap = true ;
229
- GUI . Box ( new Rect ( 10 , boxOriginY + boxHeight + 20 , Screen . width - 20 , Screen . height - ( boxOriginY + boxHeight + 40 ) ) , extraMessage , guiBoxStyle ) ;
231
+ GUI . Box ( new Rect ( 10 , boxOriginY + boxHeight + 20 , Screen . width - 20 , Screen . height - ( boxOriginY + boxHeight + 40 ) ) , extraMessage , guiBoxStyle ) ;
230
232
}
231
233
}
232
234
}
0 commit comments