原地址: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应用的更多相关文章

  1. [国嵌笔记][019][Eclipse集成开发环境]

    Eclipse集成开发环境的作用 可以编译程序,也可以对程序进行在线调试 集成开发环境 1.JLink连接开发板的JTAG 2.JLink连接PC的USB 3.eclipse软件 4.gdb serv ...

  2. PhoneGap 在eclipse上开发Android程序

    本文将记录在Eclipes上开发Android App,在使用的方法是Hybrid App(混合模式移动应用), 由于本人的工作需要,将要开发在车间使用的数据录入程序,但是其中有非常多的逻辑验证和判断 ...

  3. 【转】eclipse集成开发工具的插件安装

    转发一:打开Eclipse下载地址(http://www.eclipse.org/downloads/),可以看到有好多版本的Eclipse可供下载,初学者往往是一头雾水,不知道下载哪一个版本. 各个 ...

  4. eclipse adt开发android ndk没有NDK选项问题的解决方案

    原创 2015年01月28日 09:38:40 标签: android ndk / eclipse / adt 15989 今天是2015年1月28号,整理一下昨天使用eclipse adt搭建的an ...

  5. 1.5 Eclipse集成开发环境

    1. 格式化nandflash PATH路径优先用前面的 Arm-linux-gdb   # .bashrc   # User specific aliases and functions   ali ...

  6. 配置eclipse集成开发环境_编译_调试

    1. 因为eclipse是基于Java运行,所以在运行Eclipse之前,需要安装Java SE,对于Java SE,需要Java SE6 JRE系列的版本,可以在这个位置下载: Java SE 6只 ...

  7. 1.3……Eclipse下开发Android相关知识

    Android应用目录结构 src -------------------------------------------java原代码存放目录 gen ----------------------- ...

  8. Eclipse集成开发环境搭建

    gdbserver安装: 安装gdb-server的环境变量要放在arm-linux-gcc的环境的前面,因为arm-linux-gcc的安装包里面也有gdb,linux系统在找指令时从/root/. ...

  9. 5.3.2 Eclipse集成开发环境的使用技巧

    Eclipse具有强大的编辑.调试.编译和打包功能,本节仅讲解Eclipse中最常用的功能. 1.将程序代码和注释字体变大 (1)启动Eclipse,选择“Windows”->“Preferen ...

随机推荐

  1. android之回调函数的意义

    本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17483273) 看完这篇文后大家可以看看这个http://blog. ...

  2. winform 上传文件

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  3. MVC3、如何应用EntityFramework 连接MySql 数据库

    原文:MVC3.如何应用EntityFramework 连接MySql 数据库 新的一年,新的开始. 今天总结的主题是在MySql中应用EntityFramework 的Code First模式. 开 ...

  4. C#程序员整理的Unity 3D笔记(十五):Unity 3D UI控件至尊–NGUI

    目前,UGUI问世不过半年(其随着Unity 4.6发布问世),而市面上商用的产品,UI控件的至尊为NGUI:影响力和广度(可搜索公司招聘Unity 3D,常常能看到对NGUI关键词). NGUI虽然 ...

  5. javascript笔记——js的阻塞特性[转载]

    JS具有阻塞特性,当浏览器在执行js代码时,不能同时做其它事情,即<script>每次出现都会让页面等待脚本的解析和执行(不论JS是内嵌的还是外链的),JS代码执行完成后,才继续渲染页面. ...

  6. Qt实现桌面动态背景雪花飘落程序

            曾经收到过一份礼物,一个雪花飘落的程序,觉得效果很炫,通过前几篇的学习,我们已经掌握了贴图的一些技巧了,那么现在就可以自己实现了(当然你必须先拥有qt信号与槽的基础知识),这里先看效果 ...

  7. swfupload使用说明

    网上的例子介绍的文档真的很多.下面简单介绍一下 SWFUpload的文件上传流程是这样的: 1.引入相应的js文件 2.实例化SWFUpload对象,传入一个配置参数对象进行各方面的配置. 3.点击S ...

  8. 探索 Java 同步机制[Monitor Object 并发模式在 Java 同步机制中的实现]

    探索 Java 同步机制[Monitor Object 并发模式在 Java 同步机制中的实现] https://www.ibm.com/developerworks/cn/java/j-lo-syn ...

  9. window.print打印指定div实例代码

    window.print可以打印网页,但有时候我们只希望打印特定控件或内容,怎么办呢,请看下面的例子 首先我们可以把要打印的内容放在div中,然后用下面的代码进行打印. 复制代码代码如下: <h ...

  10. 统计某一字段等于不同值的个数的sql语句(分享)

    本文介绍下,用一条sql语句统计某一字段等于不同值的个数,方法很独特,有需要的朋友参考下. 表t,数据:  id      type001     1001     0002     1001     ...