{"id":13456880,"url":"https://github.com/azesmway/react-native-unity","last_synced_at":"2025-04-12T21:24:49.635Z","repository":{"id":37373722,"uuid":"475486961","full_name":"azesmway/react-native-unity","owner":"azesmway","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-31T18:35:43.000Z","size":2799,"stargazers_count":268,"open_issues_count":85,"forks_count":64,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-10-16T11:32:57.575Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azesmway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-29T14:44:25.000Z","updated_at":"2024-10-09T13:34:15.000Z","dependencies_parsed_at":"2023-11-22T19:27:13.260Z","dependency_job_id":"d2311162-92b8-4b39-a445-c14ce30e0525","html_url":"https://github.com/azesmway/react-native-unity","commit_stats":{"total_commits":97,"total_committers":12,"mean_commits":8.083333333333334,"dds":"0.23711340206185572","last_synced_commit":"40279d78b61ea12ec1d3514b2b6d8fc72c95b3e3"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azesmway%2Freact-native-unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azesmway%2Freact-native-unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azesmway%2Freact-native-unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azesmway%2Freact-native-unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azesmway","download_url":"https://codeload.github.com/azesmway/react-native-unity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248633163,"owners_count":21136818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:01:29.454Z","updated_at":"2025-04-12T21:24:49.611Z","avatar_url":"https://github.com/azesmway.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# @azesmway/react-native-unity\n\nThe plugin that allows you to embed a Unity project into React Native as a full-fledged component. The plugin now supports the new architecture.\n\n### Android\nAttention! Added support for Unity 2023 and above\n\n\u003e [!IMPORTANT]\n\u003e 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 - `\u003cYOUR_RN_PROJECT\u003e/unity/builds/ios`\n\n## Device Support:\n\n| Platform         | Supported |\n| ---------------- | --------- |\n| iOS Simulator    | ❌        |\n| iOS Device       | ✅        |\n| Android Emulator | ✅        |\n| Android Device   | ✅        |\n\n# Installation\n\n## Install this package in your react-native project:\n\n```sh\nnpm install @azesmway/react-native-unity\n\nor\n\nyarn add @azesmway/react-native-unity\n```\n\n## Configure your Unity project:\n\n1. 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.\n\n2. (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.\n\n\u003cdetails\u003e\n\u003csummary\u003eButtonBehavior.cs\u003c/summary\u003e\n\n```csharp\nusing System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Runtime.InteropServices;\nusing UnityEngine.UI;\nusing UnityEngine;\n\npublic class NativeAPI {\n#if UNITY_IOS \u0026\u0026 !UNITY_EDITOR\n  [DllImport(\"__Internal\")]\n  public static extern void sendMessageToMobileApp(string message);\n#endif\n}\n\npublic class ButtonBehavior : MonoBehaviour\n{\n  public void ButtonPressed()\n  {\n    if (Application.platform == RuntimePlatform.Android)\n    {\n      using (AndroidJavaClass jc = new AndroidJavaClass(\"com.azesmwayreactnativeunity.ReactNativeUnityViewManager\"))\n      {\n        jc.CallStatic(\"sendMessageToMobileApp\", \"The button has been tapped!\");\n      }\n    }\n    else if (Application.platform == RuntimePlatform.IPhonePlayer)\n    {\n#if UNITY_IOS \u0026\u0026 !UNITY_EDITOR\n      NativeAPI.sendMessageToMobileApp(\"The button has been tapped!\");\n#endif\n    }\n  }\n}\n```\n\n\u003c/details\u003e\n\n## Export iOS Unity Project:\n\nAfter you've moved the files from the `unity` folder to your Unity project, you can export the iOS unity project by following these steps:\n\n1. Open your Unity project\n2. Build Unity project for ios in ANY folder - just not the main RN project folder!!!\n3. Open the created project in XCode\n4. Select Data folder and set a checkbox in the \"Target Membership\" section to \"UnityFramework\" ![image info](./docs/step1.jpg)\n5. 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) ![image info](./docs/step2.jpg)\n6. If required - sign the project `UnityFramework.framework` and build a framework ![image info](./docs/step3.jpg)\n7. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (`\u003cYOUR_RN_PROJECT\u003e/unity/builds/ios`) ![image info](./docs/step4.jpg)\n8. Remove your `Pods` cache and lockfile with this command in the root of the main RN project `rm -rf ios/Pods \u0026\u0026 rm -f ios/Podfile.lock \u0026\u0026 npx pod-install`\n\n### Android\n\n1. Open your Unity project\n2. Export Unity app to `\u003cYOUR_RN_PROJECT\u003e/unity/builds/android`\n3. Remove `\u003cintent-filter\u003e...\u003c/intent-filter\u003e` from `\u003cYOUR_RN_PROJECT\u003e/unity/builds/android/unityLibrary/src/main/AndroidManifest.xml` at unityLibrary to leave only integrated version.\n\nIf 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.\n\n1. Add the following lines to `android/settings.gradle`:\n   ```groovy\n   include ':unityLibrary'\n   project(':unityLibrary').projectDir=new File('..\\\\unity\\\\builds\\\\android\\\\unityLibrary')\n   ```\n2. Add into `android/build.gradle`\n   ```groovy\n   allprojects {\n     repositories {\n       // this\n       flatDir {\n           dirs \"${project(':unityLibrary').projectDir}/libs\"\n       }\n       // ...\n     }\n   }\n   ```\n3. Add into `android/gradle.properties`\n   ```gradle\n   unityStreamingAssets=.unity3d\n   ```\n4. Add strings to `android/app/src/main/res/values/strings.xml`\n\n   ```javascript\n   \u003cstring name=\"game_view_content_description\"\u003eGame view\u003c/string\u003e\n   ```\n\n# Known issues\n\n- Does not work on the iOS simulator.\n- On iOS the Unity view is waiting for a parent with dimensions greater than 0 (from RN side). Please take care of this because if it is not the case, your app will crash with the native message `MTLTextureDescriptor has width of zero`.\n\n# Usage\n\n## Sample code\n\n```jsx\nimport React, { useRef, useEffect } from 'react';\n\nimport UnityView from '@azesmway/react-native-unity';\nimport { View } from 'react-native';\n\ninterface IMessage {\n  gameObject: string;\n  methodName: string;\n  message: string;\n}\n\nconst Unity = () =\u003e {\n  const unityRef = useRef\u003cUnityView\u003e(null);\n\n  useEffect(() =\u003e {\n    if (unityRef?.current) {\n      const message: IMessage = {\n        gameObject: 'gameObject',\n        methodName: 'methodName',\n        message: 'message',\n      };\n      unityRef.current.postMessage(\n        message.gameObject,\n        message.methodName,\n        message.message\n      );\n    }\n  }, []);\n\n  return (\n    \u003cView style={{ flex: 1 }}\u003e\n      \u003cUnityView\n        ref={unityRef}\n        style={{ flex: 1 }}\n        onUnityMessage={(result) =\u003e {\n          console.log('onUnityMessage', result.nativeEvent.message);\n        }}\n      /\u003e\n    \u003c/View\u003e\n  );\n};\n\nexport default Unity;\n```\n\n## Props\n\n- `style: ViewStyle` - styles the UnityView. (Won't show on Android without dimensions. Recommended to give it `flex: 1` as in the example)\n- `onUnityMessage?: (event: NativeSyntheticEvent)` - receives a message from a Unity\n- `androidKeepPlayerMounted?: boolean` - if set to true, keep the player mounted even when the view that contains it has lost focus. The player will be paused on blur and resumed on focus. **ANDROID ONLY**\n- `fullScreen?: boolean` - defaults to true. If set to false, will not request full screen access. **ANDROID ONLY**\n\n## Methods\n\n- `postMessage(gameObject, methodName, message)` - sends a message to the Unity. **FOR IOS:** The native method of unity is used to send a message\n  `sendMessageToGOWithName:(const char*)goName functionName:(const char*)name message:(const char*)msg;`, more details can be found in the [documentation](https://docs.unity3d.com/2021.1/Documentation/Manual/UnityasaLibrary-iOS.html)\n- `unloadUnity()` - the Unity is unloaded automatically when the react-native component is unmounted, but if you want to unload the Unity, you can call this method\n- `pauseUnity?: (pause: boolean)` - pause the Unity\n- `windowFocusChanged(hasFocus: boolean = false)` - simulate focus change (intended to be used to recover from black screen (not rendering) after remounting Unity view when `resumeUnity` does not work) **ANDROID ONLY**\n\n# Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazesmway%2Freact-native-unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazesmway%2Freact-native-unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazesmway%2Freact-native-unity/lists"}