├── .gitattributes
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── android
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── no
│ └── asmadsen
│ └── unity
│ └── view
│ ├── UnityEventListener.java
│ ├── UnityNativeModule.java
│ ├── UnityUtils.java
│ ├── UnityView.java
│ ├── UnityViewManager.java
│ └── UnityViewPackage.java
├── docs
├── android-graphics.png
├── android-player-settings.png
├── bundle-id.png
├── dead-code-stripping.png
├── ios-add-unity-project.png
├── ios-add-unityframework.png
├── ios-player-settings.png
├── ios-set-target-membership.png
└── unity-build.png
├── example
├── .buckconfig
├── .eslintrc.js
├── .flowconfig
├── .gitattributes
├── .gitignore
├── .prettierrc.js
├── .watchmanconfig
├── App.js
├── __tests__
│ └── App-test.js
├── android
│ ├── app
│ │ ├── _BUCK
│ │ ├── build.gradle
│ │ ├── build_defs.bzl
│ │ ├── debug.keystore
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MainApplication.java
│ │ │ └── res
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── app.json
├── babel.config.js
├── index.js
├── ios
│ ├── Podfile
│ ├── Podfile.lock
│ ├── example-tvOS
│ │ └── Info.plist
│ ├── example-tvOSTests
│ │ └── Info.plist
│ ├── example.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ ├── example-tvOS.xcscheme
│ │ │ └── example.xcscheme
│ ├── example.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── example
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Base.lproj
│ │ │ └── LaunchScreen.xib
│ │ ├── Images.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ └── Contents.json
│ │ │ └── Contents.json
│ │ ├── Info.plist
│ │ └── main.m
│ └── exampleTests
│ │ ├── Info.plist
│ │ └── exampleTests.m
├── metro.config.js
├── package.json
├── unity
│ └── example
│ │ ├── .gitignore
│ │ ├── Assets
│ │ ├── Scenes.meta
│ │ ├── Scenes
│ │ │ ├── SampleScene.unity
│ │ │ └── SampleScene.unity.meta
│ │ ├── Scripts.meta
│ │ ├── Scripts
│ │ │ ├── Editor.meta
│ │ │ ├── Editor
│ │ │ │ ├── Build.cs
│ │ │ │ ├── Build.cs.meta
│ │ │ │ ├── XCodePostBuild.cs
│ │ │ │ └── XCodePostBuild.cs.meta
│ │ │ ├── Newtonsoft.Json.meta
│ │ │ ├── Newtonsoft.Json
│ │ │ │ ├── Json_net.meta
│ │ │ │ └── Json_net
│ │ │ │ │ ├── JsonNet.meta
│ │ │ │ │ ├── JsonNet.unitypackage.json
│ │ │ │ │ ├── JsonNet.unitypackage.json.meta
│ │ │ │ │ └── JsonNet
│ │ │ │ │ ├── Newtonsoft.Json.dll
│ │ │ │ │ └── Newtonsoft.Json.dll.meta
│ │ │ ├── Rotate.cs
│ │ │ ├── Rotate.cs.meta
│ │ │ ├── UnityMessageManager.cs
│ │ │ └── UnityMessageManager.cs.meta
│ │ ├── link.xml
│ │ └── link.xml.meta
│ │ ├── Packages
│ │ └── manifest.json
│ │ └── ProjectSettings
│ │ ├── AudioManager.asset
│ │ ├── ClusterInputManager.asset
│ │ ├── DynamicsManager.asset
│ │ ├── EditorBuildSettings.asset
│ │ ├── EditorSettings.asset
│ │ ├── GraphicsSettings.asset
│ │ ├── InputManager.asset
│ │ ├── NavMeshAreas.asset
│ │ ├── Physics2DSettings.asset
│ │ ├── PresetManager.asset
│ │ ├── ProjectSettings.asset
│ │ ├── ProjectVersion.txt
│ │ ├── QualitySettings.asset
│ │ ├── TagManager.asset
│ │ ├── TimeManager.asset
│ │ ├── UnityConnectSettings.asset
│ │ ├── VFXManager.asset
│ │ └── XRSettings.asset
└── yarn.lock
├── ios
├── .gitignore
├── RNUnityView.h
├── RNUnityView.m
├── RNUnityViewManager.h
├── RNUnityViewManager.m
├── UnityNativeModule.h
├── UnityNativeModule.m
├── UnityUtils.h
├── UnityUtils.mm
├── UnityView.xcodeproj
│ └── project.pbxproj
└── UnityView.xcworkspace
│ └── contents.xcworkspacedata
├── package.json
├── react-native-unity-view.podspec
├── scripts
└── examples_postinstall.js
├── src
├── MessageHandler.ts
├── UnityModule.ts
├── UnityView.tsx
└── index.ts
├── template
├── Assets
│ ├── Scripts
│ │ ├── Newtonsoft.Json
│ │ │ └── Json_net
│ │ │ │ ├── JsonNet.unitypackage.json
│ │ │ │ └── JsonNet
│ │ │ │ ├── Newtonsoft.Json.dll
│ │ │ │ └── Newtonsoft.Json.dll.mdb
│ │ └── UnityMessageManager.cs
│ └── link.xml
├── Build.cs
└── XCodePostBuild.cs
├── tsconfig.json
└── yarn.lock
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /dist/
2 |
3 |
4 |
5 | # Created by https://www.gitignore.io/api/linux,xcode,macos,windows,reactnative,intellij+all
6 | # Edit at https://www.gitignore.io/?templates=linux,xcode,macos,windows,reactnative,intellij+all
7 |
8 | ### Intellij+all ###
9 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
10 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
11 |
12 | # User-specific stuff
13 | .idea/**/workspace.xml
14 | .idea/**/tasks.xml
15 | .idea/**/usage.statistics.xml
16 | .idea/**/dictionaries
17 | .idea/**/shelf
18 |
19 | # Generated files
20 | .idea/**/contentModel.xml
21 |
22 | # Sensitive or high-churn files
23 | .idea/**/dataSources/
24 | .idea/**/dataSources.ids
25 | .idea/**/dataSources.local.xml
26 | .idea/**/sqlDataSources.xml
27 | .idea/**/dynamic.xml
28 | .idea/**/uiDesigner.xml
29 | .idea/**/dbnavigator.xml
30 |
31 | # Gradle
32 | .idea/**/gradle.xml
33 | .idea/**/libraries
34 |
35 | # Gradle and Maven with auto-import
36 | # When using Gradle or Maven with auto-import, you should exclude module files,
37 | # since they will be recreated, and may cause churn. Uncomment if using
38 | # auto-import.
39 | # .idea/modules.xml
40 | # .idea/*.iml
41 | # .idea/modules
42 | # *.iml
43 | # *.ipr
44 |
45 | # CMake
46 | cmake-build-*/
47 |
48 | # Mongo Explorer plugin
49 | .idea/**/mongoSettings.xml
50 |
51 | # File-based project format
52 | *.iws
53 |
54 | # IntelliJ
55 | out/
56 |
57 | # mpeltonen/sbt-idea plugin
58 | .idea_modules/
59 |
60 | # JIRA plugin
61 | atlassian-ide-plugin.xml
62 |
63 | # Cursive Clojure plugin
64 | .idea/replstate.xml
65 |
66 | # Crashlytics plugin (for Android Studio and IntelliJ)
67 | com_crashlytics_export_strings.xml
68 | crashlytics.properties
69 | crashlytics-build.properties
70 | fabric.properties
71 |
72 | # Editor-based Rest Client
73 | .idea/httpRequests
74 |
75 | # Android studio 3.1+ serialized cache file
76 | .idea/caches/build_file_checksums.ser
77 |
78 | ### Intellij+all Patch ###
79 | # Ignores the whole .idea folder and all .iml files
80 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
81 |
82 | .idea/
83 |
84 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
85 |
86 | *.iml
87 | modules.xml
88 | .idea/misc.xml
89 | *.ipr
90 |
91 | # Sonarlint plugin
92 | .idea/sonarlint
93 |
94 | ### Linux ###
95 | *~
96 |
97 | # temporary files which can be created if a process still has a handle open of a deleted file
98 | .fuse_hidden*
99 |
100 | # KDE directory preferences
101 | .directory
102 |
103 | # Linux trash folder which might appear on any partition or disk
104 | .Trash-*
105 |
106 | # .nfs files are created when an open file is removed but is still being accessed
107 | .nfs*
108 |
109 | ### macOS ###
110 | # General
111 | .DS_Store
112 | ios/.DS_Store
113 | .AppleDouble
114 | .LSOverride
115 |
116 | # Icon must end with two \r
117 | Icon
118 |
119 | # Thumbnails
120 | ._*
121 |
122 | # Files that might appear in the root of a volume
123 | .DocumentRevisions-V100
124 | .fseventsd
125 | .Spotlight-V100
126 | .TemporaryItems
127 | .Trashes
128 | .VolumeIcon.icns
129 | .com.apple.timemachine.donotpresent
130 |
131 | # Directories potentially created on remote AFP share
132 | .AppleDB
133 | .AppleDesktop
134 | Network Trash Folder
135 | Temporary Items
136 | .apdisk
137 |
138 | ### ReactNative ###
139 | # React Native Stack Base
140 |
141 | .expo
142 | __generated__
143 |
144 | ### ReactNative.Xcode Stack ###
145 | # Xcode
146 | #
147 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
148 |
149 | ## User settings
150 | xcuserdata/
151 |
152 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
153 | *.xcscmblueprint
154 | *.xccheckout
155 |
156 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
157 | build/
158 | DerivedData/
159 | *.moved-aside
160 | *.pbxuser
161 | !default.pbxuser
162 | *.mode1v3
163 | !default.mode1v3
164 | *.mode2v3
165 | !default.mode2v3
166 | *.perspectivev3
167 | !default.perspectivev3
168 |
169 | ## Xcode Patch
170 | *.xcodeproj/*
171 | !*.xcodeproj/project.pbxproj
172 | !*.xcodeproj/xcshareddata/
173 | !*.xcworkspace/contents.xcworkspacedata
174 | /*.gcno
175 |
176 | ### ReactNative.macOS Stack ###
177 | # General
178 |
179 | # Icon must end with two \r
180 | Icon
181 |
182 |
183 | # Thumbnails
184 |
185 | # Files that might appear in the root of a volume
186 |
187 | # Directories potentially created on remote AFP share
188 |
189 | ### ReactNative.Gradle Stack ###
190 | .gradle
191 |
192 | # Ignore Gradle GUI config
193 | gradle-app.setting
194 |
195 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
196 | !gradle-wrapper.jar
197 |
198 | # Cache of project
199 | .gradletasknamecache
200 |
201 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
202 | # gradle/wrapper/gradle-wrapper.properties
203 |
204 | ### ReactNative.Linux Stack ###
205 |
206 | # temporary files which can be created if a process still has a handle open of a deleted file
207 |
208 | # KDE directory preferences
209 |
210 | # Linux trash folder which might appear on any partition or disk
211 |
212 | # .nfs files are created when an open file is removed but is still being accessed
213 |
214 | ### ReactNative.Android Stack ###
215 | # Built application files
216 | *.apk
217 | *.ap_
218 | *.aab
219 |
220 | # Files for the ART/Dalvik VM
221 | *.dex
222 |
223 | # Java class files
224 | *.class
225 |
226 | # Generated files
227 | bin/
228 | gen/
229 | release/
230 |
231 | # Gradle files
232 | .gradle/
233 |
234 | # Local configuration file (sdk path, etc)
235 | local.properties
236 |
237 | # Proguard folder generated by Eclipse
238 | proguard/
239 |
240 | # Log Files
241 | *.log
242 |
243 | # Android Studio Navigation editor temp files
244 | .navigation/
245 |
246 | # Android Studio captures folder
247 | captures/
248 |
249 | # IntelliJ
250 | .idea/workspace.xml
251 | .idea/tasks.xml
252 | .idea/gradle.xml
253 | .idea/assetWizardSettings.xml
254 | .idea/dictionaries
255 | .idea/libraries
256 | # Android Studio 3 in .gitignore file.
257 | .idea/caches
258 | .idea/modules.xml
259 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
260 | .idea/navEditor.xml
261 |
262 | # Keystore files
263 | # Uncomment the following lines if you do not want to check your keystore files in.
264 | #*.jks
265 | #*.keystore
266 |
267 | # External native build folder generated in Android Studio 2.2 and later
268 | .externalNativeBuild
269 |
270 | # Google Services (e.g. APIs or Firebase)
271 | # google-services.json
272 |
273 | # Freeline
274 | freeline.py
275 | freeline/
276 | freeline_project_description.json
277 |
278 | # fastlane
279 | fastlane/report.xml
280 | fastlane/Preview.html
281 | fastlane/screenshots
282 | fastlane/test_output
283 | fastlane/readme.md
284 |
285 | # Version control
286 | vcs.xml
287 |
288 | # lint
289 | lint/intermediates/
290 | lint/generated/
291 | lint/outputs/
292 | lint/tmp/
293 | # lint/reports/
294 |
295 | ### ReactNative.Buck Stack ###
296 | buck-out/
297 | .buckconfig.local
298 | .buckd/
299 | .buckversion
300 | .fakebuckversion
301 |
302 | ### ReactNative.Node Stack ###
303 | # Logs
304 | logs
305 | npm-debug.log*
306 | yarn-debug.log*
307 | yarn-error.log*
308 | lerna-debug.log*
309 |
310 | # Diagnostic reports (https://nodejs.org/api/report.html)
311 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
312 |
313 | # Runtime data
314 | pids
315 | *.pid
316 | *.seed
317 | *.pid.lock
318 |
319 | # Directory for instrumented libs generated by jscoverage/JSCover
320 | lib-cov
321 |
322 | # Coverage directory used by tools like istanbul
323 | coverage
324 | *.lcov
325 |
326 | # nyc test coverage
327 | .nyc_output
328 |
329 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
330 | .grunt
331 |
332 | # Bower dependency directory (https://bower.io/)
333 | bower_components
334 |
335 | # node-waf configuration
336 | .lock-wscript
337 |
338 | # Compiled binary addons (https://nodejs.org/api/addons.html)
339 | build/Release
340 |
341 | # Dependency directories
342 | node_modules/
343 | jspm_packages/
344 |
345 | # TypeScript v1 declaration files
346 | typings/
347 |
348 | # TypeScript cache
349 | *.tsbuildinfo
350 |
351 | # Optional npm cache directory
352 | .npm
353 |
354 | # Optional eslint cache
355 | .eslintcache
356 |
357 | # Optional REPL history
358 | .node_repl_history
359 |
360 | # Output of 'npm pack'
361 | *.tgz
362 |
363 | # Yarn Integrity file
364 | .yarn-integrity
365 |
366 | # dotenv environment variables file
367 | .env
368 | .env.test
369 |
370 | # parcel-bundler cache (https://parceljs.org/)
371 | .cache
372 |
373 | # next.js build output
374 | .next
375 |
376 | # nuxt.js build output
377 | .nuxt
378 |
379 | # react / gatsby
380 | public/
381 |
382 | # vuepress build output
383 | .vuepress/dist
384 |
385 | # Serverless directories
386 | .serverless/
387 |
388 | # FuseBox cache
389 | .fusebox/
390 |
391 | # DynamoDB Local files
392 | .dynamodb/
393 |
394 | ### Windows ###
395 | # Windows thumbnail cache files
396 | Thumbs.db
397 | Thumbs.db:encryptable
398 | ehthumbs.db
399 | ehthumbs_vista.db
400 |
401 | # Dump file
402 | *.stackdump
403 |
404 | # Folder config file
405 | [Dd]esktop.ini
406 |
407 | # Recycle Bin used on file shares
408 | $RECYCLE.BIN/
409 |
410 | # Windows Installer files
411 | *.cab
412 | *.msi
413 | *.msix
414 | *.msm
415 | *.msp
416 |
417 | # Windows shortcuts
418 | *.lnk
419 |
420 | ### Xcode ###
421 | # Xcode
422 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
423 |
424 |
425 |
426 |
427 |
428 | ### Xcode Patch ###
429 | **/xcshareddata/WorkspaceSettings.xcsettings
430 |
431 | # End of https://www.gitignore.io/api/linux,xcode,macos,windows,reactnative,intellij+all
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | example
2 | scripts
3 | docs
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 xzper
4 | Copyright (c) 2019 Andreas Storesund Madsen
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | // android/build.gradle
2 |
3 | def safeExtGet(prop, fallback) {
4 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5 | }
6 |
7 | buildscript {
8 | // The Android Gradle plugin is only required when opening the android folder stand-alone.
9 | // This avoids unnecessary downloads and potential conflicts when the library is included as a
10 | // module dependency in an application project.
11 | if (project == rootProject) {
12 | repositories {
13 | google()
14 | jcenter()
15 | }
16 | dependencies {
17 | classpath 'com.android.tools.build:gradle:3.4.1'
18 | }
19 | }
20 | }
21 |
22 | apply plugin: 'com.android.library'
23 | apply plugin: 'maven'
24 |
25 | // Matches values in recent template from React Native 0.59 / 0.60
26 | // https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L5-L9
27 | // https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L5-L9
28 | def DEFAULT_COMPILE_SDK_VERSION = 28
29 | def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
30 | def DEFAULT_MIN_SDK_VERSION = 16
31 | def DEFAULT_TARGET_SDK_VERSION = 28
32 |
33 | android {
34 | compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
35 | buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
36 | defaultConfig {
37 | minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
38 | targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
39 | versionCode 1
40 | versionName "1.0"
41 | }
42 | lintOptions {
43 | abortOnError false
44 | }
45 | }
46 |
47 | repositories {
48 | mavenLocal()
49 | maven {
50 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
51 | url "$rootDir/../node_modules/react-native/android"
52 | }
53 | maven {
54 | // Android JSC is installed from npm
55 | url "$rootDir/../node_modules/jsc-android/dist"
56 | }
57 | google()
58 | jcenter()
59 | }
60 |
61 | dependencies {
62 | // ref:
63 | // https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
64 | //noinspection GradleDynamicVersion
65 | implementation project(':UnityExport')
66 | implementation ':unity-classes'
67 | implementation 'com.facebook.react:react-native:+' // From node_modules
68 | }
69 |
70 | def configureReactNativePom(def pom) {
71 | def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
72 |
73 | pom.project {
74 | name packageJson.title
75 | artifactId packageJson.name
76 | version = packageJson.version
77 | group = "no.asmadsen.unity.view"
78 | description packageJson.description
79 | url packageJson.repository.baseUrl
80 |
81 | licenses {
82 | license {
83 | name packageJson.license
84 | url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
85 | distribution 'repo'
86 | }
87 | }
88 |
89 | developers {
90 | developer {
91 | id packageJson.author.username
92 | name packageJson.author.name
93 | }
94 | }
95 | }
96 | }
97 |
98 | afterEvaluate { project ->
99 | // some Gradle build hooks ref:
100 | // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
101 | task androidJavadoc(type: Javadoc) {
102 | source = android.sourceSets.main.java.srcDirs
103 | classpath += files(android.bootClasspath)
104 | classpath += files(project.getConfigurations().getByName('compile').asList())
105 | include '**/*.java'
106 | }
107 |
108 | task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
109 | classifier = 'javadoc'
110 | from androidJavadoc.destinationDir
111 | }
112 |
113 | task androidSourcesJar(type: Jar) {
114 | classifier = 'sources'
115 | from android.sourceSets.main.java.srcDirs
116 | include '**/*.java'
117 | }
118 |
119 | android.libraryVariants.all { variant ->
120 | def name = variant.name.capitalize()
121 | task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
122 | from variant.javaCompile.destinationDir
123 | }
124 | }
125 |
126 | artifacts {
127 | archives androidSourcesJar
128 | archives androidJavadocJar
129 | }
130 |
131 | task installArchives(type: Upload) {
132 | configuration = configurations.archives
133 | repositories.mavenDeployer {
134 | // Deploy to react-native-event-bridge/maven, ready to publish to npm
135 | repository url: "file://${projectDir}/../android/maven"
136 | configureReactNativePom pom
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Oct 28 12:09:53 CET 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android/src/main/java/no/asmadsen/unity/view/UnityEventListener.java:
--------------------------------------------------------------------------------
1 | package no.asmadsen.unity.view;
2 |
3 | public interface UnityEventListener {
4 | void onMessage(String message);
5 | }
6 |
--------------------------------------------------------------------------------
/android/src/main/java/no/asmadsen/unity/view/UnityNativeModule.java:
--------------------------------------------------------------------------------
1 | package no.asmadsen.unity.view;
2 |
3 | import com.facebook.react.bridge.Promise;
4 | import com.facebook.react.bridge.ReactApplicationContext;
5 | import com.facebook.react.bridge.ReactContext;
6 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
7 | import com.facebook.react.bridge.ReactMethod;
8 | import com.facebook.react.modules.core.DeviceEventManagerModule;
9 |
10 | public class UnityNativeModule extends ReactContextBaseJavaModule implements UnityEventListener {
11 |
12 | public UnityNativeModule(ReactApplicationContext reactContext) {
13 | super(reactContext);
14 | UnityUtils.addUnityEventListener(this);
15 | }
16 |
17 | @Override
18 | public String getName() {
19 | return "UnityNativeModule";
20 | }
21 |
22 |
23 | @ReactMethod
24 | public void isReady(Promise promise) {
25 | promise.resolve(UnityUtils.isUnityReady());
26 | }
27 |
28 | @ReactMethod
29 | public void createUnity(final Promise promise) {
30 | UnityUtils.createPlayer(getCurrentActivity(), new UnityUtils.CreateCallback() {
31 | @Override
32 | public void onReady() {
33 | promise.resolve(true);
34 | }
35 | });
36 | }
37 |
38 | @ReactMethod
39 | public void postMessage(String gameObject, String methodName, String message) {
40 | UnityUtils.postMessage(gameObject, methodName, message);
41 | }
42 |
43 | @ReactMethod
44 | public void pause() {
45 | UnityUtils.pause();
46 | }
47 |
48 | @ReactMethod
49 | public void resume() {
50 | UnityUtils.resume();
51 | }
52 |
53 | @Override
54 | public void onMessage(String message) {
55 | ReactContext context = getReactApplicationContext();
56 | context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("onUnityMessage", message);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/android/src/main/java/no/asmadsen/unity/view/UnityUtils.java:
--------------------------------------------------------------------------------
1 | package no.asmadsen.unity.view;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.PixelFormat;
6 | import android.os.Build;
7 | import android.view.ViewGroup;
8 | import android.view.WindowManager;
9 | import com.unity3d.player.UnityPlayer;
10 | import java.util.concurrent.CopyOnWriteArraySet;
11 |
12 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
13 |
14 | public class UnityUtils {
15 | private static final CopyOnWriteArraySet mUnityEventListeners =
16 | new CopyOnWriteArraySet<>();
17 | private static UnityPlayer unityPlayer;
18 | private static boolean _isUnityReady;
19 | private static boolean _isUnityPaused;
20 |
21 | public static UnityPlayer getPlayer() {
22 | if (!_isUnityReady) {
23 | return null;
24 | }
25 | return unityPlayer;
26 | }
27 |
28 | public static boolean isUnityReady() {
29 | return _isUnityReady;
30 | }
31 |
32 | public static boolean isUnityPaused() {
33 | return _isUnityPaused;
34 | }
35 |
36 | public static void createPlayer(final Activity activity, final CreateCallback callback) {
37 | if (unityPlayer != null) {
38 | callback.onReady();
39 | return;
40 | }
41 | activity.runOnUiThread(new Runnable() {
42 | @Override
43 | public void run() {
44 | activity.getWindow().setFormat(PixelFormat.RGBA_8888);
45 | int flag = activity.getWindow().getAttributes().flags;
46 | boolean fullScreen = false;
47 | if ((flag & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
48 | fullScreen = true;
49 | }
50 |
51 | unityPlayer = new UnityPlayer(activity);
52 |
53 | try {
54 | // wait a moument. fix unity cannot start when startup.
55 | Thread.sleep(1000);
56 | } catch (Exception e) {
57 | }
58 |
59 | // start unity
60 | addUnityViewToBackground();
61 | unityPlayer.windowFocusChanged(true);
62 | unityPlayer.requestFocus();
63 | unityPlayer.resume();
64 |
65 | // restore window layout
66 | if (!fullScreen) {
67 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
68 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
69 | }
70 | _isUnityReady = true;
71 | callback.onReady();
72 | }
73 | });
74 | }
75 |
76 | public static void postMessage(String gameObject, String methodName, String message) {
77 | if (!_isUnityReady) {
78 | return;
79 | }
80 | UnityPlayer.UnitySendMessage(gameObject, methodName, message);
81 | }
82 |
83 | public static void pause() {
84 | if (unityPlayer != null) {
85 | unityPlayer.pause();
86 | _isUnityPaused = true;
87 | }
88 | }
89 |
90 | public static void resume() {
91 | if (unityPlayer != null) {
92 | unityPlayer.resume();
93 | _isUnityPaused = false;
94 | }
95 | }
96 |
97 | /**
98 | * Invoke by unity C#
99 | */
100 | public static void onUnityMessage(String message) {
101 | for (UnityEventListener listener : mUnityEventListeners) {
102 | try {
103 | listener.onMessage(message);
104 | } catch (Exception e) {
105 | }
106 | }
107 | }
108 |
109 | public static void addUnityEventListener(UnityEventListener listener) {
110 | mUnityEventListeners.add(listener);
111 | }
112 |
113 | public static void removeUnityEventListener(UnityEventListener listener) {
114 | mUnityEventListeners.remove(listener);
115 | }
116 |
117 | public static void addUnityViewToBackground() {
118 | if (unityPlayer == null) {
119 | return;
120 | }
121 | if (unityPlayer.getParent() != null) {
122 | ((ViewGroup) unityPlayer.getParent()).removeView(unityPlayer);
123 | }
124 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
125 | unityPlayer.setZ(-1f);
126 | }
127 | final Activity activity = ((Activity) unityPlayer.getContext());
128 | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(1, 1);
129 | activity.addContentView(unityPlayer, layoutParams);
130 | }
131 |
132 | public static void addUnityViewToGroup(ViewGroup group) {
133 | if (unityPlayer == null) {
134 | return;
135 | }
136 | if (unityPlayer.getParent() != null) {
137 | ((ViewGroup) unityPlayer.getParent()).removeView(unityPlayer);
138 | }
139 | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT);
140 | group.addView(unityPlayer, 0, layoutParams);
141 | unityPlayer.windowFocusChanged(true);
142 | unityPlayer.requestFocus();
143 | unityPlayer.resume();
144 | }
145 |
146 | public interface CreateCallback {
147 | void onReady();
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/android/src/main/java/no/asmadsen/unity/view/UnityView.java:
--------------------------------------------------------------------------------
1 | package no.asmadsen.unity.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 | import android.widget.FrameLayout;
6 | import com.unity3d.player.UnityPlayer;
7 |
8 | public class UnityView extends FrameLayout {
9 |
10 | private UnityPlayer view;
11 |
12 | protected UnityView(Context context) {
13 | super(context);
14 | }
15 |
16 | public void setUnityPlayer(UnityPlayer player) {
17 | this.view = player;
18 | UnityUtils.addUnityViewToGroup(this);
19 | }
20 |
21 | @Override
22 | public void onWindowFocusChanged(boolean hasWindowFocus) {
23 | super.onWindowFocusChanged(hasWindowFocus);
24 | if (view != null) {
25 | view.windowFocusChanged(hasWindowFocus);
26 | }
27 | }
28 |
29 | @Override
30 | protected void onConfigurationChanged(Configuration newConfig) {
31 | super.onConfigurationChanged(newConfig);
32 | if (view != null) {
33 | view.configurationChanged(newConfig);
34 | }
35 | }
36 |
37 | @Override
38 | protected void onDetachedFromWindow() {
39 | UnityUtils.addUnityViewToBackground();
40 | super.onDetachedFromWindow();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/android/src/main/java/no/asmadsen/unity/view/UnityViewManager.java:
--------------------------------------------------------------------------------
1 | package no.asmadsen.unity.view;
2 |
3 | import android.os.Handler;
4 | import android.view.View;
5 | import com.facebook.react.bridge.LifecycleEventListener;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.uimanager.SimpleViewManager;
8 | import com.facebook.react.uimanager.ThemedReactContext;
9 | import java.util.Map;
10 | import javax.annotation.Nullable;
11 |
12 | public class UnityViewManager extends SimpleViewManager
13 | implements LifecycleEventListener, View.OnAttachStateChangeListener {
14 | private static final String REACT_CLASS = "RNUnityView";
15 |
16 | private ReactApplicationContext context;
17 |
18 | UnityViewManager(ReactApplicationContext context) {
19 | super();
20 | this.context = context;
21 | context.addLifecycleEventListener(this);
22 | }
23 |
24 | @Override
25 | public String getName() {
26 | return REACT_CLASS;
27 | }
28 |
29 | @Override
30 | protected UnityView createViewInstance(ThemedReactContext reactContext) {
31 | final UnityView view = new UnityView(reactContext);
32 | view.addOnAttachStateChangeListener(this);
33 |
34 | if (UnityUtils.getPlayer() != null) {
35 | view.setUnityPlayer(UnityUtils.getPlayer());
36 | } else {
37 | UnityUtils.createPlayer(context.getCurrentActivity(), new UnityUtils.CreateCallback() {
38 | @Override
39 | public void onReady() {
40 | view.setUnityPlayer(UnityUtils.getPlayer());
41 | }
42 | });
43 | }
44 | return view;
45 | }
46 |
47 | @Override
48 | public void onDropViewInstance(UnityView view) {
49 | view.removeOnAttachStateChangeListener(this);
50 | super.onDropViewInstance(view);
51 | }
52 |
53 | @Override
54 | public void onHostResume() {
55 | if (UnityUtils.isUnityReady()) {
56 | UnityUtils.getPlayer().resume();
57 | restoreUnityUserState();
58 | }
59 | }
60 |
61 | @Override
62 | public void onHostPause() {
63 | if (UnityUtils.isUnityReady()) {
64 | // Don't use UnityUtils.pause()
65 | UnityUtils.getPlayer().pause();
66 | }
67 | }
68 |
69 | @Override
70 | public void onHostDestroy() {
71 | if (UnityUtils.isUnityReady()) {
72 | UnityUtils.getPlayer().quit();
73 | }
74 | }
75 |
76 | private void restoreUnityUserState() {
77 | // restore the unity player state
78 | if (UnityUtils.isUnityPaused()) {
79 | Handler handler = new Handler();
80 | handler.postDelayed(new Runnable() {
81 | @Override
82 | public void run() {
83 | if (UnityUtils.getPlayer() != null) {
84 | UnityUtils.getPlayer().pause();
85 | }
86 | }
87 | }, 300); //TODO: 300 is the right one?
88 | }
89 | }
90 |
91 | @Override
92 | public void onViewAttachedToWindow(View v) {
93 | restoreUnityUserState();
94 | }
95 |
96 | @Override
97 | public void onViewDetachedFromWindow(View v) {
98 |
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/android/src/main/java/no/asmadsen/unity/view/UnityViewPackage.java:
--------------------------------------------------------------------------------
1 | package no.asmadsen.unity.view;
2 |
3 | import com.facebook.react.ReactPackage;
4 | import com.facebook.react.bridge.NativeModule;
5 | import com.facebook.react.bridge.ReactApplicationContext;
6 | import com.facebook.react.uimanager.ViewManager;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | public class UnityViewPackage implements ReactPackage {
12 | @Override
13 | public List createNativeModules(ReactApplicationContext reactContext) {
14 | List modules = new ArrayList<>();
15 | modules.add(new UnityNativeModule(reactContext));
16 | return modules;
17 | }
18 |
19 | @Override
20 | public List createViewManagers(ReactApplicationContext reactContext) {
21 | List viewManagers = new ArrayList<>();
22 | viewManagers.add(new UnityViewManager(reactContext));
23 | return viewManagers;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/docs/android-graphics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/android-graphics.png
--------------------------------------------------------------------------------
/docs/android-player-settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/android-player-settings.png
--------------------------------------------------------------------------------
/docs/bundle-id.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/bundle-id.png
--------------------------------------------------------------------------------
/docs/dead-code-stripping.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/dead-code-stripping.png
--------------------------------------------------------------------------------
/docs/ios-add-unity-project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/ios-add-unity-project.png
--------------------------------------------------------------------------------
/docs/ios-add-unityframework.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/ios-add-unityframework.png
--------------------------------------------------------------------------------
/docs/ios-player-settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/ios-player-settings.png
--------------------------------------------------------------------------------
/docs/ios-set-target-membership.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/ios-set-target-membership.png
--------------------------------------------------------------------------------
/docs/unity-build.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/docs/unity-build.png
--------------------------------------------------------------------------------
/example/.buckconfig:
--------------------------------------------------------------------------------
1 |
2 | [android]
3 | target = Google Inc.:Google APIs:23
4 |
5 | [maven_repositories]
6 | central = https://repo1.maven.org/maven2
7 |
--------------------------------------------------------------------------------
/example/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | extends: '@react-native-community',
4 | };
5 |
--------------------------------------------------------------------------------
/example/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | ; We fork some components by platform
3 | .*/*[.]android.js
4 |
5 | ; Ignore "BUCK" generated dirs
6 | /\.buckd/
7 |
8 | ; Ignore polyfills
9 | node_modules/react-native/Libraries/polyfills/.*
10 |
11 | ; These should not be required directly
12 | ; require from fbjs/lib instead: require('fbjs/lib/warning')
13 | node_modules/warning/.*
14 |
15 | ; Flow doesn't support platforms
16 | .*/Libraries/Utilities/LoadingView.js
17 |
18 | [untyped]
19 | .*/node_modules/@react-native-community/cli/.*/.*
20 |
21 | [include]
22 |
23 | [libs]
24 | node_modules/react-native/Libraries/react-native/react-native-interface.js
25 | node_modules/react-native/flow/
26 |
27 | [options]
28 | emoji=true
29 |
30 | esproposal.optional_chaining=enable
31 | esproposal.nullish_coalescing=enable
32 |
33 | module.file_ext=.js
34 | module.file_ext=.json
35 | module.file_ext=.ios.js
36 |
37 | munge_underscores=true
38 |
39 | module.name_mapper='^react-native$' -> '/node_modules/react-native/Libraries/react-native/react-native-implementation'
40 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1'
41 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub'
42 |
43 | suppress_type=$FlowIssue
44 | suppress_type=$FlowFixMe
45 | suppress_type=$FlowFixMeProps
46 | suppress_type=$FlowFixMeState
47 |
48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
50 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
51 |
52 | [lints]
53 | sketchy-null-number=warn
54 | sketchy-null-mixed=warn
55 | sketchy-number=warn
56 | untyped-type-import=warn
57 | nonstrict-import=warn
58 | deprecated-type=warn
59 | unsafe-getters-setters=warn
60 | inexact-spread=warn
61 | unnecessary-invariant=warn
62 | signature-verification-failure=warn
63 | deprecated-utility=error
64 |
65 | [strict]
66 | deprecated-type
67 | nonstrict-import
68 | sketchy-null
69 | unclear-type
70 | unsafe-getters-setters
71 | untyped-import
72 | untyped-type-import
73 |
74 | [version]
75 | ^0.105.0
76 |
--------------------------------------------------------------------------------
/example/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 |
24 | # Android/IntelliJ
25 | #
26 | build/
27 | .idea
28 | .gradle
29 | local.properties
30 | *.iml
31 |
32 | # node.js
33 | #
34 | node_modules/
35 | npm-debug.log
36 | yarn-error.log
37 |
38 | # BUCK
39 | buck-out/
40 | \.buckd/
41 | *.keystore
42 | !debug.keystore
43 |
44 | # fastlane
45 | #
46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47 | # screenshots whenever they are needed.
48 | # For more information about the recommended setup visit:
49 | # https://docs.fastlane.tools/best-practices/source-control/
50 |
51 | */fastlane/report.xml
52 | */fastlane/Preview.html
53 | */fastlane/screenshots
54 |
55 | # Bundle artifact
56 | *.jsbundle
57 |
58 | # CocoaPods
59 | /ios/Pods/
60 |
61 |
62 | ios/UnityExport
63 | android/UnityExport
--------------------------------------------------------------------------------
/example/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | bracketSpacing: false,
3 | jsxBracketSameLine: true,
4 | singleQuote: true,
5 | trailingComma: 'all',
6 | };
7 |
--------------------------------------------------------------------------------
/example/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/example/App.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Sample React Native App
3 | * https://github.com/facebook/react-native
4 | *
5 | * @format
6 | * @flow
7 | */
8 |
9 | import React, { useState } from 'react';
10 | import {
11 | SafeAreaView,
12 | StyleSheet,
13 | ScrollView,
14 | View,
15 | Text,
16 | StatusBar,
17 | Button,
18 | Alert
19 | } from 'react-native';
20 |
21 | import {
22 | Header,
23 | LearnMoreLinks,
24 | Colors,
25 | DebugInstructions,
26 | ReloadInstructions,
27 | } from 'react-native/Libraries/NewAppScreen';
28 | import UnityView, { UnityModule } from '@asmadsen/react-native-unity-view';
29 |
30 | const App: () => React$Node = () => {
31 | const [count, setClickCount] = useState(0)
32 | console.log(count)
33 | const onUnityMessage = (hander) => {
34 | console.log({hander})
35 | }
36 |
37 | const onClick = () => {
38 | UnityModule.postMessageToUnityManager({
39 | name: 'ToggleRotate',
40 | data: '',
41 | callBack: (data) => {
42 | Alert.alert('Tip', JSON.stringify(data))
43 | }
44 | });
45 | }
46 |
47 |
48 | return (
49 |
50 |
51 |
56 |
57 |
60 | );
61 | };
62 |
63 | const styles = StyleSheet.create({
64 | scrollView: {
65 | backgroundColor: Colors.lighter,
66 | },
67 | engine: {
68 | position: 'absolute',
69 | right: 0,
70 | },
71 | body: {
72 | backgroundColor: Colors.white,
73 | },
74 | sectionContainer: {
75 | marginTop: 32,
76 | paddingHorizontal: 24,
77 | },
78 | sectionTitle: {
79 | fontSize: 24,
80 | fontWeight: '600',
81 | color: Colors.black,
82 | },
83 | sectionDescription: {
84 | marginTop: 8,
85 | fontSize: 18,
86 | fontWeight: '400',
87 | color: Colors.dark,
88 | },
89 | highlight: {
90 | fontWeight: '700',
91 | },
92 | footer: {
93 | color: Colors.dark,
94 | fontSize: 12,
95 | fontWeight: '600',
96 | padding: 4,
97 | paddingRight: 12,
98 | textAlign: 'right',
99 | },
100 | });
101 |
102 | export default App;
103 |
--------------------------------------------------------------------------------
/example/__tests__/App-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @format
3 | */
4 |
5 | import 'react-native';
6 | import React from 'react';
7 | import App from '../App';
8 |
9 | // Note: test renderer must be required after react-native.
10 | import renderer from 'react-test-renderer';
11 |
12 | it('renders correctly', () => {
13 | renderer.create();
14 | });
15 |
--------------------------------------------------------------------------------
/example/android/app/_BUCK:
--------------------------------------------------------------------------------
1 | # To learn about Buck see [Docs](https://buckbuild.com/).
2 | # To run your application with Buck:
3 | # - install Buck
4 | # - `npm start` - to start the packager
5 | # - `cd android`
6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8 | # - `buck install -r android/app` - compile, install and run application
9 | #
10 |
11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
12 |
13 | lib_deps = []
14 |
15 | create_aar_targets(glob(["libs/*.aar"]))
16 |
17 | create_jar_targets(glob(["libs/*.jar"]))
18 |
19 | android_library(
20 | name = "all-libs",
21 | exported_deps = lib_deps,
22 | )
23 |
24 | android_library(
25 | name = "app-code",
26 | srcs = glob([
27 | "src/main/java/**/*.java",
28 | ]),
29 | deps = [
30 | ":all-libs",
31 | ":build_config",
32 | ":res",
33 | ],
34 | )
35 |
36 | android_build_config(
37 | name = "build_config",
38 | package = "com.example",
39 | )
40 |
41 | android_resource(
42 | name = "res",
43 | package = "com.example",
44 | res = "src/main/res",
45 | )
46 |
47 | android_binary(
48 | name = "app",
49 | keystore = "//android/keystores:debug",
50 | manifest = "src/main/AndroidManifest.xml",
51 | package_type = "debug",
52 | deps = [
53 | ":app-code",
54 | ],
55 | )
56 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | import com.android.build.OutputFile
4 |
5 | /**
6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7 | * and bundleReleaseJsAndAssets).
8 | * These basically call `react-native bundle` with the correct arguments during the Android build
9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10 | * bundle directly from the development server. Below you can see all the possible configurations
11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the
12 | * `apply from: "../../node_modules/react-native/react.gradle"` line.
13 | *
14 | * project.ext.react = [
15 | * // the name of the generated asset file containing your JS bundle
16 | * bundleAssetName: "index.android.bundle",
17 | *
18 | * // the entry file for bundle generation
19 | * entryFile: "index.android.js",
20 | *
21 | * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
22 | * bundleCommand: "ram-bundle",
23 | *
24 | * // whether to bundle JS and assets in debug mode
25 | * bundleInDebug: false,
26 | *
27 | * // whether to bundle JS and assets in release mode
28 | * bundleInRelease: true,
29 | *
30 | * // whether to bundle JS and assets in another build variant (if configured).
31 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
32 | * // The configuration property can be in the following formats
33 | * // 'bundleIn${productFlavor}${buildType}'
34 | * // 'bundleIn${buildType}'
35 | * // bundleInFreeDebug: true,
36 | * // bundleInPaidRelease: true,
37 | * // bundleInBeta: true,
38 | *
39 | * // whether to disable dev mode in custom build variants (by default only disabled in release)
40 | * // for example: to disable dev mode in the staging build type (if configured)
41 | * devDisabledInStaging: true,
42 | * // The configuration property can be in the following formats
43 | * // 'devDisabledIn${productFlavor}${buildType}'
44 | * // 'devDisabledIn${buildType}'
45 | *
46 | * // the root of your project, i.e. where "package.json" lives
47 | * root: "../../",
48 | *
49 | * // where to put the JS bundle asset in debug mode
50 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
51 | *
52 | * // where to put the JS bundle asset in release mode
53 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
54 | *
55 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
56 | * // require('./image.png')), in debug mode
57 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
58 | *
59 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
60 | * // require('./image.png')), in release mode
61 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
62 | *
63 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
64 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
65 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
66 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
67 | * // for example, you might want to remove it from here.
68 | * inputExcludes: ["android/**", "ios/**"],
69 | *
70 | * // override which node gets called and with what additional arguments
71 | * nodeExecutableAndArgs: ["node"],
72 | *
73 | * // supply additional arguments to the packager
74 | * extraPackagerArgs: []
75 | * ]
76 | */
77 |
78 | project.ext.react = [
79 | entryFile: "index.js",
80 | enableHermes: false, // clean and rebuild if changing
81 | ]
82 |
83 | apply from: "../../node_modules/react-native/react.gradle"
84 |
85 | /**
86 | * Set this to true to create two separate APKs instead of one:
87 | * - An APK that only works on ARM devices
88 | * - An APK that only works on x86 devices
89 | * The advantage is the size of the APK is reduced by about 4MB.
90 | * Upload all the APKs to the Play Store and people will download
91 | * the correct one based on the CPU architecture of their device.
92 | */
93 | def enableSeparateBuildPerCPUArchitecture = false
94 |
95 | /**
96 | * Run Proguard to shrink the Java bytecode in release builds.
97 | */
98 | def enableProguardInReleaseBuilds = false
99 |
100 | /**
101 | * The preferred build flavor of JavaScriptCore.
102 | *
103 | * For example, to use the international variant, you can use:
104 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105 | *
106 | * The international variant includes ICU i18n library and necessary data
107 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108 | * give correct results when using with locales other than en-US. Note that
109 | * this variant is about 6MiB larger per architecture than default.
110 | */
111 | def jscFlavor = 'org.webkit:android-jsc:+'
112 |
113 | /**
114 | * Whether to enable the Hermes VM.
115 | *
116 | * This should be set on project.ext.react and mirrored here. If it is not set
117 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118 | * and the benefits of using Hermes will therefore be sharply reduced.
119 | */
120 | def enableHermes = project.ext.react.get("enableHermes", false);
121 |
122 | android {
123 | compileSdkVersion rootProject.ext.compileSdkVersion
124 |
125 | compileOptions {
126 | sourceCompatibility JavaVersion.VERSION_1_8
127 | targetCompatibility JavaVersion.VERSION_1_8
128 | }
129 |
130 | defaultConfig {
131 | applicationId "com.example"
132 | minSdkVersion rootProject.ext.minSdkVersion
133 | targetSdkVersion rootProject.ext.targetSdkVersion
134 | versionCode 1
135 | versionName "1.0"
136 | }
137 | splits {
138 | abi {
139 | reset()
140 | enable enableSeparateBuildPerCPUArchitecture
141 | universalApk false // If true, also generate a universal APK
142 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
143 | }
144 | }
145 | signingConfigs {
146 | debug {
147 | storeFile file('debug.keystore')
148 | storePassword 'android'
149 | keyAlias 'androiddebugkey'
150 | keyPassword 'android'
151 | }
152 | }
153 | buildTypes {
154 | debug {
155 | signingConfig signingConfigs.debug
156 | }
157 | release {
158 | // Caution! In production, you need to generate your own keystore file.
159 | // see https://facebook.github.io/react-native/docs/signed-apk-android.
160 | signingConfig signingConfigs.debug
161 | minifyEnabled enableProguardInReleaseBuilds
162 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
163 | }
164 | }
165 | // applicationVariants are e.g. debug, release
166 | applicationVariants.all { variant ->
167 | variant.outputs.each { output ->
168 | // For each separate APK per architecture, set a unique version code as described here:
169 | // https://developer.android.com/studio/build/configure-apk-splits.html
170 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
171 | def abi = output.getFilter(OutputFile.ABI)
172 | if (abi != null) { // null for the universal-debug, universal-release variants
173 | output.versionCodeOverride =
174 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
175 | }
176 |
177 | }
178 | }
179 | }
180 |
181 | dependencies {
182 | implementation fileTree(dir: "libs", include: ["*.jar"])
183 | implementation "com.facebook.react:react-native:+" // From node_modules
184 |
185 | if (enableHermes) {
186 | def hermesPath = "../../node_modules/hermes-engine/android/";
187 | debugImplementation files(hermesPath + "hermes-debug.aar")
188 | releaseImplementation files(hermesPath + "hermes-release.aar")
189 | } else {
190 | implementation jscFlavor
191 | }
192 | }
193 |
194 | // Run this once to be able to run the application with BUCK
195 | // puts all compile dependencies into folder libs for BUCK to use
196 | task copyDownloadableDepsToLibs(type: Copy) {
197 | from configurations.compile
198 | into 'libs'
199 | }
200 |
201 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
202 |
--------------------------------------------------------------------------------
/example/android/app/build_defs.bzl:
--------------------------------------------------------------------------------
1 | """Helper definitions to glob .aar and .jar targets"""
2 |
3 | def create_aar_targets(aarfiles):
4 | for aarfile in aarfiles:
5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")]
6 | lib_deps.append(":" + name)
7 | android_prebuilt_aar(
8 | name = name,
9 | aar = aarfile,
10 | )
11 |
12 | def create_jar_targets(jarfiles):
13 | for jarfile in jarfiles:
14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")]
15 | lib_deps.append(":" + name)
16 | prebuilt_jar(
17 | name = name,
18 | binary_jar = jarfile,
19 | )
20 |
--------------------------------------------------------------------------------
/example/android/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/debug.keystore
--------------------------------------------------------------------------------
/example/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.facebook.react.ReactActivity;
4 |
5 | public class MainActivity extends ReactActivity {
6 |
7 | /**
8 | * Returns the name of the main component registered from JavaScript. This is used to schedule
9 | * rendering of the component.
10 | */
11 | @Override
12 | protected String getMainComponentName() {
13 | return "example";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import com.facebook.react.PackageList;
6 | import com.facebook.react.ReactApplication;
7 | import com.facebook.react.ReactNativeHost;
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.soloader.SoLoader;
10 | import java.lang.reflect.InvocationTargetException;
11 | import java.util.List;
12 |
13 | public class MainApplication extends Application implements ReactApplication {
14 |
15 | private final ReactNativeHost mReactNativeHost =
16 | new ReactNativeHost(this) {
17 | @Override
18 | public boolean getUseDeveloperSupport() {
19 | return BuildConfig.DEBUG;
20 | }
21 |
22 | @Override
23 | protected List getPackages() {
24 | @SuppressWarnings("UnnecessaryLocalVariable")
25 | List packages = new PackageList(this).getPackages();
26 | // Packages that cannot be autolinked yet can be added manually here, for example:
27 | // packages.add(new MyReactNativePackage());
28 | return packages;
29 | }
30 |
31 | @Override
32 | protected String getJSMainModuleName() {
33 | return "index";
34 | }
35 | };
36 |
37 | @Override
38 | public ReactNativeHost getReactNativeHost() {
39 | return mReactNativeHost;
40 | }
41 |
42 | @Override
43 | public void onCreate() {
44 | super.onCreate();
45 | SoLoader.init(this, /* native exopackage */ false);
46 | initializeFlipper(this); // Remove this line if you don't want Flipper enabled
47 | }
48 |
49 | /**
50 | * Loads Flipper in React Native templates.
51 | *
52 | * @param context
53 | */
54 | private static void initializeFlipper(Context context) {
55 | if (BuildConfig.DEBUG) {
56 | try {
57 | /*
58 | We use reflection here to pick up the class that initializes Flipper,
59 | since Flipper library is not available in release mode
60 | */
61 | Class> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
62 | aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
63 | } catch (ClassNotFoundException e) {
64 | e.printStackTrace();
65 | } catch (NoSuchMethodException e) {
66 | e.printStackTrace();
67 | } catch (IllegalAccessException e) {
68 | e.printStackTrace();
69 | } catch (InvocationTargetException e) {
70 | e.printStackTrace();
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Hello App Display Name
3 |
4 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext {
5 | buildToolsVersion = "28.0.3"
6 | minSdkVersion = 19
7 | compileSdkVersion = 28
8 | targetSdkVersion = 28
9 | }
10 | repositories {
11 | google()
12 | jcenter()
13 | }
14 | dependencies {
15 | classpath("com.android.tools.build:gradle:3.4.2")
16 |
17 | // NOTE: Do not place your application dependencies here; they belong
18 | // in the individual module build.gradle files
19 | }
20 | }
21 |
22 | allprojects {
23 | repositories {
24 | mavenLocal()
25 | maven {
26 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
27 | url("$rootDir/../node_modules/react-native/android")
28 | }
29 | maven {
30 | // Android JSC is installed from npm
31 | url("$rootDir/../node_modules/jsc-android/dist")
32 | }
33 |
34 | google()
35 | jcenter()
36 | maven { url 'https://jitpack.io' }
37 | flatDir {
38 | dirs "${project(':UnityExport').projectDir}/libs"
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useAndroidX=true
21 | android.enableJetifier=true
22 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/example/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin, switch paths to Windows format before running java
129 | if $cygwin ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=$((i+1))
158 | done
159 | case $i in
160 | (0) set -- ;;
161 | (1) set -- "$args0" ;;
162 | (2) set -- "$args0" "$args1" ;;
163 | (3) set -- "$args0" "$args1" "$args2" ;;
164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=$(save "$@")
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185 | cd "$(dirname "$0")"
186 | fi
187 |
188 | exec "$JAVACMD" "$@"
189 |
--------------------------------------------------------------------------------
/example/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem http://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'example'
2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
3 | include ':app'
4 | include ":UnityExport"
5 | project(":UnityExport").projectDir = file("./UnityExport")
6 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "displayName": "example"
4 | }
--------------------------------------------------------------------------------
/example/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:metro-react-native-babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @format
3 | */
4 |
5 | import {AppRegistry} from 'react-native';
6 | import App from './App';
7 | import {name as appName} from './app.json';
8 |
9 | AppRegistry.registerComponent(appName, () => App);
10 |
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | platform :ios, '9.0'
2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
3 |
4 | target 'example' do
5 | # Pods for example
6 | pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
7 | pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
8 | pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
9 | pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
10 | pod 'React', :path => '../node_modules/react-native/'
11 | pod 'React-Core', :path => '../node_modules/react-native/'
12 | pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
13 | pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
14 | pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
15 | pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
16 | pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
17 | pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
18 | pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
19 | pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
20 | pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
21 | pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
22 | pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
23 | pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
24 |
25 | pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
26 | pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
27 | pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
28 | pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
29 | pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
30 | pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
31 | pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
32 |
33 | pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
34 | pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
35 | pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
36 |
37 | target 'exampleTests' do
38 | inherit! :search_paths
39 | # Pods for testing
40 | end
41 |
42 | use_native_modules!
43 | end
44 |
45 | target 'example-tvOS' do
46 | # Pods for example-tvOS
47 |
48 | target 'example-tvOSTests' do
49 | inherit! :search_paths
50 | # Pods for testing
51 | end
52 |
53 | end
54 |
--------------------------------------------------------------------------------
/example/ios/example-tvOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | NSAppTransportSecurity
26 |
27 | NSExceptionDomains
28 |
29 | localhost
30 |
31 | NSExceptionAllowsInsecureHTTPLoads
32 |
33 |
34 |
35 |
36 | NSLocationWhenInUseUsageDescription
37 |
38 | UILaunchStoryboardName
39 | LaunchScreen
40 | UIRequiredDeviceCapabilities
41 |
42 | armv7
43 |
44 | UISupportedInterfaceOrientations
45 |
46 | UIInterfaceOrientationPortrait
47 | UIInterfaceOrientationLandscapeLeft
48 | UIInterfaceOrientationLandscapeRight
49 |
50 | UIViewControllerBasedStatusBarAppearance
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/example/ios/example-tvOSTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/example/ios/example.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/ios/example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/example.xcodeproj/xcshareddata/xcschemes/example-tvOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
61 |
67 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
80 |
81 |
82 |
92 |
94 |
100 |
101 |
102 |
103 |
104 |
105 |
111 |
113 |
119 |
120 |
121 |
122 |
124 |
125 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
61 |
67 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
80 |
81 |
82 |
92 |
94 |
100 |
101 |
102 |
103 |
104 |
105 |
111 |
113 |
119 |
120 |
121 |
122 |
124 |
125 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/example/ios/example.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/example/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (nonatomic, strong) UIWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/example/ios/example/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import "AppDelegate.h"
9 |
10 | #import
11 | #import
12 | #import
13 |
14 | @implementation AppDelegate
15 |
16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
17 | {
18 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
19 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
20 | moduleName:@"example"
21 | initialProperties:nil];
22 |
23 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
24 |
25 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
26 | UIViewController *rootViewController = [UIViewController new];
27 | rootViewController.view = rootView;
28 | self.window.rootViewController = rootViewController;
29 | [self.window makeKeyAndVisible];
30 | return YES;
31 | }
32 |
33 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
34 | {
35 | #if DEBUG
36 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
37 | #else
38 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
39 | #endif
40 | }
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/example/ios/example/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ios-marketing",
45 | "size" : "1024x1024",
46 | "scale" : "1x"
47 | }
48 | ],
49 | "info" : {
50 | "version" : 1,
51 | "author" : "xcode"
52 | }
53 | }
--------------------------------------------------------------------------------
/example/ios/example/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/example/ios/example/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | Hello App Display Name
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | NSAppTransportSecurity
28 |
29 | NSAllowsArbitraryLoads
30 |
31 | NSExceptionDomains
32 |
33 | localhost
34 |
35 | NSExceptionAllowsInsecureHTTPLoads
36 |
37 |
38 |
39 |
40 | NSLocationWhenInUseUsageDescription
41 |
42 | UILaunchStoryboardName
43 | LaunchScreen
44 | UIRequiredDeviceCapabilities
45 |
46 | armv7
47 |
48 | UISupportedInterfaceOrientations
49 |
50 | UIInterfaceOrientationPortrait
51 | UIInterfaceOrientationLandscapeLeft
52 | UIInterfaceOrientationLandscapeRight
53 |
54 | UIViewControllerBasedStatusBarAppearance
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/example/ios/example/main.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 |
10 | #import "AppDelegate.h"
11 | #import "UnityUtils.h"
12 |
13 | int main(int argc, char * argv[]) {
14 | @autoreleasepool {
15 | InitArgs(argc, argv);
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/example/ios/exampleTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/example/ios/exampleTests/exampleTests.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 | #import
10 |
11 | #import
12 | #import
13 |
14 | #define TIMEOUT_SECONDS 600
15 | #define TEXT_TO_LOOK_FOR @"Welcome to React"
16 |
17 | @interface exampleTests : XCTestCase
18 |
19 | @end
20 |
21 | @implementation exampleTests
22 |
23 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
24 | {
25 | if (test(view)) {
26 | return YES;
27 | }
28 | for (UIView *subview in [view subviews]) {
29 | if ([self findSubviewInView:subview matching:test]) {
30 | return YES;
31 | }
32 | }
33 | return NO;
34 | }
35 |
36 | - (void)testRendersWelcomeScreen
37 | {
38 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
39 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
40 | BOOL foundElement = NO;
41 |
42 | __block NSString *redboxError = nil;
43 | #ifdef DEBUG
44 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
45 | if (level >= RCTLogLevelError) {
46 | redboxError = message;
47 | }
48 | });
49 | #endif
50 |
51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
54 |
55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
57 | return YES;
58 | }
59 | return NO;
60 | }];
61 | }
62 |
63 | #ifdef DEBUG
64 | RCTSetLogFunction(RCTDefaultLogFunction);
65 | #endif
66 |
67 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
68 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
69 | }
70 |
71 |
72 | @end
73 |
--------------------------------------------------------------------------------
/example/metro.config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Metro configuration for React Native
3 | * https://github.com/facebook/react-native
4 | *
5 | * @format
6 | */
7 |
8 | module.exports = {
9 | transformer: {
10 | getTransformOptions: async () => ({
11 | transform: {
12 | experimentalImportSupport: false,
13 | inlineRequires: false,
14 | },
15 | }),
16 | },
17 | };
18 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "android": "react-native run-android",
7 | "ios": "react-native run-ios",
8 | "start": "react-native start",
9 | "test": "jest",
10 | "postinstall": "node ../scripts/examples_postinstall.js"
11 | },
12 | "dependencies": {
13 | "react": "16.8.1",
14 | "react-native": "0.61.3",
15 | "@asmadsen/react-native-unity-view": "file:../"
16 | },
17 | "devDependencies": {
18 | "@babel/core": "^7.5.0",
19 | "@babel/runtime": "^7.5.0",
20 | "@react-native-community/eslint-config": "^0.0.3",
21 | "babel-jest": "^24.1.0",
22 | "jest": "^24.1.0",
23 | "metro-react-native-babel-preset": "^0.51.1",
24 | "react-test-renderer": "16.8.1"
25 | },
26 | "jest": {
27 | "preset": "react-native"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/example/unity/example/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/unity
3 | # Edit at https://www.gitignore.io/?templates=unity
4 |
5 | ### Unity ###
6 | # This .gitignore file should be placed at the root of your Unity project directory
7 | #
8 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
9 | /[Ll]ibrary/
10 | /[Tt]emp/
11 | /[Oo]bj/
12 | /[Bb]uild/
13 | /[Bb]uilds/
14 | /[Ll]ogs/
15 | /[Mm]emoryCaptures/
16 |
17 | # Never ignore Asset meta data
18 | !/[Aa]ssets/**/*.meta
19 |
20 | # Uncomment this line if you wish to ignore the asset store tools plugin
21 | # /[Aa]ssets/AssetStoreTools*
22 |
23 | # TextMesh Pro files
24 | [Aa]ssets/TextMesh*Pro/
25 |
26 | # Autogenerated Jetbrains Rider plugin
27 | [Aa]ssets/Plugins/Editor/JetBrains*
28 |
29 | # Visual Studio cache directory
30 | .vs/
31 |
32 | # Gradle cache directory
33 | .gradle/
34 |
35 | # Autogenerated VS/MD/Consulo solution and project files
36 | ExportedObj/
37 | .consulo/
38 | *.csproj
39 | *.unityproj
40 | *.sln
41 | *.suo
42 | *.tmp
43 | *.user
44 | *.userprefs
45 | *.pidb
46 | *.booproj
47 | *.svd
48 | *.pdb
49 | *.mdb
50 | *.opendb
51 | *.VC.db
52 |
53 | # Unity3D generated meta files
54 | *.pidb.meta
55 | *.pdb.meta
56 | *.mdb.meta
57 |
58 | # Unity3D generated file on crash reports
59 | sysinfo.txt
60 |
61 | # Builds
62 | *.apk
63 | *.unitypackage
64 | *.symbols.zip
65 |
66 | # Crashlytics generated file
67 | crashlytics-build.properties
68 |
69 |
70 | # End of https://www.gitignore.io/api/unity
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fa6eaf404d724452a8ddccb7aaf1c410
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scenes/SampleScene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9fc0d4010bbf28b4594072e72b8655ab
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f592bee2f78d44b8facf92d3e394c99e
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0b403caa5db35484f9a517714957d742
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Editor/Build.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Text.RegularExpressions;
5 | using UnityEditor;
6 | using UnityEngine;
7 | using Application = UnityEngine.Application;
8 | using BuildResult = UnityEditor.Build.Reporting.BuildResult;
9 |
10 | public class Build : MonoBehaviour {
11 | static readonly string ProjectPath = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
12 |
13 | static readonly string apkPath = Path.Combine(ProjectPath, "Builds/" + Application.productName + ".apk");
14 |
15 | private static readonly string androidExportPath =
16 | Path.GetFullPath(Path.Combine(ProjectPath, "../../android/UnityExport"));
17 |
18 | private static readonly string iosExportPath =
19 | Path.GetFullPath(Path.Combine(ProjectPath, "../../ios/UnityExport"));
20 |
21 | [MenuItem("ReactNative/Export Android (Unity 2019.3.*) %&n", false, 1)]
22 | public static void DoBuildAndroidLibrary() {
23 | DoBuildAndroid(Path.Combine(apkPath, "unityLibrary"));
24 |
25 | Copy(Path.Combine(apkPath, "launcher/src/main/res"), Path.Combine(androidExportPath, "src/main/res"));
26 | }
27 |
28 | [MenuItem("ReactNative/Export Android legacy %&a", false, 2)]
29 | public static void DoBuildAndroidLegacy() {
30 | DoBuildAndroid(Path.Combine(apkPath, Application.productName));
31 | }
32 |
33 | public static void DoBuildAndroid(String buildPath) {
34 | if (Directory.Exists(apkPath)) {
35 | Directory.Delete(apkPath, true);
36 | }
37 | if (Directory.Exists(androidExportPath)) {
38 | Directory.Delete(androidExportPath, true);
39 | }
40 |
41 | EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
42 |
43 | var options = BuildOptions.AcceptExternalModificationsToPlayer;
44 | var report = BuildPipeline.BuildPlayer(
45 | GetEnabledScenes(),
46 | apkPath,
47 | BuildTarget.Android,
48 | options
49 | );
50 |
51 | if (report.summary.result != BuildResult.Succeeded) {
52 | throw new Exception("Build failed");
53 | }
54 |
55 | Copy(buildPath, androidExportPath);
56 | // Modify build.gradle
57 | var build_file = Path.Combine(androidExportPath, "build.gradle");
58 | var build_text = File.ReadAllText(build_file);
59 | build_text = build_text.Replace("com.android.application", "com.android.library");
60 | build_text = build_text.Replace("bundle {", "splits {");
61 | build_text = build_text.Replace("enableSplit = false", "enable false");
62 | build_text = build_text.Replace("enableSplit = true", "enable true");
63 | build_text = build_text.Replace("implementation fileTree(dir: 'libs', include: ['*.jar'])", "implementation ':unity-classes'");
64 | // build_text = Regex.Replace(build_text, @"\n.*applicationId '.+'.*\n", "\n");
65 | File.WriteAllText(build_file, build_text);
66 |
67 | // Modify AndroidManifest.xml
68 | var manifest_file = Path.Combine(androidExportPath, "src/main/AndroidManifest.xml");
69 | var manifest_text = File.ReadAllText(manifest_file);
70 | manifest_text = Regex.Replace(manifest_text, @"", "");
71 | Regex regex = new Regex(@"(\s|\S)+?", RegexOptions.Multiline);
72 | manifest_text = regex.Replace(manifest_text, "");
73 | File.WriteAllText(manifest_file, manifest_text);
74 | }
75 |
76 | [MenuItem("ReactNative/Export IOS (Unity 2019.3.*) %&i", false, 3)]
77 | public static void DoBuildIOS() {
78 | if (Directory.Exists(iosExportPath)) {
79 | Directory.Delete(iosExportPath, true);
80 | }
81 |
82 | EditorUserBuildSettings.iOSBuildConfigType = iOSBuildType.Release;
83 |
84 | var options = BuildOptions.AcceptExternalModificationsToPlayer;
85 | var report = BuildPipeline.BuildPlayer(
86 | GetEnabledScenes(),
87 | iosExportPath,
88 | BuildTarget.iOS,
89 | options
90 | );
91 |
92 | if (report.summary.result != BuildResult.Succeeded) {
93 | throw new Exception("Build failed");
94 | }
95 | }
96 |
97 | static void Copy(string source, string destinationPath) {
98 | if (Directory.Exists(destinationPath))
99 | Directory.Delete(destinationPath, true);
100 |
101 | Directory.CreateDirectory(destinationPath);
102 |
103 | foreach (string dirPath in Directory.GetDirectories(source, "*",
104 | SearchOption.AllDirectories))
105 | Directory.CreateDirectory(dirPath.Replace(source, destinationPath));
106 |
107 | foreach (string newPath in Directory.GetFiles(source, "*.*",
108 | SearchOption.AllDirectories))
109 | File.Copy(newPath, newPath.Replace(source, destinationPath), true);
110 | }
111 |
112 | static string[] GetEnabledScenes() {
113 | var scenes = EditorBuildSettings.scenes
114 | .Where(s => s.enabled)
115 | .Select(s => s.path)
116 | .ToArray();
117 |
118 | return scenes;
119 | }
120 | }
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Editor/Build.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e96617ff4a6b54f5e9ad753fed797130
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Editor/XCodePostBuild.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4643700828f0343828779638c20552eb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Newtonsoft.Json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 94a293c4348544292b095495118b48f5
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Newtonsoft.Json/Json_net.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b313ed480d4144d7e86761830d178b50
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Newtonsoft.Json/Json_net/JsonNet.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ac02febf9d35b4e42afff1a001c30be4
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Newtonsoft.Json/Json_net/JsonNet.unitypackage.json:
--------------------------------------------------------------------------------
1 | {
2 | "Id": "JsonNet",
3 | "Version": "9.0.1",
4 | "Authors": [
5 | "James Newton-King"
6 | ],
7 | "Owners": [
8 | "Esun Kim"
9 | ],
10 | "Description": "Unity3D port of Json.NET which is a popular high-performance JSON framework for .NET",
11 | "Files": [
12 | "Assets/UnityPackages/JsonNet/Newtonsoft.Json.dll",
13 | "Assets/UnityPackages/JsonNet/Newtonsoft.Json.dll.mdb",
14 | {
15 | "Target": "Assets/UnityPackages/JsonNetSample/JsonNetSample.cs",
16 | "Extra": true
17 | },
18 | {
19 | "Target": "Assets/UnityPackages/JsonNetSample/JsonNetSample.unity",
20 | "Extra": true
21 | }
22 | ]
23 | }
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Newtonsoft.Json/Json_net/JsonNet.unitypackage.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9ee9552b9ff444400b1185d3f3609258
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Newtonsoft.Json/Json_net/JsonNet/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asmadsen/react-native-unity-view/068f842716991bd0e710abae7ed6884c337ffc39/example/unity/example/Assets/Scripts/Newtonsoft.Json/Json_net/JsonNet/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Newtonsoft.Json/Json_net/JsonNet/Newtonsoft.Json.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 60f256006a9914ff88523a27c2233395
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 0
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | Any:
16 | second:
17 | enabled: 1
18 | settings: {}
19 | - first:
20 | Editor: Editor
21 | second:
22 | enabled: 0
23 | settings:
24 | DefaultValueInitialized: true
25 | - first:
26 | Windows Store Apps: WindowsStoreApps
27 | second:
28 | enabled: 0
29 | settings:
30 | CPU: AnyCPU
31 | userData:
32 | assetBundleName:
33 | assetBundleVariant:
34 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Rotate.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using UnityEngine;
4 |
5 | public class Rotate : MonoBehaviour
6 | {
7 |
8 | private bool canRotate = true;
9 |
10 | // Use this for initialization
11 | void Awake()
12 | {
13 | UnityMessageManager.Instance.OnRNMessage += onMessage;
14 | }
15 |
16 | void onDestroy()
17 | {
18 | UnityMessageManager.Instance.OnRNMessage -= onMessage;
19 | }
20 |
21 | void onMessage(MessageHandler message)
22 | {
23 | var data = message.getData();
24 | Debug.Log("onMessage:" + data);
25 | canRotate = !canRotate;
26 | UnityMessageManager.Instance.SendMessageToRN("Now it is " + (canRotate ? "": "not ") + "rotating");
27 | message.send(new { CallbackTest = "I am Unity callback" });
28 | }
29 |
30 | void OnMouseDown()
31 | {
32 | Debug.Log("click");
33 | UnityMessageManager.Instance.SendMessageToRN(new UnityMessage()
34 | {
35 | name = "click",
36 | callBack = (data) =>
37 | {
38 | Debug.Log("onClickCallBack:" + data);
39 | }
40 | });
41 | }
42 |
43 | // Update is called once per frame
44 | void Update()
45 | {
46 | if (!canRotate)
47 | {
48 | return;
49 | }
50 | var delta = 30 * Time.deltaTime;
51 | transform.localRotation *= Quaternion.Euler(delta, delta, delta);
52 | }
53 | }
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/Rotate.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 45f99306a7d394b18a61c42dbdf93fa5
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/example/unity/example/Assets/Scripts/UnityMessageManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Runtime.InteropServices;
5 | using Newtonsoft.Json;
6 | using Newtonsoft.Json.Linq;
7 | using UnityEngine;
8 |
9 | public class MessageHandler
10 | {
11 | public int id;
12 | public string seq;
13 |
14 | public String name;
15 | private JToken data;
16 |
17 | public static MessageHandler Deserialize(string message)
18 | {
19 | JObject m = JObject.Parse(message);
20 | MessageHandler handler = new MessageHandler(
21 | m.GetValue("id").Value(),
22 | m.GetValue("seq").Value(),
23 | m.GetValue("name").Value(),
24 | m.GetValue("data")
25 | );
26 | return handler;
27 | }
28 |
29 | public T getData()
30 | {
31 | return data.Value();
32 | }
33 |
34 | public MessageHandler(int id, string seq, string name, JToken data)
35 | {
36 | this.id = id;
37 | this.seq = seq;
38 | this.name = name;
39 | this.data = data;
40 | }
41 |
42 | public void send(object data)
43 | {
44 | JObject o = JObject.FromObject(new
45 | {
46 | id = id,
47 | seq = "end",
48 | name = name,
49 | data = data
50 | });
51 | UnityMessageManager.Instance.SendMessageToRN(UnityMessageManager.MessagePrefix + o.ToString());
52 | }
53 | }
54 |
55 | public class UnityMessage
56 | {
57 | public String name;
58 | public JObject data;
59 | public Action