百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-native-unity

> 编程语言
开源

@azesmway/react-native-unity 这个插件允许您将 Unity 项目嵌入到 React Native 中,作为一款完整的组件。该插件 ...

385 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

@azesmway/react-native-unity 这个插件允许您将 Unity 项目嵌入到 React Native 中,作为一款完整的组件。该插件 ...

@azesmway/react-native-unity

The plugin that allows you to embed a Unity project into React Native as a full-fledged component. The plugin now supports the new architecture.

Android

Attention! Added support for Unity 2023 and above

[!IMPORTANT] For iOS, it is no longer necessary to embed a project created with Unity. Only the built UnityFramework is used. It should be placed in the plugin folder at the path - /unity/builds/ios

Device Support:

Platform Supported
iOS Simulator ⚠️ optional (see iOS Simulator support)
iOS Device ✅
Android Emulator ✅
Android Device ✅

The iOS Simulator works only with the optional XCFramework export described below; the default device-only UnityFramework.framework does not link on the simulator.

Installation

Install this package in your react-native project:

bash
npm install @azesmway/react-native-unity

or

yarn add @azesmway/react-native-unity

Configure your Unity project:

  1. Copy the contents of the folder unity to the root of your Unity project. This folder contains the necessary scripts and settings for the Unity project. You can find these files in your react-native project under node_modules/@azesmway/react-native-unity/unity. This is necessary to ensure iOS has access to the NativeCallProxy class from this library.

  2. (optional) If you're following along with the example, you can add the following code to the ButtonBehavior.cs script in your Unity project. This allows the button press in Unity to communicate with your react-native app.

ButtonBehavior.cs

…

Export iOS Unity Project:

After you've moved the files from the unity folder to your Unity project, you can export the iOS unity project by following these steps:

  1. Open your Unity project
  2. Build Unity project for ios in ANY folder - just not the main RN project folder!!!
  3. Open the created project in XCode
  4. Select Data folder and set a checkbox in the "Target Membership" section to "UnityFramework"
  5. You need to select the NativeCallProxy.h inside the Unity-iPhone/Libraries/Plugins/iOS folder of the Unity-iPhone project and change UnityFramework’s target membership from Project to Public. Don’t forget this step! (if you don't see these files in your Xcode project, you didn't copy over the unity folder to your Unity project correctly in previous steps)
  6. If required - sign the project UnityFramework.framework and build a framework
  7. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (/unity/builds/ios)
  8. Remove your Pods cache and lockfile with this command in the root of the main RN project rm -rf ios/Pods && rm -f ios/Podfile.lock && npx pod-install

Android

  1. Open your Unity project
  2. Export Unity app to /unity/builds/android
  3. Remove ... from /unity/builds/android/unityLibrary/src/main/AndroidManifest.xml at unityLibrary to leave only integrated version.

If you're using expo, you're done. The built-in expo plugin will handle the rest. If you're not using expo, you'll need to follow the steps below.

  1. Add the following lines to android/settings.gradle:

    groovy
    include ':unityLibrary'
    project(':unityLibrary').projectDir=new File('..\\\unity\\builds\\android\\\unityLibrary')
  2. Add into android/build.gradle

    groovy
    allprojects {
      repositories {
        // this
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
        // ...
      }
    }
  3. Add into android/gradle.properties

    gradle
    unityStreamingAssets=.unity3d
  4. Add strings to android/app/src/main/res/values/strings.xml

    javascript
    Game view

Android AR (ARCore) permission

If your Unity project uses AR — AR Foundation / ARCore — add this permission to android/app/src/main/AndroidManifest.xml. This applies to expo users too: the config plugin does not add it, so declare it through android.permissions in app.json.

xml

Since Android 12 (API 31), an app targeting API 31+ needs this permission to read sensors faster than 200 Hz. ARCore requests the IMU at its maximum rate — 500 Hz on many devices — so without it the sensor registration is rejected, the ARCore session never starts and the camera stays black. In logcat it looks like this:

bash
Failed to register sensor to queue 0
...
ArPresto::Moving from ArPrestoStatus 102 to 200
operator(): width ` can hide the system navigation bar for the whole app (immersive sticky mode — the bar reappears on swipe, then hides again). The `fullScreen` prop only controls the status bar flag; change `Fullscreen Mode` / `Status Bar Hidden` in Unity's Player Settings, or set `Screen.fullScreen = false` in your scene.

# Usage

## Sample code

```jsx
import React, { useRef, useEffect } from 'react';

import UnityView from '@azesmway/react-native-unity';
import { View } from 'react-native';

interface IMessage {
  gameObject: string;
  methodName: string;
  message: string;
}

const Unity = () => {
  const unityRef = useRef(null);

  useEffect(() => {
    if (unityRef?.current) {
      const message: IMessage = {
        gameObject: 'gameObject',
        methodName: 'methodName',
        message: 'message',
      };
      unityRef.current.postMessage(
        message.gameObject,
        message.methodName,
        message.message
      );
    }
  }, []);

  return (
    
       {
          console.log('onUnityMessage', result.nativeEvent.message);
        }}
      />
    
  );
};

export default Unity;

…

bash
sh
xcodebuild -project device-export/Unity-iPhone.xcodeproj -scheme UnityFramework \
  -configuration Release -sdk iphoneos BUILD_DIR="$PWD/device-build" build
xcodebuild -project simulator-export/Unity-iPhone.xcodeproj -scheme UnityFramework \
  -configuration Release -sdk iphonesimulator BUILD_DIR="$PWD/simulator-build" build
xcodebuild -create-xcframework \
  -framework device-build/Release-iphoneos/UnityFramework.framework \
  -framework simulator-build/Release-iphonesimulator/UnityFramework.framework \
  -output /unity/builds/ios/UnityFramework.xcframework
  1. Reinstall pods. The App Store build is unaffected: Xcode links only the device slice, so the shipped app size does not change.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言