How to import unity project into existing Android

2019-02-20 07:21发布

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.

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.

Edit: 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.

3条回答
Melony?
2楼-- · 2019-02-20 08:04

yes we can start another activity before unity Activity 1 step-create java class and add it in manifest and like in image

2nd step- create onClick in java class link to unity game class s you can see in amage see pic, you can choose button also

3rd step- in manifest replace Intent in own java class it will work [3]

查看更多
Deceive 欺骗
3楼-- · 2019-02-20 08:04

From this link: https://nevzatarman.com/2015/01/04/unity-android-tutorial-opening-unity-scene-from-an-activity/

Add android:process=":UnityKillsMe" to the unity activity GameActivity.

查看更多
戒情不戒烟
4楼-- · 2019-02-20 08:20

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. Export Android project via Unity build settings

enter image description here

  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.

  2. 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'.

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

  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.category.LAUNCHER

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

  1. Finally in your settings.gradle add the module and then add the Unity project dependency on your "app" module: compile project(':UnityFolder')

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

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

    startActivity(intent);

查看更多
登录 后发表回答