Unity3D与Eclipse集成开发Android应用

 

 

首页Linux编程

背景:

阅读新闻

Unity3D与Eclipse集成开发Android应用

[日期:2011-12-02]   来源:Linux社区  作者:armoonwei   [字体:]  

Unity as a Library

Once you have eclipse installed and up to date you have to follow a few steps to get your unity project set up as a library in eclipse.

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

Java Project

The next step is to create the eclipse project that will 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 be the same as the Library project that you created. Make sure that the package name is 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 be added to the project, you do this by right clicking the JavaProject and selecting properties. You then need to Select Android and click add. A window should then popup select the library project that was created and click ok. Once you are back in the main window click apply. Now select Java Build Path from the list on the left and click add external jar. A window will now popup you need to navigate to your unity install directory and in Unity\Editor\Data\PlaybackEngines\androidplayer\bin there will be a file called classes.jar. Double click that and then click on ok.

This sets up a basic Java Project that is now linked to your unity project and the relevant libraries that we will later need.

Moving the Projects Assets

This is the important part to get your unity content into the Java Project so that it will display when you later build and run your Java Project. You now need to move all the files in the assets folder in the library project into the new project. This is because Android does not allow assets to be used in libraries. The best way to do this is from 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 is rebuilt or maybe you could write a script to handle moving the files everytime you build the project automatically. This could also be achieved using symlinks or junctions. At this point when you run the from the eclipse ide you will be asked which type of project that you want to run. Select android and click ok. After eclipse builds the project it will 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 you need to make a few changes to the java source code. In your eclipse project there will be one source file (.java) open this file. The contents of this file will 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 savedInstanceState) { 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 will notice that when you do this that it is 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 have the import statement.

import com.unity3d.player.UnityPlayerActivity;

If you run in this state you will see that you now have a full screen hello world application. This is not what you want we need one more change to get your unity content running.

In the onCreate function there is one line that is overriding the unity view in the android application. If you delete the line.

setContentView(R.layout.main);

The complete file should now look like this.

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 will see your unity content running on your android device.

使用StreamTokenizer统计文件的字符数

Android下调试Unity3D应用

相关资讯       Android开发教程 

   

本文评论   查看全部评论 (0)


评论声明

尊重网上道德,遵守中华人民共和国的各项有关法律法规

承担一切因您的行为而直接或间接导致的民事或刑事法律责任

本站管理人员有权保留或删除其管辖留言中的任意内容

本站有权在网站内转载或引用您的评论

参与本评论即表明您已经阅读并接受上述条款

 

 

 

最新资讯

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyxffs.html