2011-11-11 35 views
2

我试图写我的第一个统一脚本。这是位于在资产/插件文件名为TestPlugin.cs代码:Unity脚本armv7错误

using UnityEngine; 
using System.Runtime.InteropServices; 

public class TestPlugin : MonoBehaviour 
{ 
    [DllImport ("__Internal")] 
    private static extern int getString(); 

    public static void Awake() { 
     print (getString()); 
    } 
} 

这是两个文件,我导入生成的Xcode项目的classes文件夹中的代码:

TestPlugin .H:

#import <Foundation/Foundation.h> 

@interface TestPlugin : NSObject 

-(int)getString; 

@end 

TestPlugin.m:

#import "TestPlugin.h" 

@implementation TestPlugin 

- (id)init 
{ 
    self = [super init]; 
    if (self) { 
     // Initialization code here. 
    } 

    return self; 
} 

- (int)getString 
{ 
    return 7; 
} 

@end 

最后,这是位于Asset文件夹内的JavaScript文件。

TestPluginTest.js:

function Update() 
{ 
TestPlugin.Awake(); 
} 

而且,请注意,我并不期待这一切的工作,只是在这一点上编译(虽然额外的意见和建议,欢迎)

试图建立到iPhone(实际设备),当我在Xcode得到的错误是这样的:

用于建筑的ARMv7未定义的符号:“_getString”,从引用 : 个RegisterMonoModules()在RegisterMonoModules.o LD:符号(多个)未找到架构的ARMv7 collect2:LD返回1退出状态

“_getString”,从引用:在RegisterMonoModules.o

RegisterMonoModules()

LD:符号(S)未找到的ARMv7架构

collect2:LD返回1个退出状态

我葡萄汁PED!提前致谢!

回答

1

我认为问题在于Obj-C接口,因为链接器不知道如何处理签名。当我连接一个自写的库我设计的界面只包含纯C代码:

interface.h

#ifdef __cplusplus 
    extern "C" { 
#endif  
    int getString();   
#ifdef __cplusplus 
    } 
#endif 

interface.c:

int getString() { 
    // do something 
} 

也许有用的博客文章:

iPhone & Unity3D: Integrating 3rd Party Static Libraries in Unity3D Generated XCode Projects

Unity Native Plugins: OS X

Clever Martian's Blog - An Experiment with iPhone Native UI and Unity 3 Pro

+0

所以问题是它写在目标c? – SirYakalot

+0

这实际上解决了这个问题,但问题是我实际上需要在目标C中编写接口。这是不是推荐? – SirYakalot

+0

Unity根据http://unity3d.com/support/documentation/Manual/Plugins.html说不要。不要误解我的意思:你当然可以在Obj-C中编写你的插件代码,但是你需要一个包装器接口纯C用于C#/ JS调用插件。我的图书馆有50多个班,但有一个精简的C界面。 – Kay