Unity uses the C + + cross-platform Ultimate solution (pc,ios,android, and a platform that supports C + +)

Source: Internet
Author: User

The fact that the PC does not have to say, after all, C # and C + + interactive article is enough, of course, I feel after a few toss. Almost all the games need to operate I have mastered (a variety of methods, all kinds of pits, do not understand the message can be asked. Although no one looked at all. haha




Needless to say, we're mainly talking about two big platforms--ios and android--interacting with Unity's native code


Here is to go online search is all kinds of egg pain, for example, suppose to call Unity C # function, almost exclusively is to give Unitysendmessage method. Using this in the project is almost dead. That's a lot of complicated functions. You're the one with the broken function.

iOS is fine to say. Android is a pit, even if you want to interact with the Java code, in short, C + +-"Java-" C #. And in fact most of the time you do not need such a pain, direct C/C + +-"C # can be." Because C + + is nearly capable of operating all underlying resources. Of course, individual requirements exceptions


Business


typedef struct PARAMETER {    int A;    int b;} param;typedef void (*callback) (param* p); void TestFunc (CallBack cb) {    Param p;    P.a = ten;    P.B =;    CB (&P);}

extern "C" such details are not much to say, because I directly built a. C file so do not need this tag, here directly with the typical callback function to do the example, because of the callback. You don't have to think about how to use C/C + + or vice versa, because this example actually includes the exchange of information


public class Newbehaviourscript:monobehaviour {    [StructLayout (layoutkind.sequential)]    struct Parameter { public       int A;       public int b;    }    delegate void CallBack (IntPtr param);    [DllImport ("TestLib")]    static extern void TestFunc (CallBack cb);    [Monopinvokecallback (typeof (CallBack))]    static void Callbackfunc (IntPtr param) {       var p = (Parameter) marshal.ptrtostructure (param, typeof (Parameter));       Debug.Log ("A:" + P.a + "B:" + p.b);    } Use the This for Initializationvoid Start () {        TestFunc (callbackfunc);} Update is called once per framevoid update () {}}

Notice key No, yes,

[monopinvokecallback (typeof (CallBack))] 

this tag. Without this tag, the callback will not succeed.


android Protection C # also mentioned in the previous article that although individuals do not know about security assumptions, the only hint is to use Coroutine coroutine

Unity uses C/ The ultimate cross-platform solution (Pc,ios,android, and a platform that supports C + +)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.