Unity native plugin to capture the macOS desktop as Texture2D
mcDesktopCapture2.mp4
- Download mcDesktopCapture.unitypakcage from Releases and install it in your project.
- To allow monitoring of keyboard input in the background, you need to add Unity to Privacy Settings.
- Open
System Preferences>Security & Privacy>Privacy>Screen Recordingand addUnity.app.
(AndUnity Hub.appif you use)
| mcDesktopCapture | mcDesktopCapture2 | |
|---|---|---|
| Unity | Unity 2021.X Unity 2022.X Unity 2022.2+ (Apple Silicon) |
Unity 2021.X Unity 2022.X Unity 2022.2+ (Apple Silicon) |
| Platform | macOS 12+ (Apple Silicon and Intel) | macOS 12.3+ (Apple Silicon and Intel) |
| Technology | Quartz Display Services | ScreenCaptureKit |
| Capturing | Entire Display | Each windows |
- Support macOS 12+
- Based on Quartz Display Services
- This function only supports capturing the entire display.
var list = DesktopCapture.DisplayList;
DesktopCapture.StartCapture(list[0].id);var texture = DesktopCapture.GetTexture2D();
if (texture == null) return;
Renderer m_Renderer = GetComponent<Renderer>();
m_Renderer.material.SetTexture("_MainTex", texture);DesktopCapture.StopCapture();- Support macOS 12.3+
- Based on ScreenCaptureKit
- This feature is able to capture each window.
DesktopCapture2.Init();
var list = DesktopCapture2.WindowList;
var window = list[0];
DesktopCapture2.StartCaptureWithWindowID(window.windowID, window.frame.width, window.frame.height, true);var texture = DesktopCapture2.GetTexture2D();
if (texture == null) return;
Renderer m_Renderer = GetComponent<Renderer>();
m_Renderer.material.SetTexture("_MainTex", texture);DesktopCapture2.StopCapture();
DesktopCapture2.Destroy();