IL2CPP(Intermediate Language To C++)를 사용한 macOS 애플리케이션용 플러그인 사용에 대해 설명합니다.
IL2CPP는 완전하게 지원되는 스크립팅 백엔드로, macOS Player용 프로젝트를 빌드할 때 Mono 대신 사용할 수 있습니다.
IL2CPP를 사용하여 프로젝트를 빌드할 때 Unity는 스크립트와 어셈블리의 IL(Intermediate Language) 코드를 C++ 코드로 변환한 후에 네이티브 바이너리를 생성합니다.자세한 내용은 IL2CPP를 참조하십시오.
IL2CPP 스크립팅 백엔드를 사용할 때 C++(.cpp) 코드 파일을 Unity 프로젝트에 직접 추가할 수 있습니다.이 C++ 파일은 인스펙터 내에서 플러그인 역할을 합니다.macOS Player와 호환되도록 C++ 파일을 설정하면 Unity는 해당 파일을 관리되는 어셈블리에서 생성되는 C++ 코드와 함께 컴파일합니다.플러그인 설정에 대한 자세한 내용은 플러그인 임포트와 설정을 참조하십시오.
생성된 C++ 코드는 함수를 서로 연결하므로 별도의 동적 링크 라이브러리(DLL)가 필요하지 않습니다.DLL 이름을 사용하는 대신 "__Internal"
키보드를 사용하여 C++ 링커가 런타임 시점에 함수를 로드하지 않고 함수를 확인하도록 합니다.예시:
[DllImport("__Internal")]
private static extern int
CountLettersInString([MarshalAs(UnmanagedType.LPWStr)]string str);
다음과 같이 NativeFunctions.cpp에서 이러한 종류의 함수를 정의할 수 있습니다.
extern "C" __declspec(dllexport) int __stdcall CountLettersInString(wchar_t* str)
{
int length = 0;
while (*str++ != nullptr)
length++;
return length;
}
링커가 함수 호출을 확인할 때 관리되는 쪽의 함수 선언에 있는 모든 오류는 런타임 오류가 아니라 링커 오류가 됩니다.즉, 런타임 중에 함수를 C#에서 직접 호출하여 동적 로딩을 수행할 필요가 없습니다.이렇게 하면 P/Invoke
호출의 성능 오버헤드가 감소합니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.