Software Architect & Consultant
Web / Mobile / VR / AR / IoT / Blockchain
Rendering
AI
Physics engine
Sound engine
Networking
Concept art
Creative assets
Level design
Animations
Gameplay mechanics
Post processing
https://unity.com/features/mobile
JS
Native
Unity as a library
GameObject in Unity
Method name to call
Payload
Native iOS Plugin
NativeCallProxy.h
In Unity Project under Assets/Plugins/iOS create two files
NativeCallProxy.mm
ButtonBehavior.cs
public static extern void sendMessageToMobileApp(string message);
NativeAPI.sendMessageToMobileApp("The button has been tapped!");
Assign script to gameObject in Unity and click handler to button in Unity
We need to parse JSON we receive from RN
RNInterop.cs
RNInterop.cs
Build Unity Project for iOS into folder within your RN project
unity/builds/ios
Open Xcode workspace of your React Native project
ios/rnunitynative.xcworkspace
right click and add Files to workspace. Select Unity Project
Add UnityFramework to Embedded Frameworks,
Remove UnityFramework from Build Phases Link Binary with Libraries
Drag and drop Embed Frameworks before Compile sources
1. Change Data membership to be UnityFramework
2.Change build products path for UnityFramework to be your RN ios build folder
3.Change Native Plugins Target membership to UnityFramework & Public
4.Build UnityFramework separately
Create
ReactNativeUnityViewManager.mm
Expose module to JS
Export view property to be callback
Create separate class for ReactNativeUnityView
Expose postMessage method to JS
Send events to JS
Make sure we run on main thread
UnityFramework API to call method by name
ReactNativeUnityView.mm
Framework wrapper to handle loading and options
There is a library for that! 😉
No need to write Native code
Still need to do all the setup and build steps
Now you know how it actually works 🎉
Demo code
Learn unity
Unity Asset store
Reach out on twitter @vladimirnovick or schedule consulting at vnovick.com