Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/dist/



Expand Down Expand Up @@ -306,6 +305,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.yarn/cache

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down Expand Up @@ -428,4 +428,4 @@ $RECYCLE.BIN/
### Xcode Patch ###
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.gitignore.io/api/linux,xcode,macos,windows,reactnative,intellij+all
# End of https://www.gitignore.io/api/linux,xcode,macos,windows,reactnative,intellij+all
Binary file added .yarn/install-state.gz
Binary file not shown.
874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.4.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarnPath: .yarn/releases/yarn-3.6.4.cjs
14 changes: 7 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ buildscript {
}

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'

// Matches values in recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L5-L9
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L5-L9
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = "30.0.3"
def DEFAULT_MIN_SDK_VERSION = 28
def DEFAULT_TARGET_SDK_VERSION = 31

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
Expand Down Expand Up @@ -101,7 +101,7 @@ afterEvaluate { project ->
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
// classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}

Expand Down Expand Up @@ -130,10 +130,10 @@ afterEvaluate { project ->

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
/*repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"
configureReactNativePom pom
}
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@

public class UnityNativeModule extends ReactContextBaseJavaModule implements UnityEventListener {

// Added reference to native method defined in UnityBridge.h for capturing Java env
private native void unityBridgeSetup();

public UnityNativeModule(ReactApplicationContext reactContext) {
super(reactContext);
UnityUtils.addUnityEventListener(this);

// Add call to UnityBridge.h to capture Java env
System.loadLibrary ("juce_jni");
unityBridgeSetup();
}

@Override
Expand Down Expand Up @@ -50,9 +57,19 @@ public void resume() {
UnityUtils.resume();
}

// Added reference to native method defined in UnityBridge.h for direct communcation
private native void unityBridgeOnUnityMessage (String message);

@Override
public void onMessage(String message) {
ReactContext context = getReactApplicationContext();
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("onUnityMessage", message);
unityBridgeOnUnityMessage (message);
}

// Added callback referenced in UnityBridge.h for direct communcation
public static void postMessageToUnity (final String message)
{
UnityUtils.postMessage("UnityMessageManager", "onRNMessage", message);
}
}
11 changes: 11 additions & 0 deletions dist/MessageHandler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export declare const UnityMessagePrefix = "@UnityMessage@";
export default class MessageHandler {
id: number;
seq: 'start' | 'end' | '';
name: string;
data: any;
constructor();
static deserialize(message: string): MessageHandler;
static isUnityMessage(message: string): boolean;
send(data: any): void;
}
41 changes: 41 additions & 0 deletions dist/MessageHandler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/MessageHandler.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions dist/UnityModule.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import MessageHandler from './MessageHandler';
export interface UnityViewMessage {
name: string;
data: any;
callBack?: (data: any) => void;
}
export interface UnityModule {
/**
* Return whether is unity ready.
*/
isReady(): Promise<boolean>;
/**
* Manual init the Unity. Usually Unity is auto created when the first view is added.
*/
createUnity(): Promise<boolean>;
/**
* Send Message to UnityMessageManager.
* @param message The message will post.
*/
postMessageToUnityManager(message: string | UnityViewMessage): void;
/**
* Send Message to Unity.
* @param gameObject The Name of GameObject. Also can be a path string.
* @param methodName Method name in GameObject instance.
* @param message The message will post.
*/
postMessage(gameObject: string, methodName: string, message: string): void;
/**
* Pause the unity player
*/
pause(): void;
/**
* Pause the unity player
*/
resume(): void;
/**
* Receive string and json message from unity.
*/
addMessageListener(listener: (message: string | MessageHandler) => void): number;
/**
* Only receive string message from unity.
*/
addStringMessageListener(listener: (message: string) => void): number;
/**
* Only receive json message from unity.
*/
addUnityMessageListener(listener: (handler: MessageHandler) => void): number;
/**
* Remove message listener.
*/
removeMessageListener(handleId: number): void;
}
export declare const UnityModule: UnityModule;
162 changes: 162 additions & 0 deletions dist/UnityModule.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/UnityModule.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading