UnityInterface.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdarg.h>
  4. #include "UnityForwardDecls.h"
  5. #include "UnityRendering.h"
  6. #ifdef __OBJC__
  7. #import "Foundation/Foundation.h"
  8. #endif
  9. // unity plugin functions
  10. // audio plugin api
  11. typedef int (*UnityPluginGetAudioEffectDefinitionsFunc)(struct UnityAudioEffectDefinition*** descptr);
  12. // OLD rendering plugin api (will become obsolete soon)
  13. typedef void (*UnityPluginSetGraphicsDeviceFunc)(void* device, int deviceType, int eventType);
  14. typedef void (*UnityPluginRenderMarkerFunc)(int marker);
  15. // new rendering plugin api
  16. typedef void (*UnityPluginLoadFunc)(struct IUnityInterfaces* unityInterfaces);
  17. typedef void (*UnityPluginUnloadFunc)(void);
  18. // log handler function
  19. #ifdef __cplusplus
  20. typedef bool (*LogEntryHandler)(LogType logType, const char* log, va_list list);
  21. #endif
  22. //
  23. // these are functions referenced in trampoline and implemented in unity player lib
  24. //
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. // life cycle management
  29. void UnityInitRuntime(int argc, char* argv[]);
  30. void UnityInitApplicationNoGraphics(const char* appPathName);
  31. void UnityUnloadApplication(void);
  32. void UnityQuitApplication(int exitCode);
  33. void UnityInitApplicationGraphics(void);
  34. void UnityCleanup(void);
  35. void UnityLoadApplication(void);
  36. void UnityLoadApplicationFromSceneLessState(void);
  37. void UnitySetPlayerFocus(int focused); // send OnApplicationFocus() message to scripts
  38. void UnityLowMemory(void);
  39. void UnityPause(int pause);
  40. void UnitySuppressPauseMessage(void);
  41. int UnityIsPaused(void); // 0 if player is running, 1 if paused
  42. int UnityIsFocused(void); // 1 if player is focused, 0 if in the background
  43. void UnityWillPause(void); // send the message that app will pause
  44. void UnityWillResume(void); // send the message that app will resume
  45. void UnityDeliverUIEvents(void); // unity processing impacting UI will be called in there
  46. void UnityWaitForFrame();
  47. void UnityInputProcess(void); // no longer used, will be removed soon
  48. // player loop handling:
  49. // normal player loop
  50. void UnityPlayerLoopWithBackbuffer(UnityRenderBufferHandle color, UnityRenderBufferHandle depth);
  51. // just render, without actually running player loop (used for CAMetalDisplayLink callback when unity is paused)
  52. void UnityRenderWithoutPlayerLoopWithBackbuffer(UnityRenderBufferHandle color, UnityRenderBufferHandle depth);
  53. // batchmode player loop: no rendering to view (useful for background processing)
  54. void UnityBatchPlayerLoop(void);
  55. // checks if we need to quit or unload unity; needs to happen after we are fully done with the current frame
  56. void UnityCheckUnloadAndQuit(void);
  57. // these are deprecated (we do not call them anymore from the trampoline, but we keep them around for the possible plugins usage)
  58. void UnityPlayerLoop(void) __attribute__((deprecated("Use UnityPlayerLoopWithBackbuffer instead of UnityPlayerLoop")));
  59. void UnityRenderWithoutPlayerLoop(void) __attribute__((deprecated("Use UnityRenderWithoutPlayerLoopWithBackbuffer instead of UnityRenderWithoutPlayerLoop")));
  60. // rendering
  61. int UnityGetRenderingAPI(void);
  62. void UnityFinishRendering(void);
  63. void UnityDisplayLinkCallback(double /*machAbsoluteTimeSeconds*/); // argument is not used anymore
  64. // controling player internals
  65. // TODO: needs some cleanup
  66. void UnitySetAudioSessionActive(int active);
  67. void UnityGLInvalidateState(void);
  68. void UnityReloadResources(void);
  69. int UnityIsCaptureScreenshotRequested(void);
  70. void UnityCaptureScreenshot(void);
  71. void UnitySendMessage(const char* obj, const char* method, const char* msg);
  72. void UnityUpdateMuteState(int mute);
  73. int UnityShouldMuteOtherAudioSources(void);
  74. int UnityShouldPrepareForIOSRecording(void);
  75. int UnityIsAudioManagerAvailableAndEnabled(void);
  76. #ifdef __cplusplus
  77. void UnitySetLogEntryHandler(LogEntryHandler newHandler);
  78. #endif
  79. // plugins support
  80. // WARNING: old UnityRegisterRenderingPlugin will become obsolete soon
  81. void UnityRegisterRenderingPlugin(UnityPluginSetGraphicsDeviceFunc setDevice, UnityPluginRenderMarkerFunc renderMarker);
  82. void UnityRegisterRenderingPluginV5(UnityPluginLoadFunc loadPlugin, UnityPluginUnloadFunc unloadPlugin) __attribute__((deprecated("Renamed to UnityRegisterPlugin", "UnityRegisterPlugin")));
  83. void UnityRegisterPlugin(UnityPluginLoadFunc loadPlugin, UnityPluginUnloadFunc unloadPlugin);
  84. void UnityRegisterAudioPlugin(UnityPluginGetAudioEffectDefinitionsFunc getAudioEffectDefinitions);
  85. // resolution/orientation handling
  86. void UnityGetRenderingResolution(unsigned* w, unsigned* h);
  87. void UnityGetSystemResolution(unsigned* w, unsigned* h);
  88. void UnityRequestRenderingResolution(unsigned w, unsigned h);
  89. int UnityIsOrientationEnabled(unsigned /*ScreenOrientation*/ orientation);
  90. int UnityHasOrientationRequest(void);
  91. int UnityShouldAutorotate(void);
  92. int UnityAutorotationStatusChanged(void);
  93. int UnityShouldChangeAllowedOrientations(void);
  94. int UnityRequestedScreenOrientation(void); // returns ScreenOrientation
  95. void UnityOrientationRequestWasCommitted(void);
  96. int UnityReportResizeView(unsigned w, unsigned h, unsigned /*ScreenOrientation*/ contentOrientation); // returns ScreenOrientation
  97. void UnityReportSafeAreaChange(float x, float y, float w, float h);
  98. void UnityReportBackbufferChange(UnityRenderBufferHandle colorBB, UnityRenderBufferHandle depthBB);
  99. #if !PLATFORM_VISIONOS
  100. float UnityCalculateScalingFactorFromTargetDPI(UIScreen* screen);
  101. int UnityResolutionScalingFixedDPIFactorChanged(void);
  102. #endif
  103. void UnityReportDisplayCutouts(const float* x, const float* y, const float* width, const float* height, int count);
  104. // player settings
  105. int UnityDisableDepthAndStencilBuffers(void);
  106. int UnityUseAnimatedAutorotation(void);
  107. int UnityGetDesiredMSAASampleCount(int defaultSampleCount);
  108. int UnityGetSRGBRequested(void);
  109. int UnityGetWideColorRequested(void);
  110. void UnitySetEDRValues(float maxEDRValue, float currentEDRValue);
  111. void UnitySetHDRMode(int hdrMode);
  112. int UnityGetHDRModeRequested(void);
  113. int UnityGetShowActivityIndicatorOnLoading(void);
  114. int UnityGetAccelerometerFrequency(void);
  115. int UnityGetTargetFPS(void);
  116. int UnityGetUseCustomAppBackgroundBehavior(void);
  117. int UnityGetDeferSystemGesturesTopEdge(void);
  118. int UnityGetDeferSystemGesturesBottomEdge(void);
  119. int UnityGetDeferSystemGesturesLeftEdge(void);
  120. int UnityGetDeferSystemGesturesRightEdge(void);
  121. int UnityGetHideHomeButton(void);
  122. int UnityMetalFramebufferOnly(void);
  123. int UnityMetalMemorylessDepth(void);
  124. int UnityPreserveFramebufferAlpha(void);
  125. void UnitySetTargetFPS(int targetFPS);
  126. void UnitySetAbsoluteURL(const char* url);
  127. #ifdef __cplusplus
  128. bool UnityShouldUseMetalDisplayLink(void);
  129. #endif
  130. // native events
  131. void UnityInvalidateDisplayDataCache(void* screen);
  132. void UnityUpdateDisplayListCache(void** screens, int screenCount);
  133. // profiler
  134. void* UnityCreateProfilerCounter(const char*);
  135. void UnityDestroyProfilerCounter(void*);
  136. void UnityStartProfilerCounter(void*);
  137. void UnityEndProfilerCounter(void*);
  138. // sensors
  139. void UnitySensorsSetGyroRotationRate(int idx, float x, float y, float z);
  140. void UnitySensorsSetGyroRotationRateUnbiased(int idx, float x, float y, float z);
  141. void UnitySensorsSetGravity(int idx, float x, float y, float z);
  142. void UnitySensorsSetUserAcceleration(int idx, float x, float y, float z);
  143. void UnitySensorsSetAttitude(int idx, float x, float y, float z, float w);
  144. void UnityDidAccelerate(float x, float y, float z, double timestamp);
  145. void UnitySetJoystickPosition(int joyNum, int axis, float pos);
  146. int UnityStringToKey(const char *name);
  147. void UnitySetKeyState(int key, int /*bool*/ state);
  148. void UnitySetKeyboardKeyState(int key, int /*bool*/ state);
  149. void UnitySendKeyboardCommand(UIKeyCommand* command, int code);
  150. int UnityShouldAdjustPerformanceOnThermalStateChange();
  151. int UnityGetThermalStateSeriousFPS();
  152. int UnityGetThermalStateCriticalFPS();
  153. void UnityThermalStateChanged(int state);
  154. // UnityWebRequest handling
  155. void UnityReportWebRequestStatus(void* udata, int status);
  156. void UnityReportWebRequestNetworkError(void* udata, int status);
  157. void UnityReportWebRequestResponseHeader(void* udata, const char* headerName, const char* headerValue);
  158. void UnityReportWebRequestReceivedResponse(void* udata, unsigned expectedDataLength);
  159. void UnityReportWebRequestReceivedData(void* udata, const void* buffer, unsigned totalRead, unsigned expectedTotal);
  160. void UnityReportWebRequestFinishedLoadingData(void* udata);
  161. void UnityWebRequestRelease(void* udata);
  162. void UnityReportWebRequestSentData(void* udata, unsigned totalWritten, unsigned expectedTotal);
  163. int UnityReportWebRequestValidateCertificate(void* udata, const void* certificateData, unsigned certificateSize);
  164. unsigned long long UnityWebRequestResetUpload(void* udata);
  165. const void* UnityWebRequestGetUploadData(void* udata, unsigned* bufferSize);
  166. void UnityWebRequestConsumeUploadData(void* udata, unsigned consumedSize);
  167. // AVCapture
  168. void UnityReportAVCapturePermission(void* userData);
  169. void UnityDidCaptureVideoFrame(intptr_t tex, void* udata);
  170. // logging override
  171. #ifdef __cplusplus
  172. } // extern "C"
  173. #endif
  174. // touches processing
  175. #ifdef __cplusplus
  176. extern "C" {
  177. #endif
  178. void UnitySetViewTouchProcessing(UIView* view, int /*ViewTouchProcessing*/ processingPolicy);
  179. void UnityDropViewTouchProcessing(UIView* view);
  180. void UnitySendTouchesBegin(NSSet* touches, UIEvent* event);
  181. void UnitySendTouchesEnded(NSSet* touches, UIEvent* event);
  182. void UnitySendTouchesCancelled(NSSet* touches, UIEvent* event);
  183. void UnitySendTouchesMoved(NSSet* touches, UIEvent* event);
  184. void UnitySendTouchesUnfiltered(NSSet* touches, NSSet* allTouches);
  185. void UnityCancelTouches(void);
  186. void UnitySendScrollWheel(float deltaX, float deltaY);
  187. void UnitySendMousePosition(float x, float y);
  188. #ifdef __cplusplus
  189. } // extern "C"
  190. #endif
  191. //
  192. // these are functions referenced and implemented in trampoline
  193. //
  194. #ifdef __cplusplus
  195. extern "C" {
  196. #endif
  197. // UnityAppController.mm
  198. UIViewController* UnityGetGLViewController(void);
  199. UIView* UnityGetGLView(void);
  200. UnityView* UnityGetUnityView(void);
  201. UIWindow* UnityGetMainWindow(void);
  202. enum ScreenOrientation UnityCurrentOrientation(void);
  203. // Unity/DisplayManager.mm
  204. #if !PLATFORM_VISIONOS
  205. float UnityScreenScaleFactor(UIScreen* screen);
  206. #endif
  207. // Unity/DeviceSettings.mm
  208. int UnityDeviceHasCutout(void);
  209. #ifdef __cplusplus
  210. } // extern "C"
  211. #endif
  212. //
  213. // these are functions referenced in unity player lib and implemented in trampoline
  214. //
  215. #ifdef __cplusplus
  216. extern "C" {
  217. #endif
  218. // iPhone_Sensors.mm
  219. void UnityInitJoysticks(void);
  220. void UnityCoreMotionStart(void);
  221. void UnityCoreMotionStop(void);
  222. void UnityUpdateAccelerometerData(void);
  223. int UnityIsGyroEnabled(int idx);
  224. int UnityIsGyroAvailable(void);
  225. void UnityUpdateGyroData(void);
  226. void UnitySetGyroUpdateInterval(int idx, float interval);
  227. float UnityGetGyroUpdateInterval(int idx);
  228. void UnityUpdateJoystickData(void);
  229. NSArray* UnityGetJoystickNames(void);
  230. void UnityGetJoystickAxisName(int idx, int axis, char* buffer, int maxLen);
  231. void UnityGetNiceKeyname(int key, char* buffer, int maxLen);
  232. // UnityAppController+Rendering.mm
  233. void UnityGfxInitedCallback(void);
  234. void UnityPresentContextCallback();
  235. void UnityFramerateChangeCallback(int targetFPS);
  236. void UnitySelectRenderingAPI(void);
  237. int UnitySelectedRenderingAPI(void);
  238. int UnityIsBatchmode(void);
  239. int UnityShouldRunInBackground(void);
  240. NSBundle* UnityGetMetalBundle(void);
  241. MTLDeviceRef UnityGetMetalDevice(void);
  242. MTLCommandQueueRef UnityGetMetalCommandQueue(void);
  243. int UnityCommandQueueMaxCommandBufferCountMTL(void);
  244. // deprecated, soon to be removed
  245. MTLCommandQueueRef UnityGetMetalDrawableCommandQueue(void);
  246. UnityRenderBufferHandle UnityBackbufferColor(void);
  247. UnityRenderBufferHandle UnityBackbufferDepth(void);
  248. int UnityIsWideColorSupported(void);
  249. // UI/ActivityIndicator.mm
  250. void UnityStartActivityIndicator(void);
  251. void UnityStopActivityIndicator(void);
  252. // UI/Keyboard.mm
  253. void UnityKeyboard_Create(unsigned keyboardType, int autocorrection, int multiline, int secure, int alert, const char* text, const char* placeholder, int characterLimit);
  254. void UnityKeyboard_Show(void);
  255. void UnityKeyboard_Hide(void);
  256. void UnityKeyboard_GetRect(float* x, float* y, float* w, float* h);
  257. void UnityKeyboard_SetText(const char* text);
  258. NSString* UnityKeyboard_GetText(void);
  259. int UnityKeyboard_IsActive(void);
  260. int UnityKeyboard_Status(void);
  261. void UnityKeyboard_SetInputHidden(int hidden);
  262. int UnityKeyboard_IsInputHidden(void);
  263. void UnityKeyboard_SetCharacterLimit(unsigned characterLimit);
  264. int UnityKeyboard_CanGetSelection(void);
  265. void UnityKeyboard_GetSelection(int* location, int* range);
  266. int UnityKeyboard_CanSetSelection(void);
  267. void UnityKeyboard_SetSelection(int location, int range);
  268. // UI/UnityViewControllerBase.mm
  269. void UnityNotifyHideHomeButtonChange(void);
  270. void UnityNotifyDeferSystemGesturesChange(void);
  271. // Unity/AVCapture.mm
  272. int UnityGetAVCapturePermission(int captureTypes);
  273. void UnityRequestAVCapturePermission(int captureTypes, void* userData);
  274. // Unity/CameraCapture.mm
  275. void UnityEnumVideoCaptureDevices(void* udata, void(*callback)(void* udata, const char* name, int frontFacing, int autoFocusPointSupported, int kind, const int* resolutions, int resCount));
  276. void* UnityInitCameraCapture(int device, int w, int h, int fps, int isDepth, void* udata);
  277. void UnityStartCameraCapture(void* capture);
  278. void UnityPauseCameraCapture(void* capture);
  279. void UnityStopCameraCapture(void* capture);
  280. void UnityCameraCaptureExtents(void* capture, int* w, int* h);
  281. void UnityCameraCaptureReadToMemory(void* capture, void* dst, int w, int h);
  282. int UnityCameraCaptureVideoRotationDeg(void* capture);
  283. int UnityCameraCaptureVerticallyMirrored(void* capture);
  284. int UnityCameraCaptureSetAutoFocusPoint(void* capture, float x, float y);
  285. // Unity/DeviceSettings.mm
  286. const char* UnityDeviceUniqueIdentifier(void);
  287. const char* UnityVendorIdentifier(void);
  288. const char* UnityAdIdentifier(void);
  289. int UnityAdTrackingEnabled(void);
  290. int UnityGetLowPowerModeEnabled(void);
  291. int UnityGetWantsSoftwareDimming(void);
  292. void UnitySetWantsSoftwareDimming(int enabled);
  293. int UnityGetIosAppOnMac(void);
  294. const char* UnityDeviceName(void);
  295. const char* UnitySystemName(void);
  296. const char* UnitySystemVersion(void);
  297. const char* UnityDeviceModel(void);
  298. int UnityDeviceCPUCount(void);
  299. int UnityGetPhysicalMemory(void);
  300. int UnityDeviceGeneration(void);
  301. float UnityDeviceDPI(void);
  302. const char* UnitySystemLanguage(void);
  303. int UnityDeviceSupportsUpsideDown(void);
  304. // Unity/DisplayManager.mm
  305. void UnityActivateScreenForRendering(void* nativeDisplay);
  306. void UnityStartFrameRendering(void);
  307. void UnityDestroyUnityRenderSurfaces(void);
  308. int UnityMainScreenRefreshRate(void);
  309. void UnitySetBrightness(float brightness);
  310. float UnityGetBrightness(void);
  311. // Unity/Filesystem.mm
  312. const char* UnityDataBundleDir(void);
  313. void UnitySetDataBundleDirWithBundleId(const char * bundleId);
  314. const char* UnityDocumentsDir(void);
  315. const char* UnityLibraryDir(void);
  316. const char* UnityCachesDir(void);
  317. int UnityUpdateNoBackupFlag(const char* path, int setFlag); // Returns 1 if successful, otherwise 0
  318. // Unity/FullScreenVideoPlayer.mm
  319. int UnityIsFullScreenPlaying(void);
  320. void TryResumeFullScreenVideo(void);
  321. //Apple TV Remote
  322. int UnityGetAppleTVRemoteAllowExitToMenu(void);
  323. void UnitySetAppleTVRemoteAllowExitToMenu(int val);
  324. int UnityGetAppleTVRemoteAllowRotation(void);
  325. void UnitySetAppleTVRemoteAllowRotation(int val);
  326. int UnityGetAppleTVRemoteReportAbsoluteDpadValues(void);
  327. void UnitySetAppleTVRemoteReportAbsoluteDpadValues(int val);
  328. int UnityGetAppleTVRemoteTouchesEnabled(void);
  329. void UnitySetAppleTVRemoteTouchesEnabled(int val);
  330. // Unity/UnityReplayKit.mm
  331. void UnityShouldCreateReplayKitOverlay(void);
  332. // Runtime analytics
  333. void UnitySendEmbeddedLaunchEvent(int launchType); // Tracks events when application is launched from native host app (Unity as a Library)
  334. #ifdef __cplusplus
  335. } // extern "C"
  336. #endif
  337. #ifdef __OBJC__
  338. // This is basically a wrapper for [NSString UTF8String] with additional strdup.
  339. //
  340. // Apparently multiple calls on UTF8String will leak memory (NSData objects) that are collected
  341. // only when @autoreleasepool is exited. This function serves as documentation for this and as a
  342. // handy wrapper.
  343. inline char* AllocCString(NSString* value)
  344. {
  345. if (value == nil)
  346. return 0;
  347. const char* str = [value UTF8String];
  348. return str ? strdup(str) : 0;
  349. }
  350. #endif