Version: 2020.2
플러그인 인스펙터
네이티브 플러그인

관리되는 플러그인

Managed plug-ins are managed .NET assemblies that you create with tools like Visual Studio. They contain only .NET code which means that they can’t access any features that .NET libraries do not support. However, the standard .NET tools that Unity uses to compile scripts can access the managed code. Therefore, there isn’t a lot of difference in usage between managed plug-in code and Unity script code, except that plug-ins are compiled outside of Unity and so the source might not be available.

Usually, Unity keeps scripts in a Project as source files and compiles them whenever the source changes. However, you can use an external compiler to compile a script to a dynamically linked library (DLL). You can then add the .dll file to the Project and attach the classes it contains to GameObjects just like normal scripts. A compiled DLL is known as a managed plug-in in Unity.

It’s generally much easier to work with scripts than DLLs in Unity. However, you might want to use compilers in your code that Unity doesn’t support, or add third party Mono code in a .dll file, or you might want to supply Unity code without the source. Creating and adding a .dll file to your Unity Project is the easiest way to get around these limitations.

Creating a managed plug-in

To create a managed plug-in, you need to create a DLL, which you need a suitable compiler for. Not all compilers that produce .NET code are guaranteed to work with Unity, so you should test the compiler with some available code before doing significant work with it. If the DLL contains no code that depends on the Unity API then you can use the appropriate compiler options to compile it to a .dll file.

If you do want to use the Unity API then you need to make Unity’s own DLLs available to the compiler. On macOS, the DLLs are contained in the application bundle. To see them, find the file on your computer (Applications/Unity/Hub/Editor/[Version Number]/ and then right click on and select Show Package Contents.

On macOS the path to the Unity DLLs are:


On Windows the path to the Unity DLLs are:

C:\Program Files\Unity\Editor\Data\Managed\UnityEngine

The UnityEngine folder contains the .dll files for a number of modules that you can reference to get to the specific namespace you require. Additionally, some namepsaces require a reference to a compiled library from a Unity Project (for instance, UnityEngine.UI), which is located in the project folder’s directory:


The exact options for compiling the DLL will vary depending on the compiler you use. As an example, the command line for the Mono C# compiler, mcs, might look like this on macOS:

mcs -r:/Applications/Unity/ -target:library ClassesForDLL.cs 

In this example,, the -r option specifies a path to a library to include in the build; in this case the UnityEngine.UIModule library. The -target option specifies which type of build is required; the word “library” is signifies a DLL build. Finally, the name of the source file to compile is ClassesForDLL.cs. The compiler assumes that this file is in the current working folder, but you can use a full path to specify the file if necessary. The resulting .dll file appears in the same folder as the source file.

Using the managed plug-in

Once you’ve compiled the DLL, you can drag the .dll file into the Unity Project like any other Asset. The managed plug-in has a foldout triangle which you can use to reveal the separate classes inside the library. You can drag classes that derive from MonoBehaviour onto Game Objects like ordinary scripts. You can use non-MonoBehaviour classes directly from other scripts in the usual way.

폴드아웃 DLL에 클래스 이름이 표시되어있습니다
폴드아웃 DLL에 클래스 이름이 표시되어있습니다

Visual Studio에 대한 단계별 가이드

이 섹션에서는 간단한 DLL 예제를 빌드하여 Visual Studio와 통합하는 방법을 설명합니다. 또한 DLL 디버깅 세션을 준비하는 방법도 살펴봅니다.

프로젝트(Project) 설정

Open Visual Studio and create a new project. Select File > New > Project and then choose Visual C# > Class Library.

Complete the following information for the new library:

  • Name is the namespace (for this example use DLLTest as the name).
  • Location은 프로젝트의 부모 폴더입니다.
  • Solution name은 프로젝트의 폴더입니다.

Next, add references to the Unity DLLs. In Visual Studio, open the contextual menu for References in the Solution Explorer and select Add Reference. Then, select Browse > Select File.

At this stage, select the required .dll file, located in the UnityEngine folder.


이 예제에서는 솔루션 브라우저에서 클래스 이름을 MyUtilities로 바꾼 후 다음으로 클래스 이름의 코드를 대체합니다.

using System;   
using UnityEngine;

namespace DLLTest {

    public class MyUtilities {
        public int c;

        public void AddValues(int a, int b) {
            c = a + b;  
        public static int GenerateRandom(int min, int max) {
            System.Random rand = new System.Random();
            return rand.Next(min, max);

그리고 프로젝트를 빌드해 디버그 심볼과 함께 DLL 파일을 생성합니다.

Unity에서 DLL 사용

Create a new Project in Unity and copy the built file <project folder>/bin/Debug/DLLTest.dll into the Assets folder. Then, create a C# script called Test in Assets, and replace its contents with the following code:

using UnityEngine;
using System.Collections;
using DLLTest;

public class Test : MonoBehaviour {

     void Start () {
        MyUtilities utils = new MyUtilities();
        utils.AddValues(2, 3);
        print("2 + 3 = " + utils.c);
     void Update () {
        print(MyUtilities.GenerateRandom(0, 100));

Attach this script to a GameObject in the Scene and press Play, and Unity displays the output of the code from the DLL in the Console window.

‘안전하지 않은’ C# 코드 컴파일

To enable support for compiling unsafe C# code go to Edit > Project Settings > Player. Expand the Other Settings panel and enable the Allow Unsafe Code checkbox.

플러그인 인스펙터
네이티브 플러그인