Unity calls the native program method, which defines the interface (Dotestselector):
usingUnityengine;usingSystem.Collections;usingSystem.Runtime.InteropServices; Public classTestscript:monobehaviour {//This tells Unity-look up the function foopluginfunction//inside the static binary[DllImport ("__internal")] Private Static extern floatdotestselector (string info); voiddotest () {#ifUnity_androidusing(Androidjavaclass JC =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer")) { using(Androidjavaobject Jo = JC.) Getstatic<androidjavaobject> ("currentactivity") {Jo. Call ("Dotestselector","My Info"); } }#endif #ifUnity_iphoneDotestselector ("my Info");#endif }
public void backtounity () {
Do somthing ...
}
}
Native programs implement interfaces, such as iOS, to open native Viewcontroller:
Still developed with OBJECTIVE-C because of demand constraints
extern " C " float dotestselector (constChar* info) { *VC = [[Yourviewcontroller alloc] Initwithnibname:@ "yourviewcontrollername" Bundle:nil]; [[Unitygetmainwindow () Rootviewcontroller] PRESENTVIEWCONTROLLER:VC animated:yes completion:nil]; return 0.0f ;}
Close the native program and go back to unity, also using iOS as an example:
-(Ibaction) Onclickback: (ID) sender { [self dismissviewcontrolleranimated:yes completion:nil]; Unitysendmessage ("testscriptgameobject", [@ "backtounity" utf8string], [@ "" utf8string]);}
Unity calls native (IOS, Android) method