原地址: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. (转载)Nim游戏博弈(收集完全版)

    Nim游戏的概述: 还记得这个游戏吗?给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠,但不能在两列中取.最后拿光珍珠的人输.后来,在一份资料上看到,这种游戏称为“拈(Nim)”.据说,它源 ...

  2. html dom的加载

    操作HTML DOM文档的一个难题是,你的JavaScript代码可能在DOM完全载入之前运行,这会导致你的代码产生一些问题.页面加载时浏览器内部操作的顺序大致是这样的: 1. HTML被解析. 2. ...

  3. [Entity Framework] MySQL @ Entity Framework 6

    原文 [Entity Framework] MySQL @ Entity Framework 6 要让MySQL能够用EF6,我花了一点时间,在此记录一下 安装元件 在设定档加入Provider 安装 ...

  4. Linux文件系统结构

    准备写个Linux基础知识总结, 第一个想到的就是整理一个常用系统文件夹结构的说明,园子里“Aric小屋”的结构图整理的不错,我就不重复整理了,故借用一下

  5. java坑之无法创建线程

    环境:linux 错误:java.lang.OutOfMemoryError: unable to create new native thread 原因:OS对线程是有限制 解决办法: 在Linux ...

  6. (转)实战Memcached缓存系统(3)Memcached配置参数初解

    一.基本参数 在我们第一次安装Memcached时,一般都是用过这个命令: memcached -m 512 -u root -d -l 127.0.0.1 -p 11211 我们先来解释这几个参数的 ...

  7. Object类型

    Object类型 我们看到的大多数引用类型值都是Object类型的实例,虽然Object类型不具备多少功能,但是在储存和传输数据上的确是不错的选择. 2.对象字面量表示法 调用Object构造函数: ...

  8. 【转载】应读者强烈要求给出《超容易的Linux系统管理入门书》一书的主要知识点

    刚开始了一篇连载,收到广大Linux爱好者的反馈,非常欣慰.大家对Linux学习感到很迷茫,不知道学哪些内容,如何学习? <超容易的Linux系统管理入门书>一书是腾讯Linux专家在腾讯 ...

  9. c#索引器的简单用法

    abstract class Bird { protected string name; public abstract string Name { get; set; } public abstra ...

  10. Hadoop示例程序WordCount编译运行

    首先确保Hadoop已正确安装及运行. 将WordCount.java拷贝出来 $ cp ./src/examples/org/apache/hadoop/examples/WordCount.jav ...