原地址: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 快捷方式相关操作

    尽管现在少数手机不支持快捷方式,但是仍然有大部分手机是支持的.创建快捷方式,可以减少用户在应用列表繁多的应用程序中查找应用的时间,快速进入应用:或是应用中的某个功能使用频率较高,创建快捷方式,可以快速 ...

  2. Win7显示隐藏文件,隐藏文件夹怎么显示?如何查看?

    隐藏文件技术是木马病毒传播最惯用的手法之一,它们利用大部分网友对基础操作的不熟悉特点,逃过用户的发现和检查,显示隐藏文件的标准设置方法大家都会使用,一旦隐藏问题与病毒木马结合起来,比如典型的autor ...

  3. 【Android学习之旅】1、Android入门介绍

    1.Android介绍 1.1 Android的系统架构 下面这张图展示了Android的系统架构: 图中可见,Android大致可以分为四层架构,五块区域: Linux内核层(Linux Kerne ...

  4. Mingw64编译wxWidgets3.0.2常见错误

    使用Mingw64编译wxWidgets3.0.2,首先得下载wxMSW-Setup-3.0.2.exe(https://sourceforge.net/projects/wxwindows/file ...

  5. Android类库打包方法探究

    原文地址: http://www.cnblogs.com/wangchuanju/archive/2012/04/05/android_lib_jar.html 开发Android应用的时候,对于可用 ...

  6. java.util.LinkedList源码分析

    public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, D ...

  7. Windows Phone 8.1 页面导航

    1. Windows Phone 8.1 的应用框架 一个应用拥有 1 个 Window,一个 Window 包含 1 个 Frame,一个 Frame 包含 多个 Page. 获取 Frame 的方 ...

  8. Python 三大神器

    Python 三大神器 Python 中有很多优秀的包,本文主要讲一下 pip, virtualenv, fabric 1. pip 用来包管理 文档:https://pip.pypa.io/en/l ...

  9. ubuntu后台配置无线网络

    一.静态配置: 1.编辑 /etc/network/interfaces: auto loiface lo inet loopback auto wlan0iface wlan0 inet stati ...

  10. 微信公众号-开发者-自定义菜单-CLICK事件处理

    想点击菜单,推送消息.功能很简单,坑了我一天时间.在此笔记. 菜单代码: { "button":[ { "type":"click", &q ...