Skip to content

ThrowJojo/react-native-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-unity

This is a work in progress, I wouldn't bother using it yet because there's a lot of kinks to work out still...

Getting started

$ npm install react-native-unity --save

Mostly automatic installation

$ react-native link react-native-unity

For iOS you will need to add the 'UnityAds.framework' file to your project's bundle.

Manual installation (I really don't recommend this)

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-unity and add RNUnity.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNUnity.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. 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 the getPackages() method
  1. 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')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-unity')
    

Initialization

import UnityAds from 'react-native-unity';

// The second parameter turns test-mode on or off
UnityAds.loadAds('[appId]', true);

Showing your default placement

UnityAds.showAd();

Checking if a placement is ready, then showing that placement

UnityAds.isReady('video', (ready) => {  
    if (ready) UnityAds.showAdWithId('video');         
});

Add a ready listener

UnityAds.addReadyListener((data) => {
    // data.placementId -> placementId of ad placement that is ready
});

Add a start listener

UnityAds.addStartListener((data) => {
    // data.placementId -> placementId of ad placement that has started
});

Add a finish listener

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
});

Add an error listener

UnityAds.addErrorListener((data) => {
    // data.message -> error message
    // data.error -> number for the error, check the official SDK for more details
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published