Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of parameter transfer between iOS and Unity

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report