Unity supports native plugin, which are libraries of native code written in Swift.
Native plugin make possible for code written in C# to call functions from these libraries.
Check this document for detailed Native Plugin creation instructions.
Check Makefile for command details.
$ make framework
This should result in SwiftPmPlugin.framework
being generated in Build
.
Copy the built framework into your Unity project's Assets/Plugins/iOS
.
Enable Add To Embedded Binaries
in the Unity Inspector of SwiftPmPlugin.framework
.
$ make bundle
This should result in SwiftPmPlugin.bundle
being generated in Build
.
Copy the built bundle into your Unity project's Assets/Plugins/macOS
.
Need to restart unity to load the new bundle.
Check UnityInterface.swift for details.
@_cdecl("swiftPmPlugin_toNumber")
public func swiftPmPlugin_toNumber(_ stringPtr: UnsafePointer<CChar>?) -> Int64 {
let str = String(cString: stringPtr!)
return Int64(Int(str) ?? 0)
}
Check SwiftPmPlugin.cs for details.
[DllImport(libName)]
private static extern long swiftPmPlugin_toNumber(string stringNumber);
public static long ToNumber(string stringNumber)
{
return swiftPmPlugin_toNumber(stringNumber);
}