xcode 在 Unity 中创建 iOS 插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9712807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:39:11  来源:igfitidea点击:

Creating iOS Plugin in Unity

c#iosxcodeunity3d

提问by Henry F

I'm very new to Unity3d 3.5, and I've been reading over this manual for how to create iOS plugins in Unity (I'm using the pro version): http://unity3d.com/support/documentation/Manual/PluginsForIOS.html

我是 Unity3d 3.5 的新手,我一直在阅读本手册以了解如何在 Unity 中创建 iOS 插件(我使用的是专业版):http: //unity3d.com/support/documentation/Manual/ PluginsForIOS.html

I'm under the impression that there is a script that will scan Plugins/iOS in Unity's project folder, and symlink everything in there into Xcode. The manual pretty much just scims over how to do it, and it is not very helpful for a beginner. I was wondering if there is just a single file floating around that will accomplish this, or if it is different for every app? Any help is much appreciated, thanks in advance!

我的印象是有一个脚本可以扫描 Unity 项目文件夹中的插件/iOS,并将其中的所有内容符号链接到 Xcode。该手册几乎只是简要介绍了如何做,对初学者来说不是很有帮助。我想知道是否只有一个文件可以实现这一点,还是每个应用程序都不同?非常感谢任何帮助,提前致谢!

Also, does anyone know if there is a way to have Unity include the .h files and plist's in the Plugins/iOS folder? That sounds like a much easier process.

另外,有没有人知道是否有办法让 Unity 在 Plugins/iOS 文件夹中包含 .h 文件和 plist?这听起来像是一个简单得多的过程。

回答by Ravi D

And also make sure that you define all your C# methods are of the format :

还要确保您定义的所有 C# 方法都具有以下格式:

[DllImport ("__Internal")] private static extern float FooPluginFunction ();

[DllImport ("__Internal")] private static extern float FooPluginFunction ();

and your c functions should be wrapped inside

并且你的 c 函数应该被包裹在里面

extern "C" {
  float FooPluginFunction ();
 } 

If they are not, your app will break

如果不是,您的应用程序将崩溃

回答by ThomasW

I just tried a quick test with Unity 3.5 and the feature to automatically include the native code in the Assets/Plugins/iOSfolder appears to work, although it is limited. As the document mentions, subfolders are not supported. This feature works when you create your Xcode project by using the Unity "Build" command, no script is required.

我刚刚尝试使用 Unity 3.5 进行快速测试,自动将本机代码包含在Assets/Plugins/iOS文件夹中的功能似乎可以工作,尽管它是有限的。正如文档所述,不支持子文件夹。当您使用 Unity“Build”命令创建 Xcode 项目时,此功能有效,不需要脚本。

There is a sample project linked to on that page, but it is not set up properly. The native code needs to be moved from Assets/Codeto Assets/Plugins/iOS.

该页面上有一个链接到的示例项目,但未正确设置。本机代码需要从 移动Assets/CodeAssets/Plugins/iOS

回答by Calvin

If you want to copy or modify the info.plist file you can do that using the new [PostProcessBuild] attribute.

如果你想复制或修改 info.plist 文件,你可以使用新的 [PostProcessBuild] 属性来完成。

http://docs.unity3d.com/Documentation/ScriptReference/PostProcessBuildAttribute.html

http://docs.unity3d.com/Documentation/ScriptReference/PostProcessBuildAttribute.html

You can use that to copy an info.plist from a known location to your build directory, overwriting the existing one, or you can use something like PlistCSto modify the existing info.plist.

您可以使用它来将 info.plist 从已知位置复制到您的构建目录,覆盖现有的,或者您可以使用类似PlistCS 的东西来修改现有的 info.plist。