unity3d与eclipse集成开发android应用
原地址:http://blog.csdn.net/armoonwei/article/details/7032537
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.
- 创建一个空的unity3d工程,然后使用android平台进行编译。
- 切换到新工程的目录中,找到Temp目录,这个目录下有:staging area.
- 拷贝目录staging area到其他某个目录下,注意此目录不要放置于eclipse工作空间中。
- 打开eclipse并创建一个android的项目。
- 在创建项目的引导中,选择Android Project并点击Next按钮
- 这一步是工程的library信息, This will be the library part of your project so name the project accordingly to avoid any confusion.
- You will also want to select the option to create project from an existing source. This source being the files you copied to the folder you are using as a holding area. If you select the Staging Area folder then click OK you will see that eclipse has 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 android tab. Check the "Is Library" check box, click Apply and then OK.
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.
unity3d与eclipse集成开发android应用的更多相关文章
- [国嵌笔记][019][Eclipse集成开发环境]
Eclipse集成开发环境的作用 可以编译程序,也可以对程序进行在线调试 集成开发环境 1.JLink连接开发板的JTAG 2.JLink连接PC的USB 3.eclipse软件 4.gdb serv ...
- PhoneGap 在eclipse上开发Android程序
本文将记录在Eclipes上开发Android App,在使用的方法是Hybrid App(混合模式移动应用), 由于本人的工作需要,将要开发在车间使用的数据录入程序,但是其中有非常多的逻辑验证和判断 ...
- 【转】eclipse集成开发工具的插件安装
转发一:打开Eclipse下载地址(http://www.eclipse.org/downloads/),可以看到有好多版本的Eclipse可供下载,初学者往往是一头雾水,不知道下载哪一个版本. 各个 ...
- eclipse adt开发android ndk没有NDK选项问题的解决方案
原创 2015年01月28日 09:38:40 标签: android ndk / eclipse / adt 15989 今天是2015年1月28号,整理一下昨天使用eclipse adt搭建的an ...
- 1.5 Eclipse集成开发环境
1. 格式化nandflash PATH路径优先用前面的 Arm-linux-gdb # .bashrc # User specific aliases and functions ali ...
- 配置eclipse集成开发环境_编译_调试
1. 因为eclipse是基于Java运行,所以在运行Eclipse之前,需要安装Java SE,对于Java SE,需要Java SE6 JRE系列的版本,可以在这个位置下载: Java SE 6只 ...
- 1.3……Eclipse下开发Android相关知识
Android应用目录结构 src -------------------------------------------java原代码存放目录 gen ----------------------- ...
- Eclipse集成开发环境搭建
gdbserver安装: 安装gdb-server的环境变量要放在arm-linux-gcc的环境的前面,因为arm-linux-gcc的安装包里面也有gdb,linux系统在找指令时从/root/. ...
- 5.3.2 Eclipse集成开发环境的使用技巧
Eclipse具有强大的编辑.调试.编译和打包功能,本节仅讲解Eclipse中最常用的功能. 1.将程序代码和注释字体变大 (1)启动Eclipse,选择“Windows”->“Preferen ...
随机推荐
- C# WCF学习笔记(二)终结点地址与WCF寻址(Endpoint Address and WCF Addressing) WCF中的传输协议
URI的全称是 Uniform Rosource Identifire(统一资源标识),它唯一标识一个确定的网绐资源,同时也表示资源所处的位置及访问的方式(资源访问所用的网络协议). 对于Endpoi ...
- SignalR 2.0 系列:SignalR的服务器广播
英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with ASP.NET SignalR 2.0系列的翻译,这里是第八篇:SignalR的服务器广 ...
- contentMode各种样式展示
我们用图片来展示下contentMode的各种样式. 原图size为1155 * 715imageView的size为335 * 607 一.UIViewContentModeScaleToFill ...
- String.Trim
String.Trim有2个重载方法,分别是:Trim()和Trim(char[]),根据官方的解释 Trim():从当前String对象移除所有前导空白字符和尾部空白字符. Trim(char[]) ...
- javascript-对象的函数(一)
Date.prototype.Format = function(fmt) { //author: meizz var o = { "M+" : this.getMonth()+1 ...
- checkbox批量选中,获取选中的项的值
<!doctype html><html lang="en"> <head> <meta charset="UTF-8&quo ...
- 纯JS焦点图特效(可一个页面多用)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 纯CSS3代码实现简单的图片轮播
以4张图片为例:1.基本布局:将4张图片左浮动横向并排放入一个div容器内,图片设置统一尺寸,div宽度设置4个图片的总尺寸,然后放入相框容器div,相框设置1个图片的大小并设置溢出隐藏,以保证正确显 ...
- php三维数组去重(示例代码)
php三维数组去重的示例代码. 假设叫数组 $my_array; <?php // 新建一个空的数组. $tmp_array = array(); $new_array = array(); ...
- php mysqli多个查询的例子
php中Mysqli多个查询的例子,感兴趣的朋友可以参考下. php中Mysqli多个查询的例子,感兴趣的朋友可以参考下. mysqli_multi_query(mysqli link,string ...