"unity" integration with iOS and Android: 1. The exported Xcode project

Source: Internet
Author: User
Tags unity 5

This article belongs to one of the series of articles on "unity and iOS, Android platform Integration .

This article focuses on the directory structure of the Xcode project that unity exports.

The version of the software I use:

Unity 5.3.5F1

Xcode 7.3

Preamble Step

The first step is to create a new project Build_to_ios_android

The second step is to create a new file CSharpToCPP.cs

 using   Unityengine;  public  class   csharptocpp{ public  void  Func (int   num) { if  (num < 1  ) { 
   
    return  
    ;  
    else  
     {Debug.Log ( log:time          + num); }    }}
   

Step three, create PLUGINS/IOS/IOS_EMPTYMM.MM, Streamingassets/all_emptytxt.txt

Fourth step, save the scene, such as

Fifth Step, select iOS platform, build export Xcode project

Sixth step, open the exported Xcode project

Go to the Chase

1. Program Entrance

Any program has a portal, and Unity's exported Xcode project is no exception, and as we can see, Unityappcontroller objects are created in the app's portal.

As we can see, Unityappcontroller is inherited from the uiapplicationdelegate, as to what it is I will not repeat, we can look at this article: Brief analysis of UIApplication and uiapplicationdelegate

For a uiapplication declaration cycle, we can see that there is a very useful monitoring of system events, We can also see the corresponding function in unityappcontroller.mm, which means that we can receive these events in unity, and we will inherit Unityappcontroller and rewrite these listeners.

2, C # C + +:

In unity, we use C #, JS for programming (I'm a C # Party), but after the Xcode project is exported, the code is converted to C + + code.

In the player settings we can see that there are two modes of operation of the script, one is Il2cpp, the other is mono2x (I will certainly be replaced by CPP, I will not say), usually we will choose Il2cpp, because of high efficiency.

Select Il2cpp our logic code will all be converted to C + + code, converted to C + + code for CSharpToCPP.cs.

The following code is the translation code in, and we should be able to understand the logic in the CSharpToCPP.cs logic we wrote at the beginning.

//system.void Csharptocpp::func (System.Int32)externil2cppclass*Int32_t2847414787_il2cpp_typeinfo_var;externil2cppclass*String_t_il2cpp_typeinfo_var;externil2cppclass*Debug_t1588791936_il2cpp_typeinfo_var;externil2cppcodegenstring*_stringliteral2043233667;extern Constuint32_t Csharptocpp_func_m1441544591_metadatausageid;extern "C"  voidcsharptocpp_func_m1441544591 (csharptocpp_t373417985 * __this, int32_t ___NUM0,Constmethodinfo*method) {    Static BOOLs_il2cppmethodintialized; if(!s_il2cppmethodintialized)        {Il2cpp_codegen_initialize_method (Csharptocpp_func_m1441544591_metadatausageid); S_il2cppmethodintialized=true; } {int32_t L_0=___NUM0; if(((int32_t) l_0) >= ((int32_t)1)))        {            Gotoil_0008; }    }    {        return; }il_0008: {int32_t l_1=___NUM0; int32_t l_2=L_1; Il2cppobject* L_3 = Box (Int32_t2847414787_il2cpp_typeinfo_var, &l_2);        Il2cpp_runtime_class_init (String_t_il2cpp_typeinfo_var); string_t* L_4 = string_concat_m389863537 (NULL/*Static, unused*/, _stringliteral2043233667, L_3,/*hidden Argument*/NULL);        Il2cpp_runtime_class_init (Debug_t1588791936_il2cpp_typeinfo_var); debug_log_m1731103628 (NULL/*Static, unused*/, L_4,/*hidden Argument*/NULL); return; }}

Because C + + code is automatically generated by the machine and readable by the human urine, it is best to refer to your own C # code for reading.

Since the compile time is too long because of the unity-and Xcode-like device, I try to annotate or simply modify C + + code to fix the problem when troubleshooting.

3, Resources Streamingassets, Data/raw

Unity Export Xcode Project, the original project all kinds of resources are compressed, packaged, encrypted and stored in the Data folder, which is consistent with Android, there are a lot of resources on the Internet to decrypt the method, we need to be able to search by themselves.

Let's focus on the Streamingassets folder in unity, about the role of this file, you can take a look at this article:Unity3d Institute of the Hand of the development of all the special folders

As we can see, the all_emptytxt.txt files in the Streamingassets folder are completely copied to the Data/raw folder, which is not just files, but folders are also copied into the folder intact.

As for what this is for, for example, the configuration file is placed here, on the phone debugging can directly modify the configuration in the Xcode project, without the need to re-export Xcode project in unity.

4, Plugins/ios-Library/plugins/ios

The Plugins/ios folder usually puts some *.a, *.h, *.m files, which are copied to the Library/plugins/ios folder in the Xcode project and will be compiled when Xcode is compiled.

During the actual operation, I will put the OC, C, C + + code, and SDK provided by my iOS to the inside to avoid re-importing it in the Xcode project after each compilation.

5. Icon

In Unity's player settings is, we can add the corresponding icon

These icon images will be re-compressed, named last placed in the position.

Since icon will occupy a certain amount of memory within unity, I will typically replace the icon file in Xcode with the same effect and without occupying unity's memory.

6. Splash screen

Unity in the iOS has many kinds of flash screen solutions, the specific results of the program can be self-search ~

For the common single image splash screen export location, like icon, I usually replace here, oh yes, do not forget to cancel the Showunitysplashscreen check.

7. Framework

In Unity's plugins/ios/, the file can be configured with some framework dependencies for its own simple tick, see.

These dependencies are automatically added to the Xcode project, and we can check for additions in the Frameworks folder.

8, Player Settings, settings

There are a number of configurations in Unity's player settings that will be reflected in the Xcode project, in which the parts are not complicated and I won't go into it.

"unity" integration with iOS and Android: 1. The exported Xcode project

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.