Does anyone have a ready-made example of implementing a callback
call from c ++ from ios back to unity3d
(not UnitySendMessage
, but with any parameters)? Or where you can read about it in detail.
Those. call through C # delegates?
1 answer
C #
using UnityEngine; using System.Collections; using System.Runtime.InteropServices; using System; using AOT; public delegate void SDKCorePluginCallbackDelegate(string inparam); public class SDKCorePlugin { #if UNITY_EDITOR private static void _SDKCorePluginInitPlayer (string url,string playerName,SDKCorePluginCallbackDelegate fp) { Debug.Log ("SDKCorePlugin: Application.platform==RuntimePlatform.OSXEditor||RuntimePlatform.AndroidEditor!!!"); } #else #if UNITY_ANDROID [DllImport ("unity_bridge")] #elif UNITY_IPHONE [DllImport ("__Internal")] private static extern void _SDKCorePluginInitPlayer (string url,string playerName,SDKCorePluginCallbackDelegate fp); #endif #endif // Starts lookup for some bonjour registered service inside specified domain public static void SDKCorePluginInitPlayer (string requestURL,string playerName,string objectName, string methodName,SDKCorePluginCallbackDelegate fp) { _SDKCorePluginInitPlayer(requestURL,playerName,fp); } [MonoPInvokeCallback (typeof (SDKCorePluginCallbackDelegate))] public static void CallBackDataDelegate(string inparam) { inst.ResultText.text=inparam; } }
C ++
typedef void ( *ANSWERCB )(char*); // When native code plugin is implemented in .mm / .cpp file, then functions // should be surrounded with extern "C" block to conform C function naming rules extern "C" { void _SDKCorePluginInitPlayer(const char* url,const char *playerName,ANSWERCB fp) { [[SDKCoreClient GetSharedClient] initPlayer:CreateNSString(url) playername:CreateNSString(playerName)]; [[SDKCoreClient GetSharedClient] setCallBackParams: fp]; } }
The whole point is using AOT;
and MonoPInvokeCallback
|