Unity Android Plugin Tutorial Series part2- Let’s override Unity

In the second part of this tutorial series, we are going to override Unity. So what is the purpose or benefits of overriding Unity player and what can you accomplish with that?

  • You can socialize your game!! You can make Facebook or Twitter logins, or better you can add achievements, multiplayer etc.. with Google Play Game Services, cool stuff!
  • Maybe want to use Google Maps?
  • Accessing hardware camera, croping images
  • Implementing sqlite database, app analytics for your game, push notifications and list goes on like this.

Now lets start with easy stuff. Actually Unity’s documentation is pretty well explains how to do it. You can check the document from here: http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html . I’ m also going to cover that document again. Before we begin I have to say again I’m using Eclipse for java development, I recommend you to do so, and also I assume that you have already made your Android sdk setup.

  • To override Unity player first you need “classes.jar” that contains Unity classes. You can find that jar inside /Applications(or ProgramFiles)/Unity/PlaybackEngines/AndroidPlayer/bin folder. Copy it somewhere you can find it easily.
  • Next open up the Eclipse and create a new android project or we can use our previous project from last tutorial. Name your activity whatever you want I prefer GameActivity usually. After creating your project, right click on your project and open properties from package explorer. Select “Java Build Path” from left and select libraries tab. Click on “Add External Jars” and choose your “classes.jar” file that you have copied.

tuto_series2_1

  • Now open your activity class(I named it MainActivity for this tutorial) and instead of extending “Activity class” extend it with “UnityPlayerActivity”, now you can use UnityClasses. After that delete “setContentView(int) from your “onCreate” method you won’t be needing that line. And print something to console.

tut_2_2

  • You have now successfully overrided Unity player. Like last tutorial select your “MainActivity.java” file and export it as .jar document into your “Plugins/Android” folder.screen-shot-2014-01-17-at-23-53-56-2 (1)
  • One last to be able to run this on Unity Android. You need to also override your AndroidManifest.xml file. If you export as Android Google Project from build settings you can find your manifest inside from the eclipse project or from Unity docs .It should be like this:

tut_2-4

  • Just don’t forget to change your ActivityName and your package name(see the image above). Save the xml and add it also to your “Plugins/Android” folder inside Unity. It’s that simple… Build and run your application and you will get a log text “Overrided activity” when your app starts.

You can download and take a look at the files from here : https://www.dropbox.com/sh/gguo3pigy132ctq/gpQuDlMrM4

On next tutorials I’ show some useful methods for your android game and how to call them. Cheers…

If you like this article please support my work on Patreon, thank you!

Advertisement

5 thoughts on “Unity Android Plugin Tutorial Series part2- Let’s override Unity

Add yours

  1. Sorry, I am new… I received some error in the MainActivity.java..when following this quide
    Iayout cannot be resolved or is not a field (R.layout.activity_main)

    and I have to import android.os.Bundle; and andrroid.util.Log to fix some errors…but I can’t see them imported in the example…am I doing something wrong?

  2. You need to delete the line, “setContentView(R.layout.activity_main);” to make it work actually.
    And on Eclipse you can click Ctrl+Shift+O for auto importing so you don’t need to worry about those.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: