---
title: 네이티브 플러그인 API 소개
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ko-kr/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/introduction
latest_url: https://docs.unity.com/ko-kr/engine/7000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/introduction.md
generated_at: 2026-11-19T17:21:17.104Z
locale: ko-kr
---

# 네이티브 플러그인 API 소개

> 네이티브 플러그인 API 파일을 찾아 네이티브 플러그인으로 임포트합니다.

Unity의 [네이티브 플러그인](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native.md)은 특정 이벤트가 발생할 때 콜백을 수신할 수 있습니다. 이를 사용하여 Unity 멀티스레드 렌더링과 함께 사용할 수 있도록 플러그인에 로우레벨 렌더링을 구현할 수 있습니다.

## 인터페이스 레지스트리##interface-registry

주요 Unity 이벤트를 처리하려면 플러그인이 `UnityPluginLoad` 및 `UnityPluginUnload` 함수를 익스포트해야 합니다. IUnityInterfaces를 사용하면 플러그인이 플러그인 API의 `IUnityInterface.h`에서 찾을 수 있는 다음 기능에 액세스할 수 있습니다.

```lang-cpp
#include "IUnityInterface.h"
#include "IUnityGraphics.h"
// Unity plugin load event
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
    UnityPluginLoad(IUnityInterfaces* unityInterfaces)
{
    IUnityGraphics* graphics = unityInterfaces->Get<IUnityGraphics>();
}
```

## 그래픽스 디바이스에 대한 액세스##access-to-the-graphics-device

`IUnityGraphics.h`에서 찾을 수 있는 `IUnityGraphics` 인터페이스를 사용하여 일반 그래픽스 디바이스 기능에 플러그인 액세스를 제공합니다. 다음 스크립트는 `IUnityGraphics` 인터페이스를 사용하여 콜백을 등록하는 방법을 보여 줍니다.

```lang-cpp
#include "IUnityInterface.h"
#include "IUnityGraphics.h"
    
static IUnityInterfaces* s_UnityInterfaces = NULL;
static IUnityGraphics* s_Graphics = NULL;
static UnityGfxRenderer s_RendererType = kUnityGfxRendererNull;
    
// Unity plugin load event
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
    UnityPluginLoad(IUnityInterfaces* unityInterfaces)
{
    s_UnityInterfaces = unityInterfaces;
    s_Graphics = unityInterfaces->Get<IUnityGraphics>();
        
    s_Graphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
        
    // Run OnGraphicsDeviceEvent(initialize) manually on plugin load
    // to not miss the event in case the graphics device is already initialized
    OnGraphicsDeviceEvent(kUnityGfxDeviceEventInitialize);
}
    
// Unity plugin unload event
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
    UnityPluginUnload()
{
    s_Graphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
}
    
static void UNITY_INTERFACE_API
    OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType)
{
    switch (eventType)
    {
        case kUnityGfxDeviceEventInitialize:
        {
            s_RendererType = s_Graphics->GetRenderer();
            //TODO: user initialization code on graphics device initialization. 
            예를 들어 D3D11 리소스 생성입니다.
            중지;
        }
        case kUnityGfxDeviceEventShutdown:
        {
            s_RendererType = kUnityGfxRendererNull;
            //TODO: user graphics API code to call on graphics device shutdown.
            중지;
        }
        case kUnityGfxDeviceEventBeforeReset:
        {
            //TODO: user graphics API code to call before graphics device reset.
            중지;
        }
        case kUnityGfxDeviceEventAfterReset:
        {
            //TODO: user graphics API code to call after graphics device reset.
            중지;
        }
    };
}
```

## 렌더링 스레드의 플러그인 콜백##plug-in-callbacks-on-the-rendering-thread

플랫폼과 사용 가능한 CPU 수에 따라 멀티스레딩을 사용하여 Unity 렌더링할 수 있습니다.

> **Note:**
>
> 멀티스레드 렌더링을 사용할 때 렌더링 API 명령은 MonoBehaviour 스크립트를 실행하는 스레드와 완전히 분리된 스레드에서 발생합니다. 메인 스레드 렌더 스레드 간의 커뮤니케이션은 메인 스레드 렌더 스레드에 푸시한 작업량에 따라 플러그인이 즉시 렌더링을 시작하지 않을 수 있음을 의미합니다.

