gpt4 book ai didi

ios - 如何在 swift 中调用 UnitySendMessage 方法?

转载 作者:可可西里 更新时间:2023-11-01 00:55:11 29 4
gpt4 key购买 nike

我尝试使用 swift 语言在我的 iOS Framework 项目中调用 UnitySendMessage 方法,但它显示此错误-

使用未解析的标识符“UnitySendMessage”

这是我的 swift 文件的代码片段-

import Foundation

@objc public class Example : NSObject{

@objc open static let shared = Example()

@objc open func printMsg(){
print("\(#function) is called with message:");
UnitySendMessage("CallbackTarget", "OnCallFromSwift", "Hello, Unity!");
}
}

卡在这里,你能告诉我我错过了什么吗?

最佳答案

检查答案here .

UnitySendMessage is in libiPhone-lib.a, and as far as I can tell, the Unity folks don't include any header that declares it.

I just added the following to my code

extern void UnitySendMessage(const char *, const char *, const char *);

If you look at the generated AppController.mm, they basically do the same thing for the various UnitySendXXX functions, rather than including a header.

Having said that, while you will be able to build a library that calls UnitySendMessage, that library probably won't work unless it's linked into a Unity project, since UnitySendMessage is going to require more than just libiPhone-lib.a to actually work.

关于ios - 如何在 swift 中调用 UnitySendMessage 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51192883/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com