暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UnityAppController.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. #import <QuartzCore/CADisplayLink.h>
  3. #import <UnityFramework/RenderPluginDelegate.h>
  4. @class UnityView;
  5. @class UnityViewControllerBase;
  6. @class DisplayConnection;
  7. typedef enum
  8. {
  9. kUnityEngineLoadStateNotStarted = 0,
  10. // Minimal initialization done, allowing limited API use, such as reporting URL app was launched with
  11. kUnityEngineLoadStateMinimal = 1,
  12. // Core of Unity engine is loaded, but no graphics or first scene yet
  13. kUnityEngineLoadStateCoreInitialized = 2,
  14. // Rendering was initialized, nothing related to rendering should be touched before this state
  15. kUnityEngineLoadStateRenderingInitialized = 3,
  16. // Unity is fully initialized, it's not safe to call Unity APIs before this state
  17. kUnityEngineLoadStateAppReady = 4,
  18. } UnityEngineLoadState;
  19. __attribute__ ((visibility("default")))
  20. @interface UnityAppController : NSObject<UIApplicationDelegate>
  21. {
  22. UnityView* _unityView;
  23. CADisplayLink* _displayLink;
  24. UIWindow* _window;
  25. UIView* _rootView;
  26. UIViewController* _rootController;
  27. UIViewController* _snapshotViewController;
  28. DisplayConnection* _mainDisplay;
  29. // CODE ARCHEOLOGY: we were caching view controllers, both autorotation one and per-fixed-orientation ones
  30. // CODE ARCHEOLOGY: we stopped doing this as the performance impact is negligible,
  31. // CODE ARCHEOLOGY: yet it introduces corner cases and in general lots of code
  32. #if UNITY_SUPPORT_ROTATION
  33. UIInterfaceOrientation _curOrientation;
  34. #endif
  35. id<RenderPluginDelegate> _renderDelegate;
  36. }
  37. // override it to add your render plugin delegate
  38. - (void)shouldAttachRenderDelegate;
  39. // this one is called at the very end of didFinishLaunchingWithOptions:
  40. // after views have been created but before initing engine itself
  41. // override it to register plugins, tweak UI etc
  42. - (void)preStartUnity;
  43. // this one is called at at the very end of didFinishLaunchingWithOptions:
  44. // it will start showing unity view and rendering unity content
  45. - (void)startUnity:(UIApplication*)application;
  46. - (BOOL)advanceEngineLoadState:(UnityEngineLoadState)newState;
  47. // this is a part of UIApplicationDelegate protocol starting with ios5
  48. // setter will be generated empty
  49. @property (retain, nonatomic) UIWindow* window;
  50. @property (readonly, copy, nonatomic) UnityView* unityView;
  51. @property (readonly, copy, nonatomic) CADisplayLink* unityDisplayLink;
  52. @property (readonly, copy, nonatomic) UIView* rootView;
  53. @property (readonly, copy, nonatomic) UIViewController* rootViewController;
  54. @property (readonly, copy, nonatomic) DisplayConnection* mainDisplay;
  55. #if UNITY_SUPPORT_ROTATION
  56. @property (readonly, nonatomic) UIInterfaceOrientation interfaceOrientation;
  57. #endif
  58. @property (readonly) UnityEngineLoadState engineLoadState;
  59. @property (nonatomic, retain) id renderDelegate;
  60. @property (nonatomic, copy) void (^quitHandler)(void);
  61. @end
  62. // accessing app controller
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif
  66. extern UnityAppController* _UnityAppController;
  67. extern UnityAppController* GetAppController(void);
  68. #ifdef __cplusplus
  69. } // extern "C"
  70. #endif
  71. // Put this into mm file with your subclass implementation
  72. // pass subclass name to define
  73. #define IMPL_APP_CONTROLLER_SUBCLASS(ClassName) \
  74. @interface ClassName(OverrideAppDelegate) \
  75. { \
  76. } \
  77. +(void)load; \
  78. @end \
  79. @implementation ClassName(OverrideAppDelegate) \
  80. +(void)load \
  81. { \
  82. extern const char* AppControllerClassName; \
  83. AppControllerClassName = #ClassName; \
  84. } \
  85. @end \
  86. // plugins
  87. #define APP_CONTROLLER_RENDER_PLUGIN_METHOD(method) \
  88. do { \
  89. id<RenderPluginDelegate> delegate = GetAppController().renderDelegate; \
  90. if([delegate respondsToSelector:@selector(method)]) \
  91. [delegate method]; \
  92. } while(0)
  93. #define APP_CONTROLLER_RENDER_PLUGIN_METHOD_ARG(method, arg) \
  94. do { \
  95. id<RenderPluginDelegate> delegate = GetAppController().renderDelegate; \
  96. if([delegate respondsToSelector:@selector(method:)]) \
  97. [delegate method:arg]; \
  98. } while(0)
  99. // these are simple wrappers about ios api, added for convenience
  100. void AppController_SendNotification(NSString* name);
  101. void AppController_SendNotificationWithArg(NSString* name, id arg);
  102. void AppController_SendUnityViewControllerNotification(NSString* name);
  103. // in the case when apple adds new api that has easy fallback path for old ios
  104. // we will add new api methods at runtime on older ios, so we can switch to new api universally
  105. // in that case we still need actual declaration: we will do it here as it is the most convenient place
  106. // history:
  107. // [CADisplayLink preferredFramesPerSecond], [UIScreen maximumFramesPerSecond], [UIView safeAreaInsets]
  108. // were removed after we started to enforce xcode9 (sdk 11)