Unity and Eclipse Integration

Hi guys, I need a little help with Unity integration in Eclipse

My help page: => here

I have a Unity3D Pro version and an Android Plugin Pro version

  • Set up your Android Unity project as usual and click Build.
  • Enter the project folder, go to the Temp / StagingArea page.
  • Copy all project files to a new folder.
  • Import this folder into a new Android project in Eclipse.
  • Mark this project as a library in the properties window for the project. (Right-click on the project name, go to "Properties"> "Android" and check "Library".)
  • Create a new Android project in Eclipse. This will be the Java part of your project.
  • Add the Unity Android project as a library to the new project. (Right-click on the name of the project, open "Properties-> Android", select "Add ...", add the project.)
  • Add the classes.jar library to the library links for your new project. (In the properties, go to Java_Build_path-> Libraries, select "Add external jar ...", go to UNITY_INSTALLATION \ Editor \ Data \ PlaybackEngines \ and roidplayer \ bin and add classes.jar)

Now, if I run this small project on my device, I get something like this

You can see the image at this link.

https://copy.com/vVaCyQTEUECV

The next step:

  • . (Android , , Unity .)

res .

AndroidMnifest.xml

MainActivity.java

package com.Developer.PackMan;

import com.unity3d.player.UnityPlayerNativeActivity;


import android.os.Bundle;

public class MainActivity extends UnityPlayerNativeActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

}
}

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.Developer.PackMan" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-feature android:name="android.hardware.sensor.accelerometer" />
</manifest>

) com.Developer.Packman) , .

, LogCat Console, .

. .

+4
2

, Unity3d, Android, . AFAIR Unity3d 4.3. , :)

: http://forum.unity3d.com/threads/98315-Using-Unity-Android-In-a-Sub-View/page4?p=1477830&viewfull=1#post1477830

https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse

Pre-:

Unity3d Android, classes.jar, '... Unity\Editor\Data\PlaybackEngines\androidplayer\bin'. .

:

  • Android-, Android .
  • Android Unity3d. Unity , Android-.
  • RMB Unity, "" , "Android" "Is ? ".
  • RMB Android, "" , "Android" "", - Unity - Android.
  • "" " Java" "". " JAR" . Jar .
  • , SDK.
  • "" Unity Android. Unity.

Coding:

, - Android, Unity, Android.

  • : '.
  • , Unity: '. Unity, Android.
  • , UnityPlayerActivity, Activity.
  • 'setContentView onCreate() - - Unity ; onResume() UnityPlayer . , , .

:

  • NoClassDefFoundException ( ) , UnityPlayerActivity: " Android-", " Java" → " " "class.jar" ( , ). OK, , ...
  • dex Lcom/unity3d/player/nativeloader - , "libs" Unity "unity-classes.jar".
  • ( , ) src - src

Activity, Unity3d:

private Button buttonChangeColour;
private UnityPlayer unityPlayer = null;

@Override
public void onResume() {

    super.onResume();

    if (unityPlayer == null) {

        View rootView = findViewById(android.R.id.content);
        unityPlayer = findUnityPlayerView(rootView);

        if (unityPlayer != null) {

            ViewGroup unityPlayerParentView = (ViewGroup)(unityPlayer.getParent());
            View mainHomeView = getLayoutInflater().inflate(R.layout.activity_home, null);
            LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            unityPlayerParentView.addView(mainHomeView, layoutParams);

            buttonChangeColour = (Button) findViewById(R.id.buttonChangeColour);
            buttonChangeColour.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // [...]
                }
            });
        }
    }
}

private UnityPlayer findUnityPlayerView(View view) {

    if (view instanceof UnityPlayer) {

        return (UnityPlayer) view;
    }
    if (view instanceof ViewGroup) {

        ViewGroup childrenViews = (ViewGroup) view;

        for (int i = 0; i < childrenViews.getChildCount(); i++) {

            UnityPlayer foundView = findUnityPlayerView(childrenViews.getChildAt(i));

            if (foundView != null) {

                return foundView;
            }
        }
    }

    return null;
}
+5

Unity ? 4.X eclipse

, , eclipse.

+1

Source: https://habr.com/ru/post/1534823/


All Articles