Unity3d integrates with Eclipse to develop Android apps

Source: Internet
Author: User

Original address: http://blog.csdn.net/armoonwei/article/details/7032537

Unity as a Library

Once you had eclipse installed and up to date you had to follow a few steps to get your unity project set up as a Librar Y in Eclipse.

    • Create an empty Unity3d project and then compile it using the Android platform.
    • Switch to the new project directory and locate the TEMP directory, which has the following: Staging area.
    • Copy the directory staging area to one of the other directories, and note that this directory is not placed in the Eclipse workspace.
    • open Eclipse and create an Android project.  
    • in the boot that created the project, select Android Project and click the Next button
    • This step is the library information for the project,  this'll be is the library part of Yo ur project so name the project accordingly to avoid any confusion.
    • you'll also want to select the option to create project from an existing source. This source being the files you copied to the folder is the using as a holding area. If you select the "Staging Area" folder then click OK you'll see that eclipse have filled in the relevant fields for you.
    • Click Finish on the Project Creation Wizard.
    • Finally Right click the root folder in the Package Explorer tab in Eclipse and select the Properties option then the A Ndroid tab. Check the ' Is Library ' check box, click Apply and then OK.

This completes the steps so you need to carry out to having your unity project addressed as a library in eclipse.

Java Project

The next step is to create the Eclipse project, that would form the executable part of the project.

  • Create another new Android project.
  • Name the project and select the Build Target and Min SDK Version to is the same as the Library project that you created.
  • Make sure, the package name was the same as the bundle identifier in your unity project otherwise you can get problems With conflicting files in the generated Java files in your project.
  • Now the library you created needs to being added to the project, you do this by right clicking the Javaproject and selecting Properties.
  • Need to Select Android and click Add. A window should then popup Select the Library project is created and click OK. Once you is back in the main window click Apply.
  • Now select the Java Build Path from the list to the left and click Add External jar. A window would now popup need to navigate to your Unity install directory and in Unity\editor\data\playbackengines\andr Oidplayer\bin there would be a file called Classes.jar. Double Click and then click on OK.

This sets up a basic Java project that's now linked to your Unity project and the relevant libraries that we'll later n Eed.

Moving the Projects Assets

This was the important part to get your unity content into the Java Project so that it would display when you later build a D Run your Java Project. You are need to move all the files in the Assets folder in the library project into the new project. This is because Android does isn't allow assets to being used in libraries. The best-of-the-within the Eclipse IDE. If you expand the assets files within both parts of the package explorer and simply drag the bin and Libs folders from the Library part of your project to the other. This last step needs to repeated everytime your unity project are rebuilt or maybe you could write a script to handle Movin G The files everytime you build the project automatically. This could also is achieved using symlinks or junctions. At this point, you run the from the Eclipse IDE, you'll be asked which type of project, want to run. Select Android and click OK. After eclipse builds the project it would deploy it to your connected Android DEvice and you should see a Hello World style application running.

Getting Your Unity Content Running

To get your unity project need to make a few changes to the Java source code. In your eclipse project there would be a source file (. java) Open this file. The contents of this file would resemble something like this.

Package com. Unity3d.eclipseintegration;import Android.app.activity;import Android.os.bundle;public class EclipseIntegration Extends activity {    /** called when the activity is first created. *    /@Override public    void OnCreate (Bundle sav Edinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (R.layout.main);    }}

We need to change this. The first thing is to change the base class of the object. It should now instead extend unityplayeractivity. You'll notice it's red underlined proclaiming errors. This is simply missing import directives in the file. The Eclipse shortcut to auto resolve this is ctrl+shift+o. The Fiel should now has the import statement.

Import com.unity3d.player.UnityPlayerActivity;

If you run with this state, you'll see the A full screen Hello World application. This is not the want we need one more than change to get your unity content running.

The OnCreate function there is a line and that's overriding the Unity view in the Android application. If you delete the line.

Setcontentview (R.layout.main);

The complete file is should now.

Package com. Unity3d.eclipseintegration;import Android.os.bundle;import Com.unity3d.player.unityplayeractivity;public Class Eclipseintegration extends Unityplayeractivity {    /** called when the activity is first created. */    @Override    public void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);}    }

If you run it now, you'll see your unity content running on your Android device.

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.