You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+75-58
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,22 @@
1
1
# @azesmway/react-native-unity
2
2
3
-
The plugin that allows you to embed a UNITY project into the react native as a full-fledged component
3
+
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.
4
4
5
-
### ATTENTION!
5
+
> [!IMPORTANT]
6
+
> 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 - `<YOUR_RN_PROJECT>/unity/builds/ios`
6
7
7
-
The plugin now supports the new architecture as well.
8
-
For iOS, it is no longer necessary to embed a project created with Unity. Only the built UnityFramework.framework is used. It should be placed in the plugin folder at the path -
9
-
```<YOUR_PROJECT>/unity/builds/ios```.
10
-
11
-
### IOS ONLY!!! If you used a previous version of the plugin - then be sure to delete everything that was related to Unity in the main react native project!
8
+
## Device Support:
12
9
10
+
| Platform | Supported |
11
+
| ---------------- | --------- |
12
+
| iOS Simulator | ❌ |
13
+
| iOS Device | ✅ |
14
+
| Android Emulator | ✅ |
15
+
| Android Device | ✅ |
13
16
14
17
# Installation
15
18
16
-
## RN
19
+
## Install this package in your react-native project:
17
20
18
21
```sh
19
22
npm install @azesmway/react-native-unity
@@ -23,16 +26,16 @@ or
23
26
yarn add @azesmway/react-native-unity
24
27
```
25
28
26
-
## Unity
27
-
28
-
1. Copy from folder "unity" to <Unity_Project_Name> folder and rebuild unity project.
29
+
## Configure your Unity project:
29
30
30
-
#### OnEvent in Unity
31
+
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.
31
32
32
-
Add this code:
33
+
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.
33
34
34
-
```js
35
+
<details>
36
+
<summary>ButtonBehavior.cs</summary>
35
37
38
+
```csharp
36
39
usingSystem;
37
40
usingSystem.Collections;
38
41
usingSystem.Collections.Generic;
@@ -66,58 +69,68 @@ public class ButtonBehavior : MonoBehaviour
66
69
}
67
70
}
68
71
}
69
-
70
72
```
71
73
72
-
## iOS
74
+
</details>
75
+
76
+
## Export iOS Unity Project:
77
+
78
+
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:
73
79
74
-
1. Build Unity project for ios in ANY folder - just not the main RN project folder!!!
75
-
2. Open the created project in XCode
76
-
3. Select Data folder and set a checkbox in the "Target Membership" section to "UnityFramework" 
77
-
4. 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! 
78
-
5. If required - sign the project ```UnityFramework.framework``` and build a framework 
79
-
6. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (```<YOUR_PROJECT>/unity/builds/ios```) 
80
-
7. Execute the command in the root of the main RN project ```rm -rf ios/Pods && rm -f ios/Podfile.lock && npx pod-install```
80
+
1. Open your Unity project
81
+
2. Build Unity project for ios in ANY folder - just not the main RN project folder!!!
82
+
3. Open the created project in XCode
83
+
4. Select Data folder and set a checkbox in the "Target Membership" section to "UnityFramework" 
84
+
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) 
85
+
6. If required - sign the project `UnityFramework.framework` and build a framework 
86
+
7. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (`<YOUR_RN_PROJECT>/unity/builds/ios`) 
87
+
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`
81
88
82
89
### Android
83
90
84
-
1. Export Unity app to `[project_root]/unity/builds/android`
85
-
2. Add the following lines to `android/settings.gradle`:
86
-
```gradle
91
+
1. Open your Unity project
92
+
2. Export Unity app to `<YOUR_RN_PROJECT>/unity/builds/android`
93
+
3. Remove `<intent-filter>...</intent-filter>` from `<YOUR_RN_PROJECT>/unity/builds/android/unityLibrary/src/main/AndroidManifest.xml` at unityLibrary to leave only integrated version.
94
+
95
+
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.
96
+
97
+
1. Add the following lines to `android/settings.gradle`:
6. Remove `<intent-filter>...</intent-filter>` from ``<project_name>/unity/builds/android/unityLibrary/src/main/AndroidManifest.xml`` at unityLibrary to leave only integrated version.
- Works only on real iOS devices. Android emulators are capable of showing the UnityView.
114
-
- 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`.
126
+
-Does not work on the iOS simulator.
127
+
- 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`.
-`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. **FOR ANDROID:** has no effect on iOS.
165
-
-`fullScreen?: boolean` - defaults to true. If set to false, will not request full screen access. **ANDROID ONLY**
180
+
181
+
- `style: ViewStyle` - styles the UnityView. (Won't show on Android without dimensions. Recommended to give it `flex:1` as in the example)
166
182
- `onUnityMessage?: (event: NativeSyntheticEvent)` - receives a message from a Unity
167
-
-`style: ViewStyle` - styles the UnityView. (Won't show on Android without dimensions. Recommended to give it `flex: 1` as in the example)
183
+
- `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**
184
+
- `fullScreen?: boolean` - defaults to true. If set to false, will not request full screen access. **ANDROID ONLY**
168
185
169
186
## Methods
170
-
-`postMessage(gameObject, methodName, message)` - sends a message to the Unity. **FOR IOS:** The native method of unity is used to send a message
171
-
`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)
172
187
188
+
- `postMessage(gameObject, methodName, message)` - sends a message to the Unity. **FOR IOS:** The native method of unity is used to send a message
189
+
`sendMessageToGOWithName:(constchar*)goName functionName:(constchar*)name message:(constchar*)msg;`, more details can be found in the [documentation](https://docs.unity3d.com/2021.1/Documentation/Manual/UnityasaLibrary-iOS.html)
173
190
- `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
174
191
- `pauseUnity?: (pause: boolean)` - pause the Unity
175
-
-`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**
192
+
- `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**
0 commit comments