이 페이지는 iOS 플랫폼용 네이티브 코드 플러그인에 대해 설명합니다.
다음과 같이 외부 메서드를 C# 파일에 지정해야 합니다.
[DllImport ("__Internal")]
private static extern float FooPluginFunction();
iOS 빌드 타겟으로 에디터를 설정.
생성된 Xcode 프로젝트의 ‘클래스’ 폴더에 네이티브 코드 소스 파일을 추가하시기 바랍니다(이 폴더에는 프로젝트가 업데이트될 때 덮어쓰지 않지만 네이티브 코드를 백업하는 것이 좋습니다).
C++ (.cpp) 또는 Objective-C++ (.mm)를 사용하여 플러그인을 실행할 경우 네임 맹글링(name mangling) 문제를 피하기 위해 함수를 C링크에 선언해야 합니다.
extern "C" {
float FooPluginFunction();
}
C 또는 Objective-C로 작성된 플러그인은 네임 맹글링을 사용하지 않기 때문에 필요하지 않습니다.
iOS 네이티브 플러그인은 실제 디바이스 배포 중에만 호출할 수 있기 때문에 모든 네이티브 플러그인은 추가 C# 코드 레이어에서 래핑하는 것이 좋습니다. 이 코드는 Application.platform을 확인하고 해당 앱이 디바이스에서 실행 중인 경우에만 네이티브 메서드를 호출합니다. 또한 에디터에서 앱이 실행될 경우에만 더미 값을 반환할 수 있습니다. Bonjour 브라우저의 샘플 애플리케이션에서 예시를 참조하시기 바랍니다.
Unity iOS는 UnitySendMessage 를 통해 네이티브에서 관리 콜백 기능을 제한적으로 지원합니다.
UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");
함수에는 세 개의 파라미터인 타겟 게임 오브젝트의 이름, 해당 오브젝트를 호출할 스크립트 메서드, 그리고 호출된 메서드에 전달할 메시지 문자열이 있습니다.
알려진 제한 사항.
function MethodName(message:string)
Unity iOS 는 자동화된 플러그인 통합을 제한된 방식으로 지원합니다. Assets\Plugins\iOS 폴더에 위치한 .a,.m,.mm,.c,.cpp 확장자를 가진 모든 파일은 생성된 Xcode 프로젝트에 자동으로 병합됩니다. 이 병합은 Assets\Plugins\iOS 폴더에 위치한 파일을 최종 폴더에 심링크하는 것으로 이루어지며, 이는 일부 워크플로에 영향을 미칠 수 있습니다. .h 파일은 Xcode 프로젝트 트리에는 포함되지 않지만 목표 파일 시스템에 나타나기 때문에 .m/.mm/.c/.cpp 파일의 컴파일이 가능합니다.
참고: 하위 폴더는 현재 지원되지 않습니다.
네이티브 코드 플러그인의 사용에 대한 간단한 예시는 여기에서 찾을 수 있습니다.
이 샘플은 objective-C 코드가 Unity의 iOS 애플리케이션에서 어떻게 시작되는지 보여줍니다. 이 애플리케이션은 굉장히 단순한 Bonjour 클라이언트를 구현합니다. 이 애플리케이션은 Unity iOS 프로젝트(Plugins\Bonjour.cs 는 네이티브 코드의 C# 인터페이스이며, BonjourTest.cs 는 애플리케이션 로직을 구현하는 스크립트입니다)와 네이티브 코드(Assets\Code)를 포함합니다. 네이티브 코드는 빌드된 Xcode 프로젝트에 추가돼야 합니다.
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.