UnityInterface.h 16 KB

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