我正在嘗試撰寫一個本機插件來訪問一些尚未由 Social.localUser 統一 API 公開的 GameKit 功能(即本地用戶受多人限制的事實)。
我已經撰寫了一個GameKitWrapper.mm檔案,我在其中宣告了一個函式及其對應的 Csharp。在 IOS 上一切正常(找到了插件并且方法回傳了正確的值),但是在 appleTV 和 macOSX 上找不到 .mm 檔案。
據我了解,在 macOSX 和 appleTv 上,我應該動態鏈接插件,而不是使用代表靜態鏈接庫的“__Internal”關鍵字。但是,即使我在為 appleTV 或 macOSX 構建時將 更改[DllImport("__Internal")]為我的插件的名稱(我嘗試過DllImport["GameKitNativeWrapper"]并且DllImport["GameKitNativeWrapper.mm"]),它也不起作用,并且出現此錯誤:
DllNotFoundException: Unable to load DLL 'GameKitNativeWrapper': The specified module could not be found.
正如我在檔案中閱讀的那樣,它應該可以作業。我的設定中是否缺少任何內容以使插件在 appleTV 和 macOSX 上運行?
我應該將.mm檔案編譯成一個包嗎?以便在 AppleTV 和/或 Mac 上運行應用程式時可以動態鏈接它?
下面是相關的 C# 源檔案GameKitHelper.cs
namespace Plugins.GameKit
{
using System.Runtime.InteropServices;
public static class GameKitHelper
{
[DllImport("__Internal")]
private static extern bool IOSIsMultiplayerGamingRestricted();
public static bool IsMultiplayerRestricted()
{
if (DeviceHelper.IsAppleDevice())
{
return IOSIsMultiplayerGamingRestricted();
}
else
{
return false;
}
}
}
}
這是相關的 GameKitNativeWrapper.mm 檔案:
#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>
#include <Availability.h>
#include <TargetConditionals.h>
@interface GameKitNativeWrapper: NSObject
{
}
@end
@implementation GameKitNativeWrapper
static GameKitNativeWrapper *_sharedInstance;
(GameKitNativeWrapper*) sharedInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSLog(@"Creating GameKitNativeWrapper shared instance.");
_sharedInstance = [[GameKitNativeWrapper alloc] init];
});
return _sharedInstance;
}
-(id)init
{
self = [super init];
if (self)
[self initHelper];
return self;
}
-(void)initHelper
{
NSLog(@"initHelper called");
}
-(bool)isMultiplayerGamingRestricted
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
return localPlayer.isMultiplayerGamingRestricted;
}
@end
extern "C"
{
bool IOSIsMultiplayerGamingRestricted()
{
return [[GameKitNativeWrapper sharedInstance] isMultiplayerGamingRestricted];
}
}

uj5u.com熱心網友回復:
如果你想使用你的 Objective-C (.mm) 來實作統一的Mac OS 插件,你應該將它部署為一個包。
要使用 XCode 創建捆綁專案:
打開 XCode。選擇File > New > Project > macOS > Framework & Library > Bundle。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/358542.html
標籤:目标-c 统一3d dll导入 unity3d-native-plugins
