UnityInterface.h 16 KB

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