Skip to content

Commit 313af01

Browse files
committed
README updates
1 parent 0ed1fbc commit 313af01

File tree

1 file changed

+53
-39
lines changed

1 file changed

+53
-39
lines changed

README.md

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# @azesmway/react-native-unity
22

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.
44

5-
### ATTENTION!
65

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`
108
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 ||
1217

1318

1419
# Installation
1520

16-
## RN
21+
## Install this package in your react-native project:
1722

1823
```sh
1924
npm install @azesmway/react-native-unity
@@ -23,16 +28,16 @@ or
2328
yarn add @azesmway/react-native-unity
2429
```
2530

26-
## Unity
27-
28-
1. Copy from folder "unity" to <Unity_Project_Name> folder and rebuild unity project.
31+
## Configure your Unity project:
2932

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.
3134

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.
3336

34-
```js
37+
<details>
38+
<summary>ButtonBehavior.cs</summary>
3539

40+
```csharp
3641
using System;
3742
using System.Collections;
3843
using System.Collections.Generic;
@@ -66,52 +71,61 @@ public class ButtonBehavior : MonoBehaviour
6671
}
6772
}
6873
}
69-
7074
```
75+
</details>
76+
77+
## Export iOS Unity Project:
7178

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:
7380

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" ![image info](./docs/step1.jpg)
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! ![image info](./docs/step2.jpg)
78-
5. If required - sign the project ```UnityFramework.framework``` and build a framework ![image info](./docs/step3.jpg)
79-
6. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (```<YOUR_PROJECT>/unity/builds/ios```) ![image info](./docs/step4.jpg)
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" ![image info](./docs/step1.jpg)
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) ![image info](./docs/step2.jpg)
86+
6. If required - sign the project `UnityFramework.framework` and build a framework ![image info](./docs/step3.jpg)
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`) ![image info](./docs/step4.jpg)
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`
8189

8290
### Android
8391

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`:
99+
```groovy
87100
include ':unityLibrary'
88101
project(':unityLibrary').projectDir=new File('..\\unity\\builds\\android\\unityLibrary')
89102
```
90-
3. Add into `android/build.gradle`
91-
```gradle
103+
2. Add into `android/build.gradle`
104+
```groovy
92105
allprojects {
93106
repositories {
94107
// this
95108
flatDir {
96109
dirs "${project(':unityLibrary').projectDir}/libs"
97110
}
98-
// ...
111+
// ...
112+
}
113+
}
99114
```
100-
4. Add into `android/gradle.properties`
115+
3. Add into `android/gradle.properties`
101116
```gradle
102117
unityStreamingAssets=.unity3d
103118
```
104-
5. Add strings to ``android/app/src/main/res/values/strings.xml``
119+
4. Add strings to ``android/app/src/main/res/values/strings.xml``
105120
106121
```javascript
107122
<string name="game_view_content_description">Game view</string>
108123
```
109-
6. Remove `<intent-filter>...</intent-filter>` from ``<project_name>/unity/builds/android/unityLibrary/src/main/AndroidManifest.xml`` at unityLibrary to leave only integrated version.
110124
111125
# Known issues
112126
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`.
115129
116130
# Usage
117131
@@ -157,19 +171,19 @@ const Unity = () => {
157171
};
158172
159173
export default Unity;
160-
161174
```
162175

163176
## 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+
167178
- `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**
168182

169183
## Methods
184+
170185
- `postMessage(gameObject, methodName, message)` - sends a message to the Unity. **FOR IOS:** The native method of unity is used to send a message
171186
`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-
173187
- `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
174188
- `pauseUnity?: (pause: boolean)` - pause the Unity
175189
- `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
180194

181195
# License
182196

183-
MIT
197+
MIT

0 commit comments

Comments
 (0)