플러그인에서 렌더링하려면 관리되는 플러그인 스크립트에서 [GL.IssuePluginEvent](/engine/6000.0/script-reference/unityengine/gl/issuepluginevent.md)를 호출합니다. 그러면 아래 코드 예시와 같이 Unity 렌더링 파이프라인이 렌더 스레드에서 네이티브 함수를 호출합니다. 예를 들어 카메라의 OnPostRender 함수에서 GL.IssuePluginEvent를 호출하면 카메라가 렌더링을 완료한 직후 플러그인 콜백이 호출됩니다.

네이티브 플러그인 코드:

```lang-cpp
// Plugin function to handle a specific rendering event
static void Unity_INTERFACE_API OnRenderEvent(int eventID)
{
    // User rendering code
}
    
// Freely defined function to pass a callback to plugin-specific scripts
extern "C" UnityRenderingEvent Unity_INTERFACE_EXPORT Unity_INTERFACE_API
    GetRenderEventFunc()
{
    return OnRenderEvent;
}
```

관리되는 플러그인 코드:

```lang-cs
#if UNITY_IPHONE && !UNITY_EDITOR
[DllImport("__Internal")]
#else
[DllImport("RenderingPlugin")]
#endif
private static extern IntPtr GetRenderEventFunc();
    
// Queue a specific callback to be called on the render thread
GL.IssuePluginEvent(GetRenderEventFunc(), 1);
```

`UnityRenderingEvent` 콜백의 서명은 [네이티브 렌더링 플러그인 샘플의 IUnityGraphics.h에 있습니다](https://github.com/Unity-Technologies/NativeRenderingPlugin/tree/master/PluginSource/source/Unity).

## OpenGL 그래픽스 API 사용하는 플러그인##plug-in-using-the-opengl-graphics-api

OpenGL 오브젝트에는 다음의 두 가지 타입이 있습니다.

* 텍스처, 버퍼, 렌더 버퍼, 샘플러, 쿼리, 셰이더 및 프로그램 객체와 같이 OpenGL 컨텍스트 간에 공유되는 **오브젝트**입니다.
* 버텍스 배열, 프레임버퍼, 프로그램 파이프라인, 트랜스폼 피드백, 동기화 객체와 같은 **OpenGL당 컨텍스트 오브젝트**

Unity 여러 OpenGL 컨텍스트를 사용합니다. Unity 에디터와 플레이어를 초기화하고 닫을 때 마스터 컨텍스트를 사용하지만, 렌더링 시 전용 컨텍스트를 사용합니다. 즉, `kUnityGfxDeviceEventInitialize` 및 `kUnityGfxDeviceEventShutdown` 이벤트 중에 컨텍스트별 오브젝트를 생성할 수 없습니다.

## Vulkan 그래픽스 API 사용한 플러그인##plug-in-using-the-vulkan-graphics-api

Vulkan 그래픽스 API를 사용하는 네이티브 그래픽스 플러그인을 개발할 때 [확인 레이어](/engine/6000.0/manual/unity-editor/command-line-arguments/editor.md#debugging)를 통해 디버깅을 활성화할 수 있습니다. 확인 레이어를 활성화하려면 플러그인 실행 중에 크래시를 방지하려면 다음을 수행해야 합니다.

* 네이티브 그래픽스 플러그인과 동일한 디렉토리에 확인 레이어 플러그인을 추가합니다.
* [플러그인 인스펙터 창](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/plug-in-inspector.md)에서 네이티브 및 Vulkan 확인 계층 플러그인 모두에 대해 동일한 **Load on Startup** 설정을 구성합니다.

## 추가 리소스##additional-resources

* [로우레벨 네이티브 플러그인 렌더링 확장 기능](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-rendering-extensions.md)
* [로우레벨 네이티브 플러그인 셰이더 컴파일러 액세스](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-shader-compiler-access.md)
* [로우레벨 네이티브 플러그인 메모리 관리자 API](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-memory-manager-api.md)
* [로우레벨 네이티브 플러그인 메모리 관리자 API 레퍼런스](/engine/6000.0/manual/scripting/compilation-and-code-reload/plug-ins/native-plugin-interface/low-level-native-plugin-memory-manager-api-reference.md)
* [Android에서 Vulkan 확인 레이어](https://developer.android.com/ndk/guides/graphics/validation-layer)
