-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDelegate.mm
167 lines (132 loc) · 5.21 KB
/
AppDelegate.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Template
#import "AppDelegate.h"
#import "MainViewController.h"
//for vuforia:
#import "VuforiaRenderDelegate.h"
extern "C" void VuforiaRenderEvent(int marker);
@implementation AppDelegate
- (void)shouldAttachRenderDelegate
{
NSLog(@"should attach render delgate");
if( self.initialized )
{
//for vuforia:
self.unityController.renderDelegate = [[VuforiaRenderDelegate alloc] init];
UnityRegisterRenderingPlugin(NULL, &VuforiaRenderEvent);
}
}
- (UIWindow *)unityWindow {
return UnityGetMainWindow();
}
- (void) showUnityWindow {
NSLog(@"showUnityWindow");
if (!self.initialized)
{
self.unityController = [[UnityAppController alloc] init];
[self.unityController application:self.m_application didFinishLaunchingWithOptions:self.m_options];
self.m_waitingMessage = nil;
self.m_application = nil;
self.m_options = nil;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillTerminateCallback:)
name:UIApplicationWillTerminateNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActiveCallback:)
name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActiveCallback:)
name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillEnterForegroundCallback:)
name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidEnterBackgroundCallback:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
self.initialized = YES;
}
[self onAppDidBecomeActiveCallback:nil];
[self.unityWindow makeKeyAndVisible];
}
-(void) hideUnityWindow {
NSLog(@"hideUnityWindow");
//[self onAppWillResignActiveCallback:nil];
[self.window makeKeyAndVisible];
}
-(void)notifyUnityReady {
NSLog(@"unityReady notified");
self.unityInitialized = YES;
if( self.m_waitingMessage != nil )
{
[self sendMessageToUnity:self.m_waitingMessage];
self.m_waitingMessage = nil;
}
}
// Source: https://the-nerd.be/2014/08/07/call-methods-on-unity3d-straight-from-your-objective-c-code/
- (void)sendMessageToUnity:(NSString*)parameter
{
if( self.unityInitialized )
{
UnitySendMessage("IonicComms", "OnMessageReceivedFromIonic", [parameter UTF8String]);
}
else
{
self.m_waitingMessage = parameter;
}
}
- (void)sendMessageToUnity:(NSString*)func parameter:(NSString*)parameter
{
if( self.unityInitialized )
{
UnitySendMessage("IonicComms", [func UTF8String], [parameter UTF8String]);
}
}
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.viewController = [[MainViewController alloc] init];
self.m_application = application;
self.m_options = launchOptions;
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (void)assignIonicComms:(unityARCaller*)comms
{
self.ionicComms = comms;
}
- (void)sendMessageToIonic:(NSString*)message
{
[self.ionicComms receivedMessageFromUnity:message];
}
- (void)sendResultToIonic:(NSString*)result
{
[self.ionicComms returnResult:result];
}
- (void)onAppWillTerminateCallback:(NSNotification*)notification
{
[self.unityController applicationWillTerminate:[UIApplication sharedApplication]];
}
- (void)onAppWillResignActiveCallback:(NSNotification*)notification
{
[self.unityController applicationWillResignActive:[UIApplication sharedApplication]];
}
- (void)onAppWillEnterForegroundCallback:(NSNotification*)notification
{
[self.unityController applicationWillEnterForeground:[UIApplication sharedApplication]];
}
- (void)onAppDidBecomeActiveCallback:(NSNotification*)notification
{
[self.unityController applicationDidBecomeActive:[UIApplication sharedApplication]];
}
- (void)onAppDidEnterBackgroundCallback:(NSNotification*)notification
{
[self.unityController applicationDidEnterBackground:[UIApplication sharedApplication]];
}
-(void)applicationWillResignActive:(UIApplication *)application{
//[self.unityController applicationWillResignActive:application];
}
-(void)applicationDidEnterBackground:(UIApplication *)application{
//[self.unityController applicationDidEnterBackground:application];
}
-(void)applicationWillEnterForeground:(UIApplication *)application{
//[self.unityController applicationWillEnterForeground:application];
}
-(void)applicationDidBecomeActive:(UIApplication *)application{
//[self.unityController applicationDidBecomeActive:application];
}
-(void)applicationWillTerminate:(UIApplication *)application{
//[self.unityController applicationWillTerminate:application];
}
@end