unity pro 提供了对objective-c的接口。要在unity项目中调用xcode的函数,首先在object-c代码中用C写好需要实现的方法(object-c要.mm后缀名)。拷贝文件到unity项目Plugins文件的iOS文件里。
然后
在unity中写C#代码调用objectC。
unity3.5.2和xcode4.3.2环境
ObjectC:
------------------------------------------------------------------------------------------------------
extern "C"
{
void callMe()
{
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"Unity Call"
message:@"Unity To Objecttive-c"
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Close",nil)
otherButtonTitles:nil];
[
alerView show
];
}
}
-------------------------------------------------------------------------------------------------------
C#
-------------------------------------------------------------------------------------------------------
[DllImport("__Internal")]
private static extern void callMe();
void OnGUI()
{
if(GUI.Button(new Rect(100, 100, 100, 50), "Call ObjectC Function"))
{
callMe();
}
}
--------------------------------------------------------------------------------------------------------
使用[DllImport("__Internal")]需要导人相应的包
using System.Runtime.InteropServices;