[add] first
This commit is contained in:
60
Classes/PluginBase/AppDelegateListener.h
Normal file
60
Classes/PluginBase/AppDelegateListener.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "LifeCycleListener.h"
|
||||
|
||||
|
||||
@protocol AppDelegateListener<LifeCycleListener>
|
||||
@optional
|
||||
// these do not have apple defined notifications, so we use our own notifications
|
||||
|
||||
// notification will be posted from
|
||||
// - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
|
||||
// notification user data is deviceToken
|
||||
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSNotification*)notification;
|
||||
|
||||
// notification will be posted from
|
||||
// - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
|
||||
// notification user data is error
|
||||
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSNotification*)notification;
|
||||
|
||||
// notification will be posted from
|
||||
// - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
|
||||
// notification user data is userInfo
|
||||
- (void)didReceiveRemoteNotification:(NSNotification*)notification;
|
||||
|
||||
// notification will be posted from
|
||||
// - (void)application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification
|
||||
// notification user data is notification
|
||||
- (void)didReceiveLocalNotification:(NSNotification*)notification;
|
||||
|
||||
// notification will be posted from
|
||||
// - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
|
||||
// notification user data is the NSDictionary containing all the params
|
||||
- (void)onOpenURL:(NSNotification*)notification;
|
||||
|
||||
// notification will be posted from
|
||||
// - (BOOL)application:(UIApplication*)application willFinishLaunchingWithOptions:(NSDictionary*)launchOptions
|
||||
// notification user data is the NSDictionary containing launchOptions
|
||||
- (void)applicationWillFinishLaunchingWithOptions:(NSNotification*)notification;
|
||||
// notification will be posted from
|
||||
// - (void)application:(UIApplication*)application handleEventsForBackgroundURLSession:(nonnull NSString *)identifier completionHandler:(nonnull void (^)())completionHandler
|
||||
// notification user data is NSDictionary with one item where key is session identifier and value is completion handler
|
||||
- (void)onHandleEventsForBackgroundURLSession:(NSNotification*)notification;
|
||||
|
||||
// these are just hooks to existing notifications
|
||||
- (void)applicationDidReceiveMemoryWarning:(NSNotification*)notification;
|
||||
- (void)applicationSignificantTimeChange:(NSNotification*)notification;
|
||||
- (void)applicationWillChangeStatusBarFrame:(NSNotification*)notification;
|
||||
- (void)applicationWillChangeStatusBarOrientation:(NSNotification*)notification;
|
||||
@end
|
||||
|
||||
void UnityRegisterAppDelegateListener(id<AppDelegateListener> obj);
|
||||
void UnityUnregisterAppDelegateListener(id<AppDelegateListener> obj);
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityDidRegisterForRemoteNotificationsWithDeviceToken;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityDidFailToRegisterForRemoteNotificationsWithError;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityDidReceiveRemoteNotification;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityDidReceiveLocalNotification;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityOnOpenURL;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityWillFinishLaunchingWithOptions;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityHandleEventsForBackgroundURLSession;
|
||||
62
Classes/PluginBase/AppDelegateListener.mm
Normal file
62
Classes/PluginBase/AppDelegateListener.mm
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "AppDelegateListener.h"
|
||||
|
||||
#define DEFINE_NOTIFICATION(name) extern "C" __attribute__((visibility ("default"))) NSString* const name = @#name;
|
||||
|
||||
DEFINE_NOTIFICATION(kUnityDidRegisterForRemoteNotificationsWithDeviceToken);
|
||||
DEFINE_NOTIFICATION(kUnityDidFailToRegisterForRemoteNotificationsWithError);
|
||||
DEFINE_NOTIFICATION(kUnityDidReceiveRemoteNotification);
|
||||
DEFINE_NOTIFICATION(kUnityDidReceiveLocalNotification);
|
||||
DEFINE_NOTIFICATION(kUnityOnOpenURL);
|
||||
DEFINE_NOTIFICATION(kUnityWillFinishLaunchingWithOptions);
|
||||
DEFINE_NOTIFICATION(kUnityHandleEventsForBackgroundURLSession);
|
||||
|
||||
#undef DEFINE_NOTIFICATION
|
||||
|
||||
void UnityRegisterAppDelegateListener(id<AppDelegateListener> obj)
|
||||
{
|
||||
#define REGISTER_SELECTOR(sel, notif_name) \
|
||||
if([obj respondsToSelector:sel]) \
|
||||
[[NSNotificationCenter defaultCenter] addObserver:obj \
|
||||
selector:sel \
|
||||
name:notif_name \
|
||||
object:nil \
|
||||
]; \
|
||||
|
||||
UnityRegisterLifeCycleListener(obj);
|
||||
|
||||
REGISTER_SELECTOR(@selector(didRegisterForRemoteNotificationsWithDeviceToken:), kUnityDidRegisterForRemoteNotificationsWithDeviceToken);
|
||||
REGISTER_SELECTOR(@selector(didFailToRegisterForRemoteNotificationsWithError:), kUnityDidFailToRegisterForRemoteNotificationsWithError);
|
||||
REGISTER_SELECTOR(@selector(didReceiveRemoteNotification:), kUnityDidReceiveRemoteNotification);
|
||||
REGISTER_SELECTOR(@selector(didReceiveLocalNotification:), kUnityDidReceiveLocalNotification);
|
||||
REGISTER_SELECTOR(@selector(onOpenURL:), kUnityOnOpenURL);
|
||||
|
||||
REGISTER_SELECTOR(@selector(applicationDidReceiveMemoryWarning:), UIApplicationDidReceiveMemoryWarningNotification);
|
||||
REGISTER_SELECTOR(@selector(applicationSignificantTimeChange:), UIApplicationSignificantTimeChangeNotification);
|
||||
#if !PLATFORM_TVOS
|
||||
REGISTER_SELECTOR(@selector(applicationWillChangeStatusBarFrame:), UIApplicationWillChangeStatusBarFrameNotification);
|
||||
REGISTER_SELECTOR(@selector(applicationWillChangeStatusBarOrientation:), UIApplicationWillChangeStatusBarOrientationNotification);
|
||||
#endif
|
||||
|
||||
REGISTER_SELECTOR(@selector(applicationWillFinishLaunchingWithOptions:), kUnityWillFinishLaunchingWithOptions);
|
||||
REGISTER_SELECTOR(@selector(onHandleEventsForBackgroundURLSession:), kUnityHandleEventsForBackgroundURLSession);
|
||||
|
||||
#undef REGISTER_SELECTOR
|
||||
}
|
||||
|
||||
void UnityUnregisterAppDelegateListener(id<AppDelegateListener> obj)
|
||||
{
|
||||
UnityUnregisterLifeCycleListener(obj);
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityDidRegisterForRemoteNotificationsWithDeviceToken object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityDidFailToRegisterForRemoteNotificationsWithError object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityDidReceiveRemoteNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityDidReceiveLocalNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityOnOpenURL object: nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationDidReceiveMemoryWarningNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationSignificantTimeChangeNotification object: nil];
|
||||
#if !PLATFORM_TVOS
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationWillChangeStatusBarFrameNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationWillChangeStatusBarOrientationNotification object: nil];
|
||||
#endif
|
||||
}
|
||||
29
Classes/PluginBase/LifeCycleListener.h
Normal file
29
Classes/PluginBase/LifeCycleListener.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
// important app life-cycle events
|
||||
|
||||
@protocol LifeCycleListener<NSObject>
|
||||
@optional
|
||||
- (void)didFinishLaunching:(NSNotification*)notification;
|
||||
- (void)didBecomeActive:(NSNotification*)notification;
|
||||
- (void)willResignActive:(NSNotification*)notification;
|
||||
- (void)didEnterBackground:(NSNotification*)notification;
|
||||
- (void)willEnterForeground:(NSNotification*)notification;
|
||||
- (void)willTerminate:(NSNotification*)notification;
|
||||
- (void)unityDidUnload:(NSNotification*)notification;
|
||||
- (void)unityDidQuit:(NSNotification*)notification;
|
||||
@end
|
||||
|
||||
void UnityRegisterLifeCycleListener(id<LifeCycleListener> obj);
|
||||
void UnityUnregisterLifeCycleListener(id<LifeCycleListener> obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern __attribute__((visibility("default"))) NSString* const kUnityDidUnload;
|
||||
extern __attribute__((visibility("default"))) NSString* const kUnityDidQuit;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
39
Classes/PluginBase/LifeCycleListener.mm
Normal file
39
Classes/PluginBase/LifeCycleListener.mm
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "LifeCycleListener.h"
|
||||
|
||||
#define DEFINE_NOTIFICATION(name) extern "C" __attribute__((visibility ("default"))) NSString* const name = @#name;
|
||||
DEFINE_NOTIFICATION(kUnityDidUnload);
|
||||
DEFINE_NOTIFICATION(kUnityDidQuit);
|
||||
|
||||
void UnityRegisterLifeCycleListener(id<LifeCycleListener> obj)
|
||||
{
|
||||
#define REGISTER_SELECTOR(sel, notif_name) \
|
||||
if([obj respondsToSelector:sel]) \
|
||||
[[NSNotificationCenter defaultCenter] addObserver:obj \
|
||||
selector:sel \
|
||||
name:notif_name \
|
||||
object:nil \
|
||||
]; \
|
||||
|
||||
REGISTER_SELECTOR(@selector(didFinishLaunching:), UIApplicationDidFinishLaunchingNotification);
|
||||
REGISTER_SELECTOR(@selector(didBecomeActive:), UIApplicationDidBecomeActiveNotification);
|
||||
REGISTER_SELECTOR(@selector(willResignActive:), UIApplicationWillResignActiveNotification);
|
||||
REGISTER_SELECTOR(@selector(didEnterBackground:), UIApplicationDidEnterBackgroundNotification);
|
||||
REGISTER_SELECTOR(@selector(willEnterForeground:), UIApplicationWillEnterForegroundNotification);
|
||||
REGISTER_SELECTOR(@selector(willTerminate:), UIApplicationWillTerminateNotification);
|
||||
REGISTER_SELECTOR(@selector(unityDidUnload:), kUnityDidUnload);
|
||||
REGISTER_SELECTOR(@selector(unityDidQuit:), kUnityDidQuit);
|
||||
|
||||
#undef REGISTER_SELECTOR
|
||||
}
|
||||
|
||||
void UnityUnregisterLifeCycleListener(id<LifeCycleListener> obj)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationDidFinishLaunchingNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationDidBecomeActiveNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationWillResignActiveNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationDidEnterBackgroundNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationWillEnterForegroundNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: UIApplicationWillTerminateNotification object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityDidUnload object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityDidQuit object: nil];
|
||||
}
|
||||
68
Classes/PluginBase/RenderPluginDelegate.h
Normal file
68
Classes/PluginBase/RenderPluginDelegate.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include "LifeCycleListener.h"
|
||||
|
||||
struct UnityDisplaySurfaceBase; // Unity/UnityRendering.h
|
||||
struct RenderingSurfaceParams; // Unity/DisplayManager.h
|
||||
|
||||
// due to delicate nature of render loop we have just one delegate in app
|
||||
// if you need to use several rendering delegates you need to do one of:
|
||||
// 1. create custom delegate that will have code to combine effects by itself
|
||||
// 2. use helper that simply holds array of delegates (which will work only in easiest cases)
|
||||
@protocol RenderPluginDelegate<LifeCycleListener, NSObject>
|
||||
|
||||
@required
|
||||
// this will be called right after gles intialization.
|
||||
// surface pointer will never be changed, so you should keep it.
|
||||
// the only valid fields in there as of now are layer and context
|
||||
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
|
||||
|
||||
@optional
|
||||
|
||||
// this will be called before recreating main display surface (from [UnityView recreateRenderingSurface])
|
||||
// you can tweak params here.
|
||||
// use it for enabling CVTextureCache support and the likes
|
||||
- (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
|
||||
|
||||
// this will be called right after recreating main display surface (from [UnityView recreateRenderingSurface])
|
||||
// as [UnityView recreateRenderingSurface] is the only place where unity itself will trigger surface recreate
|
||||
// you can use this method to update your rendering depending on changes
|
||||
- (void)onAfterMainDisplaySurfaceRecreate;
|
||||
|
||||
// this will be called after frame render and msaa resolve but before blitting to system FB
|
||||
// you can expect that frame contents are ready (though still in target resolution)
|
||||
// use it for anylizing/postprocessing rendered frame, taking screenshot and the like
|
||||
// you should use targetFB if it is not 0
|
||||
// otherwise use systemFB (covers case of intermediate fb not needed: no msaa, native res, no CVTextureCache involved)
|
||||
- (void)onFrameResolved;
|
||||
@end
|
||||
|
||||
|
||||
// simple helper for common plugin stuff
|
||||
// you can implement protocol directly, but subclassing this will provide some common implementation
|
||||
@interface RenderPluginDelegate : NSObject<RenderPluginDelegate>
|
||||
{
|
||||
struct UnityDisplaySurfaceBase* mainDisplaySurface;
|
||||
}
|
||||
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
|
||||
@end
|
||||
|
||||
|
||||
// simple helper to have an array of render delegates.
|
||||
// be warned that it works in simplest cases only, when there is no interop between delegates
|
||||
@interface RenderPluginArrayDelegate : RenderPluginDelegate
|
||||
{
|
||||
NSArray* delegateArray;
|
||||
}
|
||||
@property(nonatomic, retain) NSArray* delegateArray;
|
||||
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
|
||||
- (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
|
||||
- (void)onAfterMainDisplaySurfaceRecreate;
|
||||
- (void)onFrameResolved;
|
||||
|
||||
- (void)didBecomeActive:(NSNotification*)notification;
|
||||
- (void)willResignActive:(NSNotification*)notification;
|
||||
- (void)didEnterBackground:(NSNotification*)notification;
|
||||
- (void)willEnterForeground:(NSNotification*)notification;
|
||||
- (void)willTerminate:(NSNotification*)notification;
|
||||
@end
|
||||
90
Classes/PluginBase/RenderPluginDelegate.mm
Normal file
90
Classes/PluginBase/RenderPluginDelegate.mm
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "RenderPluginDelegate.h"
|
||||
|
||||
@implementation RenderPluginDelegate
|
||||
|
||||
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface
|
||||
{
|
||||
mainDisplaySurface = surface;
|
||||
|
||||
// TODO: move lifecycle to init?
|
||||
UnityRegisterLifeCycleListener(self);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#define CALL_METHOD_ON_ARRAY(method) \
|
||||
do{ \
|
||||
for(id<RenderPluginDelegate> del in delegateArray) \
|
||||
{ \
|
||||
if([del respondsToSelector:@selector(method)]) \
|
||||
[del method]; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define CALL_METHOD_ON_ARRAY_ARG(method, arg) \
|
||||
do{ \
|
||||
for(id<RenderPluginDelegate> del in delegateArray) \
|
||||
{ \
|
||||
if([del respondsToSelector:@selector(method:)]) \
|
||||
[del method:arg]; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
@implementation RenderPluginArrayDelegate
|
||||
|
||||
@synthesize delegateArray;
|
||||
|
||||
- (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface
|
||||
{
|
||||
[super mainDisplayInited: surface];
|
||||
CALL_METHOD_ON_ARRAY_ARG(mainDisplayInited, surface);
|
||||
}
|
||||
|
||||
- (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY_ARG(onBeforeMainDisplaySurfaceRecreate, params);
|
||||
}
|
||||
|
||||
- (void)onAfterMainDisplaySurfaceRecreate;
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY(onAfterMainDisplaySurfaceRecreate);
|
||||
}
|
||||
|
||||
- (void)onFrameResolved;
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY(onFrameResolved);
|
||||
}
|
||||
|
||||
|
||||
- (void)didBecomeActive:(NSNotification*)notification
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY_ARG(didBecomeActive, notification);
|
||||
}
|
||||
|
||||
- (void)willResignActive:(NSNotification*)notification
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY_ARG(willResignActive, notification);
|
||||
}
|
||||
|
||||
- (void)didEnterBackground:(NSNotification*)notification
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY_ARG(didEnterBackground, notification);
|
||||
}
|
||||
|
||||
- (void)willEnterForeground:(NSNotification*)notification
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY_ARG(willEnterForeground, notification);
|
||||
}
|
||||
|
||||
- (void)willTerminate:(NSNotification*)notification
|
||||
{
|
||||
CALL_METHOD_ON_ARRAY_ARG(willTerminate, notification);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#undef CALL_METHOD_ON_ARRAY
|
||||
#undef CALL_METHOD_ON_ARRAY_ARG
|
||||
51
Classes/PluginBase/UnityViewControllerListener.h
Normal file
51
Classes/PluginBase/UnityViewControllerListener.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/NSNotification.h>
|
||||
|
||||
// view changes on the main view controller
|
||||
|
||||
@protocol UnityViewControllerListener<NSObject>
|
||||
@optional
|
||||
- (void)viewWillLayoutSubviews:(NSNotification*)notification;
|
||||
- (void)viewDidLayoutSubviews:(NSNotification*)notification;
|
||||
- (void)viewWillDisappear:(NSNotification*)notification;
|
||||
- (void)viewDidDisappear:(NSNotification*)notification;
|
||||
- (void)viewWillAppear:(NSNotification*)notification;
|
||||
- (void)viewDidAppear:(NSNotification*)notification;
|
||||
|
||||
- (void)interfaceWillChangeOrientation:(NSNotification*)notification;
|
||||
- (void)interfaceDidChangeOrientation:(NSNotification*)notification;
|
||||
@end
|
||||
|
||||
@protocol UnityViewControllerNotifications<NSObject>
|
||||
@optional
|
||||
- (void)onViewWillLayoutSubviews;
|
||||
- (void)onViewDidLayoutSubviews;
|
||||
- (void)onViewDidDisappear:(BOOL)animated;
|
||||
- (void)onViewWillDisappear:(BOOL)animated;
|
||||
- (void)onViewDidAppear:(BOOL)animated;
|
||||
- (void)onViewWillAppear:(BOOL)animated;
|
||||
@end
|
||||
|
||||
// this default delegate will send notifications for UnityViewControllerListener
|
||||
@interface UnityViewControllerNotificationsDefaultSender : NSObject<UnityViewControllerNotifications>
|
||||
- (void)onViewWillLayoutSubviews;
|
||||
- (void)onViewDidLayoutSubviews;
|
||||
- (void)onViewDidDisappear:(BOOL)animated;
|
||||
- (void)onViewWillDisappear:(BOOL)animated;
|
||||
- (void)onViewDidAppear:(BOOL)animated;
|
||||
- (void)onViewWillAppear:(BOOL)animated;
|
||||
@end
|
||||
|
||||
|
||||
void UnityRegisterViewControllerListener(id<UnityViewControllerListener> obj);
|
||||
void UnityUnregisterViewControllerListener(id<UnityViewControllerListener> obj);
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityViewWillLayoutSubviews;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityViewDidLayoutSubviews;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityViewWillDisappear;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityViewDidDisappear;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityViewWillAppear;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityViewDidAppear;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityInterfaceWillChangeOrientation;
|
||||
extern "C" __attribute__((visibility("default"))) NSString* const kUnityInterfaceDidChangeOrientation;
|
||||
80
Classes/PluginBase/UnityViewControllerListener.mm
Normal file
80
Classes/PluginBase/UnityViewControllerListener.mm
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "UnityViewControllerListener.h"
|
||||
#include <UIKit/UIApplication.h>
|
||||
|
||||
#define DEFINE_NOTIFICATION(name) extern "C" __attribute__((visibility ("default"))) NSString* const name = @#name;
|
||||
|
||||
DEFINE_NOTIFICATION(kUnityViewWillLayoutSubviews);
|
||||
DEFINE_NOTIFICATION(kUnityViewDidLayoutSubviews);
|
||||
DEFINE_NOTIFICATION(kUnityViewWillDisappear);
|
||||
DEFINE_NOTIFICATION(kUnityViewDidDisappear);
|
||||
DEFINE_NOTIFICATION(kUnityViewWillAppear);
|
||||
DEFINE_NOTIFICATION(kUnityViewDidAppear);
|
||||
DEFINE_NOTIFICATION(kUnityInterfaceWillChangeOrientation);
|
||||
DEFINE_NOTIFICATION(kUnityInterfaceDidChangeOrientation);
|
||||
|
||||
#undef DEFINE_NOTIFICATION
|
||||
|
||||
void UnityRegisterViewControllerListener(id<UnityViewControllerListener> obj)
|
||||
{
|
||||
#define REGISTER_SELECTOR(sel, notif_name) \
|
||||
if([obj respondsToSelector:sel]) \
|
||||
[[NSNotificationCenter defaultCenter] addObserver:obj selector:sel name:notif_name object:nil]; \
|
||||
|
||||
REGISTER_SELECTOR(@selector(viewWillLayoutSubviews:), kUnityViewWillLayoutSubviews);
|
||||
REGISTER_SELECTOR(@selector(viewDidLayoutSubviews:), kUnityViewDidLayoutSubviews);
|
||||
REGISTER_SELECTOR(@selector(viewWillDisappear:), kUnityViewWillDisappear);
|
||||
REGISTER_SELECTOR(@selector(viewDidDisappear:), kUnityViewDidDisappear);
|
||||
REGISTER_SELECTOR(@selector(viewWillAppear:), kUnityViewWillAppear);
|
||||
REGISTER_SELECTOR(@selector(viewDidAppear:), kUnityViewDidAppear);
|
||||
REGISTER_SELECTOR(@selector(interfaceWillChangeOrientation:), kUnityInterfaceWillChangeOrientation);
|
||||
REGISTER_SELECTOR(@selector(interfaceDidChangeOrientation:), kUnityInterfaceDidChangeOrientation);
|
||||
|
||||
#undef REGISTER_SELECTOR
|
||||
}
|
||||
|
||||
void UnityUnregisterViewControllerListener(id<UnityViewControllerListener> obj)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityViewWillLayoutSubviews object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityViewDidLayoutSubviews object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityViewWillDisappear object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityViewDidDisappear object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityViewWillAppear object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityViewDidAppear object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityInterfaceWillChangeOrientation object: nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: obj name: kUnityInterfaceDidChangeOrientation object: nil];
|
||||
}
|
||||
|
||||
extern void AppController_SendUnityViewControllerNotification(NSString* name);
|
||||
|
||||
@implementation UnityViewControllerNotificationsDefaultSender
|
||||
- (void)onViewWillLayoutSubviews
|
||||
{
|
||||
AppController_SendUnityViewControllerNotification(kUnityViewWillLayoutSubviews);
|
||||
}
|
||||
|
||||
- (void)onViewDidLayoutSubviews
|
||||
{
|
||||
AppController_SendUnityViewControllerNotification(kUnityViewDidLayoutSubviews);
|
||||
}
|
||||
|
||||
- (void)onViewDidDisappear:(BOOL)animated
|
||||
{
|
||||
AppController_SendUnityViewControllerNotification(kUnityViewDidDisappear);
|
||||
}
|
||||
|
||||
- (void)onViewWillDisappear:(BOOL)animated
|
||||
{
|
||||
AppController_SendUnityViewControllerNotification(kUnityViewWillDisappear);
|
||||
}
|
||||
|
||||
- (void)onViewDidAppear:(BOOL)animated
|
||||
{
|
||||
AppController_SendUnityViewControllerNotification(kUnityViewDidAppear);
|
||||
}
|
||||
|
||||
- (void)onViewWillAppear:(BOOL)animated
|
||||
{
|
||||
AppController_SendUnityViewControllerNotification(kUnityViewWillAppear);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user