This is a work in progress, I wouldn't bother using it yet because there's a lot of kinks to work out still...
$ npm install react-native-unity --save
$ react-native link react-native-unity
For iOS you will need to add the 'UnityAds.framework' file to your project's bundle.
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-unity
and addRNUnity.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNUnity.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNUnityPackage;
to the imports at the top of the file - Add
new RNUnityPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-unity' project(':react-native-unity').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-unity/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-unity')
import UnityAds from 'react-native-unity';
// The second parameter turns test-mode on or off
UnityAds.loadAds('[appId]', true);
UnityAds.showAd();
UnityAds.isReady('video', (ready) => {
if (ready) UnityAds.showAdWithId('video');
});
UnityAds.addReadyListener((data) => {
// data.placementId -> placementId of ad placement that is ready
});
UnityAds.addStartListener((data) => {
// data.placementId -> placementId of ad placement that has started
});
UnityAds.addFinishListener((data) => {
// data.placementId -> placementId of ad placement that finished
// data.finishState -> number for the finish state of the ad, check the official SDK for more details
});
UnityAds.addErrorListener((data) => {
// data.message -> error message
// data.error -> number for the error, check the official SDK for more details
});