UNITY PLAYER SETTINGS
Multitasking->Requires Fullscreen-> no selection set !Status Bar->Status Bar Hidden-> no selection set !Other Settings->Target SDK-> selectDevice SDKorSimulator SDK
BUILD SETTINGS
Export project-> selection set !
UNITY PLAYER SETTINGS
Resolution and Presentation->Fullscreen Mode-> selectWindowedResolution and Presentation->Resizable Window-> selection set !Resolution and Presentation->Hide Navigation Bar-> no selection set !Resolution and Presentation->Render outside safe area-> no selection set !Other Settings->Scripting Backend-> selectIL2CPPOther Settings->Target Architectures->ARM64-> selection set !
- Install
react-native-unity2vianpm - Move your Unity project to
unityfolder at project root
- Run
pod install - Build Unity app to
[project_root]/unity/builds/ios
NB: Remember to build the Xcode project generated by Unity first, because an intact UnityFramework.framework is required to successfully build your workspace afterwards.
- Add
Unity-iPhone.xcodeprojto your workspace:Menu->File->Add Files to [workspace_name]...->[project_root]/unity/builds/ios/Unity-iPhone.xcodeproj - Add
UnityFramework.frameworktoFrameworks, Libraries, and Embedded Content:- select
your_apptarget in workspace - in
General/Frameworks, Libraries, and Embedded Contentpress+ - select
Unity-iPhone/Products/UnityFramework.framework - in
Build PhasesremoveUnityFramework.frameworkfromLinked Frameworks and Libraries( select it and press-) - in
Build PhasesmoveEmbedded FrameworksbeforeCompile Sources( drag and drop )
- select
- Add
DatatoCopy Bundle Resources- select
Unity-iPhoneproject in workspace - select
UnityFrameworkin targets - in
Build PhasesaddDatatoCopy Bundle Resources
- select
Click to expand!
Add the following lines to your main.m file
#import <UIKit/UIKit.h>
+++ #import <RNUnity/RNUnity.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
+++ [RNUnity setArgc:argc];
+++ [RNUnity setArgv:argv];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}Add the following lines to your AppDelegate.mm file
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
+++ #import <RNUnity/RNUnity.h>
+++ - (void)applicationWillResignActive:(UIApplication *)application { [[[RNUnity ufw] appController] applicationWillResignActive: application]; }
+++ - (void)applicationDidEnterBackground:(UIApplication *)application { [[[RNUnity ufw] appController] applicationDidEnterBackground: application]; }
+++ - (void)applicationWillEnterForeground:(UIApplication *)application { [[[RNUnity ufw] appController] applicationWillEnterForeground: application]; }
+++ - (void)applicationDidBecomeActive:(UIApplication *)application { [[[RNUnity ufw] appController] applicationDidBecomeActive: application]; }
+++ - (void)applicationWillTerminate:(UIApplication *)application { [[[RNUnity ufw] appController] applicationWillTerminate: application]; }
@endClick to expand!
Make the following changes to your AppDelegate.swift file
@UIApplicationMain
class AppDelegate: UIApplicationDelegate {
init() {
RNUnity.initFromSwift()
}
func applicationWillResignActive(_ application: UIApplication) {
RNUnity.applicationWillResignActive(application)
}
func applicationDidEnterBackground(_ application: UIApplication) {
RNUnity.applicationDidEnterBackground(application)
}
func applicationWillEnterForeground(_ application: UIApplication) {
RNUnity.applicationWillEnterForeground(application)
}
func applicationDidBecomeActive(_ application: UIApplication) {
RNUnity.applicationDidBecomeActive(application)
}
func applicationWillTerminate(_ application: UIApplication) {
RNUnity.applicationWillTerminate(application)
}
}-
Create directory into
android/app/libs -
Copy libs from
<project_name>/unity/builds/android/unityLibrary/libs/*toandroid/app/libs -
Add ndk support into
android/app/build.gradledefaultConfig { ... ndk { abiFilters "armeabi-v7a", "arm64-v8a" } }
-
Append the following lines to
android/settings.gradle:include ':unityLibrary' project(':unityLibrary').projectDir=new File('..\\unity\\builds\\android\\unityLibrary')
-
Insert the following lines inside the dependencies block in
android/app/build.gradle:implementation project(':unityLibrary') implementation files("${project(':unityLibrary').projectDir}/libs/unity-classes.jar")
-
Add strings to
res/values/strings.xml<string name="game_view_content_description">Game view</string> <string name="unity_root">unity_root</string>
-
Update
.MainActivityintoAndroidManifest.xml<application ... android:extractNativeLibs="true" <activity android:name=".MainActivity" ... android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="true" >
-
Setup
minSdkVersiongreater than or equal to21 -
Remove
<intent-filter>...</intent-filter>from<project_name>/unity/builds/android/unityLibrary/src/main/AndroidManifest.xmlat unityLibrary to leave only integrated version. -
Add to
android/gradle.propertiesunityStreamingAssets=.unity3d
-
Add to
build.gradleallprojects { repositories { flatDir { dirs "$rootDir/app/libs" }
-
<project_name>/unity/builds/android/unityLibrary/src/main/AndroidManifest.xmldeleteandroid:icon="@mipmap/app_icon"andandroid:theme="@style/UnityThemeSelector"if they are installed