The Xamarin/Unity 3D integration for Android and iOS, as developed by Florian Auer from Arau Consulting, provides a highly effective, simple, but practical method to leverage the power of both frameworks to build robust, user-friendly, cross-platform mobile applications with easy-to-use 3D rendering and physics.
However, as described below, integrating Unity 3D and Xamarin is not native to either framework. As a result, utilizing both together for mobile game development was impossible. This changed in 2019 when Unity published their “Unity-as-a-library” framework (Unity 2019.3.02a), making it possible to integrate a View running Unity3D in an existing Android or iOS app. Auer subsequently developed the binding to leverage the best features from both Xamarin and Unity when developing mobile game apps for Android and iOS.
Let’s expand on this topic by introducing Xamarin and Unity 3D before looking at the functionality Florian Auer (Arau Consulting) has developed and open-sourced.
Introducing Xamarin for iOS and Android
As far back as 2000, Microsoft introduced the .NET software development framework, including C#, a new programming language. Soon afterward, development on Mono started and was led by Miguel de Icaza. Its original aim was to provide C# development tools for Linux. However, this project soon evolved into delivering a cross-platform runtime for .NET.
Fast forward to 2011, Xamarin, a new company, took over the development and maintenance of Mono for Android and MonoTouch (for iOS). In 2016, Microsoft signed an agreement to acquire Xamarin. The value that Xamarin iOS and Xamarin Android brings to the developer’s toolbox is that they have a shared C# codebase, providing developers with the functionality to write device-specific (or platform-specific) iOS and Android apps using native user interfaces, sharing code across various platforms, including Linux, Android, Windows, iOS, and macOS.
From a technical perspective, Xamarin for iOS and Android are cross-platform implementations of the CLI or Common Language Infrastructure, also known as .NET.
An introduction to Unity 3D
Unity or Unity 3D is a cross-platform game engine first released in June 2005 and developed by Unity Technologies. It was initially developed for macOS, but it has since been extended to support multiple platforms, including iOS and Android. Wikipedia.com notes that an exceptionally popular Unity 3D use case is mobile game development, especially iOS and Android. Examples of notable games include Pokémon Go and Call of Duty: Mobile. Lastly, it is also popular with Indie game developers because it is simple for beginner game developers.
![](https://ml6ngtmlwmxb.i.optimole.com/cb:Kwzr~4e42b/w:676/h:246/q:mauto/f:best/ig:avif/https://araucon.com/wp-content/uploads/2021/08/Official_unity_logo.png)
Developers can use Unity to develop both 2D and 3D games. Additionally, one of the programming languages used to build mobile game apps is C#. Therefore, because both Xamarin and Unity 3D use C# as their development language and Unity utilizes Mono to compile Android and iOS apps, it stands to reason that they might be compatible. Or not?
Unity and Xamarin are not compatible in their original formats, even though Unity uses a pre-Xamarin variant of Mono as a foundation to compile Android and iOS apps. Therefore, it is reasonable to assume that using Xamarin and Unity 3D to develop mobile applications will be challenging.
Unity 3D/Xamarin integration for iOS and Android
As noted at the top of his article, Florian Auer of Arau Consulting has open-sourced his solution to this integration. Therefore, let’s expand on this statement by considering the functionality that he has included in his two open-source projects:
1. The Xamarin Unity Forms project for Xamarin iOS and Android
The source code for this project, titled UnityView4Xamarin.Forms, is found on GitHub.
The original Android Xamarin/Unity binding project, titled Xamarin with Unity App, was developed and published on Github by Egor Bogatov.
This project also includes the code and functionality that allows Android developers to use both Unity and Xamarin in a single application to bind to ARCore objects as developed by Egor Bogotov. Succinctly stated, ARCore is a Google product, and its primary function is mainly to create augmented reality experiences on Android devices.
The Xamarin iOS binding project, developed by Florian Auer, is described in point 2 below.
Additionally, the Unity4Xamarin.Forms project bundles both Xamarin.Android and Xamarin.iOS together with an abstraction layer for Xamarin.Forms.
2. The Xamarin iOS binding project
Succinctly stated, this project, as found on GitHub, extends the functionality of the Unity Xamarin Forms project for iOS (point 1 above); specifically, the Unity forms player.
At this juncture, it is vital to note that there are manual steps required to run Unity with Xamarin for iOS. In summary, it must be built and run as a library using code from Unity3D that can be found on GitHub.
In summary, the steps are as follows:
- Open the Unity project and export as an iOS build.
- Modify the build files according to the code found in the Build iOS Modifications subdirectory.
- Lastly, adhere strictly to the step-by-step explanations found in the docs/ios.md file.
Why?
There are several reasons for this, predominantly to reduce the Unity Framework API endpoint code, simplifying the binding process.
Final thoughts
There is no doubt that Florian Auer’s solution to the Unity 3D/Xamarin integration problem is simple, easy-to-use, understandable, and comprehensively solves the problem. Therefore, the only thing left to do is clone all three projects described above and start developing your own mobile app with state of the art 3D rendering for iOS and Android.
Lastly, these projects are ongoing. They have not been concluded, and help will be appreciated to resolve some of the issues tagged in the GitHub repo.
Everything is very open with a precise clarification of the challenges. It was really informative. Your website is useful. Thanks for sharing!
Very good write-up. I absolutely love this website. Continue the good work!