Creating live wallpaper in Unity

This post is part of my series on Android live wallpapers.
Visit my other blog posts where I cover creating live wallpapers in:

Templates for all three technologies are on my repository:
https://github.com/dbeef/CreatingAndroidLiveWallpapers


After covering live wallpapers in Android Studio (which I recommend to see, for the sake of having reference to the concepts I will use in this post) I had some understanding of what I want to do in Unity, which was:

  • Overriding default AndroidManifest.xml that Unity creates
  • Add one custom Java class, that I will reference from overriden manifest
  • Add another resource xml file

Additionally, as Unity creates its own Activity when exporting as Android Project, I wanted to reference that activity from my Service declared in Java class, so I could render Unity scene when running as wallpaper.

So I created a clean new Unity project and set-up building to Android.

After quick Googling it looked adding my custom Android-specific code to Unity project will be essentially… Creating Assets/Plugins/Android directory (from root of the project) and copying my files there.

When listing files from that directory:

listing_unity

So what I did was copying res, *.java files from of my Android Studio project, omitting SimpleWallpaperActivity.java, as Unity provides its own Activity.

I also omitted AndroidManifest.xml file – as the one provided by Unity (when exporting as Android project) was a bit bloated and it would be more efficient to just copy very specific content that I needed into Unity’s – I copied whole service tag from my Android Studio project and uses-feature tag.

What was still needed at this point is to reference Unity’s activity to render the scene.
As normally I don’t use Unity I gave up after some time and found out existing wallpaper service that utilizes Unity’s activity by PavelDoGreat:

https://github.com/PavelDoGreat/Unity-Android-Live-Wallpaper/blob/master/WallpaperActivity.java

Keeping package name consistent within Unity and overriden classes that I supplied was essential, otherwise some symbols can be undefined.

You can set package name in Unity’s:
Edit -> Project Settings -> Player.

What then? Just hit Unity’s Build and run.

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 )

Google photo

You are commenting using your Google 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