@@ -50,6 +50,7 @@ which is not diffiucilt, it's just time consuming given the number of files.
50
50
- Add the ` objc ` folder in this repo with the new custom unity init and obj-c bridging header
51
51
- Rename ` main ` in ` main.mm ` to anything else
52
52
- Alter the application delegate and cerate a main.swift file.
53
+ - Wrap the UnityAppController into your application delegate
53
54
- Adjust the ` GetAppController ` function in ` UnityAppController.h `
54
55
55
56
@@ -191,6 +192,63 @@ Note that if your `AppDelegate` is NOT called `AppDelegate` you will need to upd
191
192
the last argument above in `UIApplicationMain (< argc> , < argv> , < UIApplication> , < here> )`
192
193
to be whatever yours is called.
193
194
195
+ #### Wrap the UnityAppController into your application delegate
196
+
197
+ We are taking away control from the unity generated application delegate, we
198
+ need to act as a proxy for it in our `AppDelegate`.
199
+
200
+ First add the following variable to your `AppDelegate`
201
+
202
+ ```swift
203
+ var currentUnityController: UnityAppController!
204
+ ```
205
+ Now we need to initialize and proxy through the calls to the `UnityAppController`.
206
+ All said and done you will be left with the following:
207
+
208
+ ```swift
209
+ //
210
+ // AppDelegate.swift
211
+ //
212
+ // Created by Adam Venturella on 10/28/15
213
+ //
214
+
215
+ import UIKit
216
+
217
+ class AppDelegate: UIResponder, UIApplicationDelegate {
218
+
219
+ var window: UIWindow?
220
+ var currentUnityController: UnityAppController!
221
+
222
+
223
+ func application (application : UIApplication, didFinishLaunchingWithOptions launchOptions : [NSObject: AnyObject ]? ) -> Bool {
224
+ currentUnityController = UnityAppController ()
225
+ currentUnityController.application (application, didFinishLaunchingWithOptions : launchOptions)
226
+ return true
227
+ }
228
+
229
+ func applicationWillResignActive (application : UIApplication) {
230
+ currentUnityController.applicationWillResignActive (application)
231
+ }
232
+
233
+ func applicationDidEnterBackground (application : UIApplication) {
234
+ currentUnityController.applicationDidEnterBackground (application)
235
+ }
236
+
237
+ func applicationWillEnterForeground (application : UIApplication) {
238
+ currentUnityController.applicationWillEnterForeground (application)
239
+ }
240
+
241
+ func applicationDidBecomeActive (application : UIApplication) {
242
+ currentUnityController.applicationDidBecomeActive (application)
243
+ }
244
+
245
+ func applicationWillTerminate (application : UIApplication) {
246
+ currentUnityController.applicationWillTerminate (application)
247
+ }
248
+ }
249
+
250
+ ```
251
+
194
252
#### Adjust the `GetAppController` function in `UnityAppController.h `
195
253
196
254
Locate the file `UnityAppController.h ` in the xcode group `Unity/ Classes/ `
@@ -213,4 +271,16 @@ Comment that out. You will end up with this:
213
271
// }
214
272
```
215
273
274
+ Now we need to add a new version of this function:
275
+
276
+ ```objc
277
+ NS_INLINE UnityAppController* GetAppController ()
278
+ {
279
+
280
+ NSObject< UIApplicationDelegate>* delegate = [UIApplication sharedApplication].delegate ;
281
+ UnityAppController* currentUnityController = (UnityAppController * )[delegate valueForKey: @" currentUnityController" ];
282
+ return currentUnityController;
283
+ }
284
+ ```
285
+
216
286
[www.the - nerd.be ]: http: // www.the-nerd.be/2015/08/20/a-better-way-to-integrate-unity3d-within-a-native-ios-application/ "The Nerd"
0 commit comments