f111fei / react-native-unity-view

Show an unity view in react native
MIT License
402 stars 102 forks source link

Configure & load multiple unity gradle exports in one react native project #145

Open adikhadilkar opened 4 years ago

adikhadilkar commented 4 years ago

Hey,

I have successfully integrated the Gradle export of a Unity project in a React native project.

I am able to load the exported Unity module on click of a react native button as well as I can communicate with the unity module through a react native project & vice a versa.

Is there any way to add multiple gradle exports (multiple unity projects) in one react native project & achieve communication between them (one unity project / module at a time only) ?

I have tried a few things. I am not sure if it is the right way of solving this issue.

1) I have added 2 gradle exports of 2 different unity projects in android directory of my app

2) I have included path of these 2 gradle exports in android/settings.gradle file

`include ':react-native-unity-view'`
`project(':react-native-unity-view').projectDir = new File(rootProject.projectDir, 
'../node_modules/react-native-unity-view/android')`

`include ":UnityExport"`
`project(":UnityExport").projectDir = file("./UnityExport")`

`include ":UnityExport1"`
`project(":UnityExport1").projectDir = file("./UnityExport1")`

3) I have also added the dependency of second unity export in node_modules/react-native-unity-view/android/build.gradle file

`dependencies {`
   `    compile project(':UnityExport')`
   `    compile project(':UnityExport1')`
   `    compile 'com.facebook.react:react-native:+'`
`}`

To load unity module we generally create an instance of UnityView in our .js file

import UnityView, {UnityModule} from 'react-native-unity-view'; React.createElement(UnityView, { style: {position: 'absolute', left: 0, right: 0, top: 0, bottom: 0}, onUnityMessage: this.onUnityMessage.bind(this), });

Can anyone please tell me 1) if we can integrate multiple unity module within a react native project? 2) if we can, then how should we load those modules on click of separate react native buttons?

relevant references / help / example codes is appreciated.