The method of parameter transfer between iOS and Unity
This article mainly introduces "the method of parameter transfer between iOS and Unity". In the daily operation, I believe that many people have doubts about the method of parameter transfer between iOS and Unity. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the method of parameter transfer between iOS and Unity". Next, please follow the editor to study!
1. Call method one
Unity modulation method passes parameters, and a return value is returned.
/ / Unity code
[DllImport ("_ _ Internal")]
/ / pass the string parameter to iOS. The return value is returned to Unity through the return method of iOS.
Private static extern string getIPv6 (string mHost, string mPort) / / iOS Code
Extern "C" const char * getIPv6 (const char * mHost, const char * mPort)
{
/ / strdup (const char * _ S1) copies the mHost string and allocates space through Malloc ()
/ / return strdup (mHost)
Return makeStringCopy (mHost)
}
Char* makeStringCopy (const char* string)
{
If (NULL = = string) {
Return NULL
}
Char* res = (char*) malloc (strlen (string) + 1)
Strcpy (res, string)
Return res
} using System.Runtime.InteropServices
two。 Call method two
Unity modulation method passes parameters. No return value is returned.
/ / Unity code
/ / transfer data to iOS
[DllImport ("_ _ Internal")]
/ / pass the string parameter to iOS. No return value is returned. The return value is returned to Unity through the UnitySendMessage method of iOS.
Private static extern void setDate (string date)
/ / receive data from iOS
Public void GetDate (string date)
{
} / / iOS code
Extern "C" void setDate (const char * date)
{
/ * *
Send data to Unity
@ param obj model name
@ param method Unity the name of the method that receives iOS data
@ param msg data passed to Unity
UnitySendMessage (const char* obj, const char* method, const char* msg)
, /
UnitySendMessage ("PublicGameObject", "GetDate", date)
At this point, the study of "the method of passing parameters between iOS and Unity" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!