UnityInterface.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdarg.h>
  4. #include "UnityForwardDecls.h"
  5. #include "UnityRendering.h"
  6. // unity plugin functions
  7. // audio plugin api
  8. typedef int (*UnityPluginGetAudioEffectDefinitionsFunc)(struct UnityAudioEffectDefinition*** descptr);
  9. // OLD rendering plugin api (will become obsolete soon)
  10. typedef void (*UnityPluginSetGraphicsDeviceFunc)(void* device, int deviceType, int eventType);
  11. typedef void (*UnityPluginRenderMarkerFunc)(int marker);
  12. // new rendering plugin api
  13. typedef void (*UnityPluginLoadFunc)(struct IUnityInterfaces* unityInterfaces);
  14. typedef void (*UnityPluginUnloadFunc)();
  15. // log handler function
  16. #ifdef __cplusplus
  17. typedef bool (*LogEntryHandler)(LogType logType, const char* log, va_list list);
  18. #endif
  19. //
  20. // these are functions referenced in trampoline and implemented in unity player lib
  21. //
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. // life cycle management
  26. void UnityInitStartupTime();
  27. void UnityInitRuntime(int argc, char* argv[]);
  28. void UnityInitApplicationNoGraphics(const char* appPathName);
  29. void UnityInitApplicationGraphics();
  30. void UnityCleanup();
  31. void UnityLoadApplication();
  32. void UnityPlayerLoop(); // normal player loop
  33. void UnityBatchPlayerLoop(); // batch mode like player loop, without rendering (usable for background processing)
  34. void UnitySetPlayerFocus(int focused); // send OnApplicationFocus() message to scripts
  35. void UnityLowMemory();
  36. void UnityPause(int pause);
  37. int UnityIsPaused(); // 0 if player is running, 1 if paused
  38. void UnityWillPause(); // send the message that app will pause
  39. void UnityWillResume(); // send the message that app will resume
  40. void UnityInputProcess();
  41. void UnityDeliverUIEvents(); // unity processing impacting UI will be called in there
  42. // rendering
  43. int UnityGetRenderingAPIs(int capacity, int* outAPIs);
  44. void UnityFinishRendering();
  45. // OpenGL ES.
  46. int UnityHasRenderingAPIExtension(const char* extension);
  47. void UnityOnSetCurrentGLContext(EAGLContext* context);
  48. // This must match the one in ApiEnumsGLES.h
  49. typedef enum UnityFramebufferTarget
  50. {
  51. kDrawFramebuffer = 0,
  52. kReadFramebuffer,
  53. kFramebufferTargetCount
  54. } UnityFramebufferTarget;
  55. void UnityBindFramebuffer(UnityFramebufferTarget target, int fbo);
  56. void UnityRegisterFBO(UnityRenderBufferHandle color, UnityRenderBufferHandle depth, unsigned fbo);
  57. // when texture (managed in trampoline) is used in unity (e.g. with external render surfaces)
  58. // we need to poke unity when we delete it (so it could clear caches etc)
  59. void UnityOnDeleteGLTexture(int tex);
  60. // controling player internals
  61. // TODO: needs some cleanup
  62. void UnitySetAudioSessionActive(int active);
  63. void UnityGLInvalidateState();
  64. void UnityReloadResources();
  65. int UnityIsCaptureScreenshotRequested();
  66. void UnityCaptureScreenshot();
  67. void UnitySendMessage(const char* obj, const char* method, const char* msg);
  68. EAGLContext* UnityGetDataContextGLES();
  69. #ifdef __cplusplus
  70. void UnitySetLogEntryHandler(LogEntryHandler newHandler);
  71. #endif
  72. // plugins support
  73. // WARNING: old UnityRegisterRenderingPlugin will become obsolete soon
  74. void UnityRegisterRenderingPlugin(UnityPluginSetGraphicsDeviceFunc setDevice, UnityPluginRenderMarkerFunc renderMarker);
  75. void UnityRegisterRenderingPluginV5(UnityPluginLoadFunc loadPlugin, UnityPluginUnloadFunc unloadPlugin);
  76. void UnityRegisterAudioPlugin(UnityPluginGetAudioEffectDefinitionsFunc getAudioEffectDefinitions);
  77. // resolution/orientation handling
  78. void UnityGetRenderingResolution(unsigned* w, unsigned* h);
  79. void UnityGetSystemResolution(unsigned* w, unsigned* h);
  80. void UnityRequestRenderingResolution(unsigned w, unsigned h);
  81. int UnityIsOrientationEnabled(unsigned /*ScreenOrientation*/ orientation);
  82. int UnityHasOrientationRequest();
  83. int UnityShouldAutorotate();
  84. int UnityRequestedScreenOrientation(); // returns ScreenOrientation
  85. void UnityOrientationRequestWasCommitted();
  86. int UnityReportResizeView(unsigned w, unsigned h, unsigned /*ScreenOrientation*/ contentOrientation); // returns ScreenOrientation
  87. void UnityReportSafeAreaChange(float x, float y, float w, float h);
  88. void UnityReportBackbufferChange(UnityRenderBufferHandle colorBB, UnityRenderBufferHandle depthBB);
  89. float UnityCalculateScalingFactorFromTargetDPI(UIScreen* screen);
  90. // player settings
  91. int UnityDisableDepthAndStencilBuffers();
  92. int UnityUseAnimatedAutorotation();
  93. int UnityGetDesiredMSAASampleCount(int defaultSampleCount);
  94. int UnityGetSRGBRequested();
  95. int UnityGetWideColorRequested();
  96. int UnityGetShowActivityIndicatorOnLoading();
  97. int UnityGetAccelerometerFrequency();
  98. int UnityGetTargetFPS();
  99. int UnityGetUseCustomAppBackgroundBehavior();
  100. int UnityGetDeferSystemGesturesTopEdge();
  101. int UnityGetDeferSystemGesturesBottomEdge();
  102. int UnityGetDeferSystemGesturesLeftEdge();
  103. int UnityGetDeferSystemGesturesRightEdge();
  104. int UnityGetHideHomeButton();
  105. int UnityMetalFramebufferOnly();
  106. // push notifications
  107. #if !PLATFORM_TVOS
  108. void UnitySendLocalNotification(UILocalNotification* notification);
  109. #endif
  110. void UnitySendRemoteNotification(NSDictionary* notification);
  111. void UnitySendDeviceToken(NSData* deviceToken);
  112. void UnitySendRemoteNotificationError(NSError* error);
  113. // native events
  114. void UnityInvalidateDisplayDataCache(void* screen);
  115. void UnityUpdateDisplayList(void** screens, int screenCount);
  116. // profiler
  117. void* UnityCreateProfilerCounter(const char*);
  118. void UnityDestroyProfilerCounter(void*);
  119. void UnityStartProfilerCounter(void*);
  120. void UnityEndProfilerCounter(void*);
  121. // sensors
  122. void UnitySensorsSetGyroRotationRate(int idx, float x, float y, float z);
  123. void UnitySensorsSetGyroRotationRateUnbiased(int idx, float x, float y, float z);
  124. void UnitySensorsSetGravity(int idx, float x, float y, float z);
  125. void UnitySensorsSetUserAcceleration(int idx, float x, float y, float z);
  126. void UnitySensorsSetAttitude(int idx, float x, float y, float z, float w);
  127. void UnityDidAccelerate(float x, float y, float z, double timestamp);
  128. void UnitySetJoystickPosition(int joyNum, int axis, float pos);
  129. int UnityStringToKey(const char *name);
  130. void UnitySetKeyState(int key, int /*bool*/ state);
  131. // WWW connection handling
  132. void UnityReportWWWStatus(void* udata, int status);
  133. void UnityReportWWWNetworkError(void* udata, int status);
  134. void UnityReportWWWResponseHeader(void* udata, const char* headerName, const char* headerValue);
  135. void UnityReportWWWReceivedResponse(void* udata, unsigned expectedDataLength);
  136. void UnityReportWWWReceivedData(void* udata, const void* buffer, unsigned totalRead, unsigned expectedTotal);
  137. void UnityReportWWWFinishedLoadingData(void* udata);
  138. void UnityReportWWWSentData(void* udata, unsigned totalWritten, unsigned expectedTotal);
  139. const void* UnityWWWGetUploadData(void* udata, unsigned* bufferSize);
  140. void UnityWWWConsumeUploadData(void* udata, unsigned consumedSize);
  141. // AVCapture
  142. void UnityReportAVCapturePermission();
  143. void UnityDidCaptureVideoFrame(intptr_t tex, void* udata);
  144. // logging override
  145. #ifdef __cplusplus
  146. } // extern "C"
  147. #endif
  148. // touches processing
  149. #ifdef __cplusplus
  150. extern "C" {
  151. #endif
  152. void UnitySetViewTouchProcessing(UIView* view, int /*ViewTouchProcessing*/ processingPolicy);
  153. void UnityDropViewTouchProcessing(UIView* view);
  154. void UnitySendTouchesBegin(NSSet* touches, UIEvent* event);
  155. void UnitySendTouchesEnded(NSSet* touches, UIEvent* event);
  156. void UnitySendTouchesCancelled(NSSet* touches, UIEvent* event);
  157. void UnitySendTouchesMoved(NSSet* touches, UIEvent* event);
  158. void UnityCancelTouches();
  159. #ifdef __cplusplus
  160. } // extern "C"
  161. #endif
  162. //
  163. // these are functions referenced and implemented in trampoline
  164. //
  165. #ifdef __cplusplus
  166. extern "C" {
  167. #endif
  168. // UnityAppController.mm
  169. UIViewController* UnityGetGLViewController();
  170. UIView* UnityGetGLView();
  171. UIWindow* UnityGetMainWindow();
  172. enum ScreenOrientation UnityCurrentOrientation();
  173. // Unity/DisplayManager.mm
  174. float UnityScreenScaleFactor(UIScreen* screen);
  175. #ifdef __cplusplus
  176. } // extern "C"
  177. #endif
  178. //
  179. // these are functions referenced in unity player lib and implemented in trampoline
  180. //
  181. #ifdef __cplusplus
  182. extern "C" {
  183. #endif
  184. // iPhone_Sensors.mm
  185. void UnityInitJoysticks();
  186. void UnityCoreMotionStart();
  187. void UnityCoreMotionStop();
  188. int UnityIsGyroEnabled(int idx);
  189. int UnityIsGyroAvailable();
  190. void UnityUpdateGyroData();
  191. void UnitySetGyroUpdateInterval(int idx, float interval);
  192. float UnityGetGyroUpdateInterval(int idx);
  193. void UnityUpdateJoystickData();
  194. int UnityGetJoystickCount();
  195. void UnityGetJoystickName(int idx, char* buffer, int maxLen);
  196. void UnityGetJoystickAxisName(int idx, int axis, char* buffer, int maxLen);
  197. void UnityGetNiceKeyname(int key, char* buffer, int maxLen);
  198. // UnityAppController+Rendering.mm
  199. void UnityInitMainScreenRenderingCallback();
  200. void UnityGfxInitedCallback();
  201. void UnityPresentContextCallback(struct UnityFrameStats const* frameStats);
  202. void UnityFramerateChangeCallback(int targetFPS);
  203. int UnitySelectedRenderingAPI();
  204. NSBundle* UnityGetMetalBundle();
  205. MTLDeviceRef UnityGetMetalDevice();
  206. MTLCommandQueueRef UnityGetMetalCommandQueue();
  207. MTLCommandQueueRef UnityGetMetalDrawableCommandQueue();
  208. EAGLContext* UnityGetDataContextEAGL();
  209. UnityRenderBufferHandle UnityBackbufferColor();
  210. UnityRenderBufferHandle UnityBackbufferDepth();
  211. int UnityGetWideColorSupported();
  212. // UI/ActivityIndicator.mm
  213. void UnityStartActivityIndicator();
  214. void UnityStopActivityIndicator();
  215. // UI/Keyboard.mm
  216. void UnityKeyboard_Create(unsigned keyboardType, int autocorrection, int multiline, int secure, int alert, const char* text, const char* placeholder);
  217. void UnityKeyboard_Show();
  218. void UnityKeyboard_Hide();
  219. void UnityKeyboard_GetRect(float* x, float* y, float* w, float* h);
  220. void UnityKeyboard_SetText(const char* text);
  221. NSString* UnityKeyboard_GetText();
  222. int UnityKeyboard_IsActive();
  223. int UnityKeyboard_IsDone();
  224. int UnityKeyboard_WasCanceled();
  225. int UnityKeyboard_Status();
  226. void UnityKeyboard_SetInputHidden(int hidden);
  227. int UnityKeyboard_IsInputHidden();
  228. int UnityKeyboard_CanGetSelection();
  229. void UnityKeyboard_GetSelection(int* location, int* range);
  230. // UI/UnityViewControllerBase.mm
  231. void UnityNotifyAutoOrientationChange();
  232. void UnityNotifyHideHomeButtonChange();
  233. void UnityNotifyDeferSystemGesturesChange();
  234. // Unity/AVCapture.mm
  235. int UnityGetAVCapturePermission(int captureTypes);
  236. void UnityRequestAVCapturePermission(int captureTypes);
  237. // Unity/CameraCapture.mm
  238. void UnityEnumVideoCaptureDevices(void* udata, void(*callback)(void* udata, const char* name, int frontFacing));
  239. void* UnityInitCameraCapture(int device, int w, int h, int fps, void* udata);
  240. void UnityStartCameraCapture(void* capture);
  241. void UnityPauseCameraCapture(void* capture);
  242. void UnityStopCameraCapture(void* capture);
  243. void UnityCameraCaptureExtents(void* capture, int* w, int* h);
  244. void UnityCameraCaptureReadToMemory(void* capture, void* dst, int w, int h);
  245. int UnityCameraCaptureVideoRotationDeg(void* capture);
  246. int UnityCameraCaptureVerticallyMirrored(void* capture);
  247. // Unity/DeviceSettings.mm
  248. const char* UnityDeviceUniqueIdentifier();
  249. const char* UnityVendorIdentifier();
  250. const char* UnityAdvertisingIdentifier();
  251. int UnityAdvertisingTrackingEnabled();
  252. const char* UnityDeviceName();
  253. const char* UnitySystemName();
  254. const char* UnitySystemVersion();
  255. const char* UnityDeviceModel();
  256. int UnityDeviceCPUCount();
  257. int UnityGetPhysicalMemory();
  258. int UnityDeviceGeneration();
  259. float UnityDeviceDPI();
  260. const char* UnitySystemLanguage();
  261. int UnityDeviceSupportsUpsideDown();
  262. // Unity/DisplayManager.mm
  263. EAGLContext* UnityGetMainScreenContextGLES();
  264. EAGLContext* UnityGetContextEAGL();
  265. void UnityStartFrameRendering();
  266. void UnityDestroyUnityRenderSurfaces();
  267. int UnityMainScreenRefreshRate();
  268. // Unity/Filesystem.mm
  269. const char* UnityApplicationDir();
  270. const char* UnityDocumentsDir();
  271. const char* UnityLibraryDir();
  272. const char* UnityCachesDir();
  273. int UnityUpdateNoBackupFlag(const char* path, int setFlag); // Returns 1 if successful, otherwise 0
  274. // Unity/MetalHelper.mm
  275. void UnityAddNewMetalAPIImplIfNeeded(MTLDeviceRef device);
  276. // Unity/WWWConnection.mm
  277. void* UnityStartWWWConnectionGet(void* udata, const void* headerDict, const char* url);
  278. void* UnityStartWWWConnectionPost(void* udata, const void* headerDict, const char* url, const void* data, unsigned length);
  279. void UnityDestroyWWWConnection(void* connection);
  280. void UnityShouldCancelWWW(const void* connection);
  281. // Unity/FullScreenVideoPlayer.mm
  282. int UnityIsFullScreenPlaying();
  283. void TryResumeFullScreenVideo();
  284. //Apple TV Remote
  285. int UnityGetAppleTVRemoteAllowExitToMenu();
  286. void UnitySetAppleTVRemoteAllowExitToMenu(int val);
  287. int UnityGetAppleTVRemoteAllowRotation();
  288. void UnitySetAppleTVRemoteAllowRotation(int val);
  289. int UnityGetAppleTVRemoteReportAbsoluteDpadValues();
  290. void UnitySetAppleTVRemoteReportAbsoluteDpadValues(int val);
  291. int UnityGetAppleTVRemoteTouchesEnabled();
  292. void UnitySetAppleTVRemoteTouchesEnabled(int val);
  293. #ifdef __cplusplus
  294. } // extern "C"
  295. #endif
  296. #ifdef __OBJC__
  297. // This is basically a wrapper for [NSString UTF8String] with additional strdup.
  298. //
  299. // Apparently multiple calls on UTF8String will leak memory (NSData objects) that are collected
  300. // only when @autoreleasepool is exited. This function serves as documentation for this and as a
  301. // handy wrapper.
  302. inline char* AllocCString(NSString* value)
  303. {
  304. if (value == nil)
  305. return 0;
  306. const char* str = [value UTF8String];
  307. return str ? strdup(str) : 0;
  308. }
  309. #endif