react-native-unity | React Native package to use Unity as library with RN app | Frontend Framework library
kandi X-RAY | react-native-unity Summary
kandi X-RAY | react-native-unity Summary
React Native package to use Unity as library with RN app
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of react-native-unity
react-native-unity Key Features
react-native-unity Examples and Code Snippets
#import
+++ #import
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
+++ [RNUnity setArgc:argc];
+++ [RNUnity setArgv:argv];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate clas
import { Unity, UnityResponderView } from '@wowmaking/react-native-unity';
Unity.init();
const App = () => {
return (
Unity.execCommand('command_name', { /* any specific command data */ })}>Press ME!
);
};
Community Discussions
Trending Discussions on react-native-unity
QUESTION
I'm a React Native noob.
I just integrated my Unity3D app with the React Native app using nreact-native-unity-view
(https://github.com/nhancv/nreact-native-unity-view)
ANSWER
Answered 2020-Oct-11 at 18:07The easiest way is to use the stack navigator and have a separate page for the unity screen. https://reactnavigation.org/docs/stack-navigator/
the code to navigate would be navigation.navigate('screenname'); This code wont work until you sort the imports related to unity and related items.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install react-native-unity
Install package via npm
Move your Unity project to unity folder at project root
Add following line at your unity/Packages/manifest.json { ... "com.wowmaking.react-native-unity": "file:../../node_modules/@wowmaking/react-native-unity/unity" }
To receive commands from JavaScript, you must create another game object, or use existing. Commands receiver object must implements IRNCommandsReceiver interface using Wowmaking.RNU; public class NewGameObject : MonoBehaviour, IRNCommandsReceiver { ... }
Set your object as commands receiver to RNBridge on Awake using Wowmaking.RNU; public class NewGameObject : MonoBehaviour, IRNCommandsReceiver { private void Awake() { RNBridge.RegisterCommandsReceiver(this); } }
Implement IRNCommandsReceiver interface by adding HandleCommand method using Wowmaking.RNU; public class NewGameObject : MonoBehaviour, IRNCommandsReceiver { private void Awake() { RNBridge.RegisterCommandsReceiver(this); } public void HandleCommand(RNCommand command) { switch (command.name) { // command.Resolve(new {}) || command.Reject(new {}) } } } IMPORTANT! Call Resolve or Reject method of received RNCommand instance to remove it from JavaScript thread
Go to Menu -> Edit -> Project setings... -> Player -> iOS -> Other Settings
Find Target SDK setting and select Simulator SDK
Run pod install
Build Unity app to [project_root]/unity/builds/ios
Add Unity-iPhone.xcodeproj to your workspace: Menu -> File -> Add Files to [workspace_name]... -> [project_root]/unity/builds/ios/Unity-iPhone.xcodeproj
Add UnityFramework.framework to Embedded Binaries: select your_app target in workspace in General / Embedded Binaries press + select Unity-iPhone/Products/UnityFramework.framework remove UnityFramework.framework from Linked Frameworks and Libraries ( select it and press - ) in Build Phases move Embedded Binaries before Compile Sources ( drag and drop )
In AppDelegate.m file make background color of React root view transparent
Add ndk support into android/app/build.gradle defaultConfig { ... 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")
Change parent activity in MainActivity.java from ReactActivity to UnityReactActivity import com.wowmaking.rnunity.UnityReactActivity; public class MainActivity extends UnityReactActivity { ... }
Add strings to res/values/strings.xml <string name="game_view_content_description">Game view</string> <string name="unity_root">unity_root</string>
Update .MainActivity into AndroidManifest.xml <activity android:name=".MainActivity" ... android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="true" android:launchMode="singleTask" >
Setup minSdkVersion greater than or equal to 19
Remove <intent-filter>...</intent-filter> from AndroidManifest.xml at unityLibrary to leave only integrated version.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page