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
+53-39Lines changed: 53 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,24 @@
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!
6
5
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```.
6
+
> [!IMPORTANT]
7
+
> 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`
10
8
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!
9
+
## Device Support:
10
+
11
+
| Platform | Supported |
12
+
| -------- | --------- |
13
+
| iOS Simulator | ❌ |
14
+
| iOS Device | ✅ |
15
+
| Android Emulator | ✅ |
16
+
| Android Device | ✅ |
12
17
13
18
14
19
# Installation
15
20
16
-
## RN
21
+
## Install this package in your react-native project:
17
22
18
23
```sh
19
24
npm install @azesmway/react-native-unity
@@ -23,16 +28,16 @@ or
23
28
yarn add @azesmway/react-native-unity
24
29
```
25
30
26
-
## Unity
27
-
28
-
1. Copy from folder "unity" to <Unity_Project_Name> folder and rebuild unity project.
31
+
## Configure your Unity project:
29
32
30
-
#### OnEvent in Unity
33
+
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
34
32
-
Add this code:
35
+
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
36
34
-
```js
37
+
<details>
38
+
<summary>ButtonBehavior.cs</summary>
35
39
40
+
```csharp
36
41
usingSystem;
37
42
usingSystem.Collections;
38
43
usingSystem.Collections.Generic;
@@ -66,52 +71,61 @@ public class ButtonBehavior : MonoBehaviour
66
71
}
67
72
}
68
73
}
69
-
70
74
```
75
+
</details>
76
+
77
+
## Export iOS Unity Project:
71
78
72
-
## iOS
79
+
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
80
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```
81
+
1. Open your Unity project
82
+
2. Build Unity project for ios in ANY folder - just not the main RN project folder!!!
83
+
3. Open the created project in XCode
84
+
4. Select Data folder and set a checkbox in the "Target Membership" section to "UnityFramework" 
85
+
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) 
86
+
6. If required - sign the project `UnityFramework.framework` and build a framework 
87
+
7. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (`<YOUR_RN_PROJECT>/unity/builds/ios`) 
88
+
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
89
82
90
### Android
83
91
84
-
1. Export Unity app to `[project_root]/unity/builds/android`
85
-
2. Add the following lines to `android/settings.gradle`:
86
-
```gradle
92
+
1. Open your Unity project
93
+
2. Export Unity app to `<YOUR_RN_PROJECT>/unity/builds/android`
94
+
3. Remove `<intent-filter>...</intent-filter>` from ``<project_name>/unity/builds/android/unityLibrary/src/main/AndroidManifest.xml`` at unityLibrary to leave only integrated version.
95
+
96
+
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.
97
+
98
+
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.
110
124
111
125
# Known issues
112
126
113
-
- 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`.
127
+
- Does not work on the iOS simulator.
128
+
- 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`.
115
129
116
130
# Usage
117
131
@@ -157,19 +171,19 @@ const Unity = () => {
157
171
};
158
172
159
173
export default Unity;
160
-
161
174
```
162
175
163
176
## Props
164
-
-`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**
166
-
-`onUnityMessage?: (event: NativeSyntheticEvent)` - receives a message from a Unity
177
+
167
178
-`style: ViewStyle` - styles the UnityView. (Won't show on Android without dimensions. Recommended to give it `flex: 1` as in the example)
179
+
-`onUnityMessage?: (event: NativeSyntheticEvent)` - receives a message from a Unity
180
+
-`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**
181
+
-`fullScreen?: boolean` - defaults to true. If set to false, will not request full screen access. **ANDROID ONLY**
168
182
169
183
## Methods
184
+
170
185
-`postMessage(gameObject, methodName, message)` - sends a message to the Unity. **FOR IOS:** The native method of unity is used to send a message
171
186
`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
-
173
187
-`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
188
-`pauseUnity?: (pause: boolean)` - pause the Unity
175
189
-`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**
@@ -180,4 +194,4 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
0 commit comments