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

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

问题描述

我在将 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.

我知道如何从 unity 导出它,但它会自动将其设置为 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 Studios 而不是 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

还需要删除 Application 节点属性,以免与您的项目清单冲突.

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 studios project 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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