如何将unity项目导入现有的Android Studio项目? [英] How to import unity project into existing Android studios projecT?

查看:423
本文介绍了如何将unity项目导入现有的Android Studio项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将unity项目导入Android Studios时遇到问题.我已经有一个Android Studio项目(用于菜单和其他操作),并且我想从Unity 5 3D中添加一个场景作为第二个活动(而不是主要活动).

I am having problems importing unity project into Android Studios. I already have a Android studio project (for menu and other things), and i want to add a scene from Unity 5 3D, as a second activity (not the main activity).

我想在用户单击按钮时调用统一场景.

I want to call unity scene when user clicks the button.

我知道如何从单位导出,但是它会自动将其设置为MainActivity,并且我找不到手动覆盖它的方法.

I know how to export it from unity but it automatically sets it as MainActivity, and i cant find a way to manually overwrite it.

修改: 我想在Android Studio中而不是在Eclipse中进行操作.我只想知道是否有一种简单的方法,或者至少是一个提示.

I want to do it in Android Studios and not Eclipse. I just want to know if there is an easy way to do it, or at least a hint for how to do it.

推荐答案

具有相同的要求,并将Unity项目成功导入到现有的Android Studio项目中.如前所述,第一件事将是导出Unity项目.我使用的是Unity版本2017.1.大致步骤如下:

Had the same requirement and successfully imported the Unity project into an existing Android Studio project. As mentioned the first thing will be to export the Unity project. I used Unity version 2017.1. Rough steps below:

  1. 通过Unity构建设置导出Android项目

  1. 您可以简单地选择现有项目所在的文件夹. Unity应该添加一个子文件夹,其中包含一个Android Studio格式的项目以及所有依赖项以及运行它所需的所有内容.

  1. You can simply select the folder where your existing project is located. Unity should add a sub folder with an Android Studio format project and all dependencies and everything it needs to run.

现在,我们需要将该应用程序"项目转换为图书馆"项目.只需更改 build.gradle 文件即可完成.将应用插件:" com.android.application "替换为应用插件:" com.android.library ".

Now we need to convert this "Application" project to a "Library" project. This is simply done by changing the build.gradle file. Replace apply plugin: 'com.android.application' with apply plugin: 'com.android.library'.

您还需要删除 applicationId 并更改编译版本以匹配您项目的版本.

You also need to remove the applicationId and change the compile versions to match your project's versions.

  1. 还请确保修改Unity模块AndroidManifest.xml文件.您将需要删除LAUNCHER意向过滤器,因为UnityPlayerActivity将不再是主要活动.

  1. Also make sure to modify the Unity module AndroidManifest.xml file. You will need to remove the LAUNCHER intent-filter as the UnityPlayerActivity will not be the main activity anymore.

android.intent.action.MAIN

android.intent.action.MAIN

android.intent.category.LAUNCHER

android.intent.category.LAUNCHER

还需要删除应用程序"节点属性,以免与项目清单冲突.

Also need to remove the Application node attributes so it won't conflict with your project's manifest.

  1. 最后,在settings.gradle中添加模块,然后在"app"模块上添加Unity项目依赖项: compile project(':UnityFolder')

构建,现在您应该可以通过调用以下命令来启动Unity场景:

Build and now you should be able to start the Unity Scene by calling:

Intent intent = new Intent(this,UnityPlayerActivity.class);

Intent intent = new Intent(this, UnityPlayerActivity.class);

startActivity(intent);

startActivity(intent);

这篇关于如何将unity项目导入现有的Android Studio项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