Current location - Health Preservation Learning Network - Healthy weight loss - How does unity Project run on android?
How does unity Project run on android?
First, we need to create an android project. Because the project needs to use the interface provided by Unity, we need to introduce the interface classes.jar into the current project. The interface displays the location of the package and opens the finder->; Application->; Unity->; Click the Unity icon, and right-click and select "Show Package Contents"->; Content-> Playback engine->; Android player-& gt; bin-& gt; After the classes.jar interface package is introduced into the project, write JAVA code. UnityTestActivity is the main activity, which is called when the Unity program moves together. It is configured in AndroidManifest.xml and needs to inherit UnityPlayerActivity, but it is an interface class provided in the classes.jar package we just introduced. UnityTestActivity provides two method interfaces, namely the StartActivity0 (string name) method and the startActivity 1 (string name) method. Both methods are called by a C# script in Unity, which means that a new Activity will be opened after the program is called, and the parameter name is also passed by the C# script, and then the passed String parameter will be passed to the newly opened activity. The next step is to set up xml files and layout files. I am familiar with all the students who can program Android. Publish the written java code to the jar package. Next, create the unity project. The folder structure in Unity project is as follows: plug-ins-> plug-ins; The name of Android cannot be modified, and it must be consistent. Then copy the engineering files of Android in Eclipse here, and copy all other folders to plugins->; Android folder. Finally, in the plug-in->; Create a bin folder in the Android folder, and then copy the one just generated. Jar file. The name of jar can be modified at will, but the jar package must be COM->; xys->; Your class file, otherwise you will be prompted that the class file cannot be found after running the program. The next step is how to call the code of android method in C#. Add the following code. AndroidJavaClass JC = new AndroidJavaClass(" com . unity 3d . player . unity player "); AndroidJavaObject jo = jc。 GetStatic & ltAndroidJavaObject & gt(“current activity”); Joe. Call("StartActivity0 ","first activity "); Get the AndroidJavaClass first, and then get that AndroidjavaObject is the currently active object, which is the main UnityTestActivity.JAVA we created on it. Call Joe. Call () parameter 1 after getting its object, which means calling the name of the method in the UnityTestActivity.JAVA class, and parameter 2 means that the method passes the past parameters. As shown in the following figure: "the first activity" and "the second activity" are the past strings I passed in C#. 7 released as the android platform apk.