I’m trying to set up some SwiftUI sliders to modify Unity properties. I feel like I have a good handle on sending data from Unity to SwiftUI (@DanMillerU3D 's linkedIn post really helped) but I’m stuck on how to get values back from SwiftUI to Unity. I think I’m fine on the C# side, but I’m not sure how to create my own delegate/callback like the SwiftUISamplePlugin CallbackDelegateType/CallCSharpCallback that receives types of data other that strings.
This is the bit I’m most confused about, when trying to create my own:
typealias CallbackDelegateType = @convention(c) (UnsafePointer<CChar>) -> Void
var sCallbackDelegate: CallbackDelegateType? = nil
// Declared in C# as: static extern void SetNativeCallback(CallbackDelegate callback);
@_cdecl("SetNativeCallback")
func setNativeCallback(_ delegate: CallbackDelegateType)
{
print("############ SET NATIVE CALLBACK")
sCallbackDelegate = delegate
}
// This is a function for your own use from the enclosing Unity-VisionOS app, to call the delegate
// from your own windows/views (HelloWorldContentView uses this)
public func CallCSharpCallback(_ str: String)
{
if (sCallbackDelegate == nil) {
return
}
str.withCString {
sCallbackDelegate!($0)
}
}
Could anyone let me know how I can create a callback that receives for example a string, a float and an int parameters?
Thank you!!