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
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
example
scripts
docs
docs
template
2 changes: 2 additions & 0 deletions ios/RNUnityViewManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "RCTViewManager.h"
#if !TARGET_OS_SIMULATOR
#import <UnityFramework/UnityFramework.h>
#endif // !TARGET_OS_SIMULATOR
#import "UnityUtils.h"
#import "RNUnityView.h"

Expand Down
12 changes: 8 additions & 4 deletions ios/RNUnityViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ @implementation RNUnityViewManager
- (UIView *)view
{
self.currentView = [[RNUnityView alloc] init];
#if !TARGET_OS_SIMULATOR
if ([UnityUtils isUnityReady]) {
[self.currentView setUnityView: [GetAppController() unityView]];
} else {
[UnityUtils createPlayer:^{
[self.currentView setUnityView: [GetAppController() unityView]];
}];
[GetAppController() setUnityMessageHandler: ^(const char* message) {
[_bridge.eventDispatcher sendDeviceEventWithName:@"onUnityMessage"
body:[NSString stringWithUTF8String:message]];
}];
}

[GetAppController() setUnityMessageHandler: ^(const char* message) {
[_bridge.eventDispatcher sendDeviceEventWithName:@"onUnityMessage"
body:[NSString stringWithUTF8String:message]];
}];
#endif // !TARGET_OS_SIMULATOR

return self.currentView;
}

Expand Down
4 changes: 4 additions & 0 deletions ios/UnityNativeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
#import <React/RCTBridgeModule.h>
#import "UnityUtils.h"

#if TARGET_OS_SIMULATOR
@interface UnityNativeModule : NSObject <RCTBridgeModule>
#else
@interface UnityNativeModule : NSObject <RCTBridgeModule, UnityEventListener>
#endif
@end
2 changes: 2 additions & 0 deletions ios/UnityUtils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import <Foundation/Foundation.h>
#if !TARGET_OS_SIMULATOR
#import <UnityFramework/UnityFramework.h>
#endif // !TARGET_OS_SIMULATOR

#ifndef UnityUtils_h
#define UnityUtils_h
Expand Down
16 changes: 16 additions & 0 deletions ios/UnityUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

void UnityInitTrampoline();

#if !TARGET_OS_SIMULATOR
UnityFramework* ufw;
#endif // !TARGET_OS_SIMULATOR

extern "C" void InitArgs(int argc, char* argv[])
{
Expand All @@ -28,6 +30,7 @@
return unity_inited;
}

#if !TARGET_OS_SIMULATOR
UnityFramework* UnityFrameworkLoad() {
NSString* bundlePath = nil;
bundlePath = [[NSBundle mainBundle] bundlePath];
Expand All @@ -39,6 +42,7 @@
UnityFramework* ufw = [bundle.principalClass getInstance];
return ufw;
}
#endif // !TARGET_OS_SIMULATOR

extern "C" void InitUnity()
{
Expand All @@ -47,31 +51,39 @@
}
unity_inited = true;

#if !TARGET_OS_SIMULATOR
ufw = UnityFrameworkLoad();

[ufw setDataBundleId: "com.unity3d.framework"];
[ufw frameworkWarmup: g_argc argv: g_argv];
#endif // !TARGET_OS_SIMULATOR
}

extern "C" void UnityPostMessage(NSString* gameObject, NSString* methodName, NSString* message)
{
#if !TARGET_OS_SIMULATOR
dispatch_async(dispatch_get_main_queue(), ^{
[ufw sendMessageToGOWithName:[gameObject UTF8String] functionName:[methodName UTF8String] message:[message UTF8String]];
});
#endif // !TARGET_OS_SIMULATOR
}

extern "C" void UnityPauseCommand()
{
#if !TARGET_OS_SIMULATOR
dispatch_async(dispatch_get_main_queue(), ^{
[ufw pause:true];
});
#endif // !TARGET_OS_SIMULATOR
}

extern "C" void UnityResumeCommand()
{
#if !TARGET_OS_SIMULATOR
dispatch_async(dispatch_get_main_queue(), ^{
[ufw pause:false];
});
#endif // !TARGET_OS_SIMULATOR
}

@implementation UnityUtils
Expand All @@ -89,6 +101,7 @@ + (void)handleAppStateDidChange:(NSNotification *)notification
if (!_isUnityReady) {
return;
}
#if !TARGET_OS_SIMULATOR
UnityAppController* unityAppController = GetAppController();

UIApplication* application = [UIApplication sharedApplication];
Expand All @@ -106,6 +119,7 @@ + (void)handleAppStateDidChange:(NSNotification *)notification
} else if ([notification.name isEqualToString:UIApplicationDidReceiveMemoryWarningNotification]) {
[unityAppController applicationDidReceiveMemoryWarning:application];
}
#endif // !TARGET_OS_SIMULATOR
}

+ (void)listenAppState
Expand Down Expand Up @@ -146,6 +160,7 @@ + (void)createPlayer:(void (^)(void))completed
// Always keep RN window in top
application.keyWindow.windowLevel = UIWindowLevelNormal + 1;

#if !TARGET_OS_SIMULATOR
InitUnity();

UnityAppController *controller = GetAppController();
Expand All @@ -156,6 +171,7 @@ + (void)createPlayer:(void (^)(void))completed
[application.windows[1] makeKeyWindow];

[UnityUtils listenAppState];
#endif // !TARGET_OS_SIMULATOR
});
}

Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"name": "@asmadsen/react-native-unity-view",
"name": "@cartographr/react-native-unity-view",
"title": "React Native Unity View",
"version": "0.0.7",
"version": "0.0.10",
"description": "Embed Unity Player inside a React Native app",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rimraf dist/ && tsc"
"build": "rimraf dist/ && tsc",
"prepublishOnly": "yarn build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/asmadsen/react-native-unity-view.git",
"baseUrl": "https://github.com/asmadsen/react-native-unity-view"
"url": "git://github.com/cartographr/react-native-unity-view.git",
"baseUrl": "https://github.com/cartographr/react-native-unity-view"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"keywords": [
"react-native"
Expand Down
10 changes: 5 additions & 5 deletions react-native-unity-view.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ Pod::Spec.new do |s|
s.description = <<-DESC
react-native-unity-view
DESC
s.homepage = "https://github.com/asmadsen/react-native-unity-view"
s.homepage = "https://github.com/cartographr/react-native-unity-view"
s.license = "MIT"
# s.license = { :type => "MIT", :file => "LICENSE" }
s.authors = { "Andreas Storesund Madsen" => "[email protected]" }
s.platforms = { :ios => "9.0", :tvos => "10.0" }
s.source = { :git => "https://github.com/asmadsen/react-native-unity-view.git", :tag => "#{s.version}" }
s.source = { :git => "https://github.com/cartographr/react-native-unity-view.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm}"
s.public_header_files = 'ios/**/*.h'
s.frameworks = 'UnityFramework'
# s.weak_frameworks = 'UnityFramework'
s.dependency "React"

s.xcconfig = {
'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}/../UnityExport" "${PODS_CONFIGURATION_BUILD_DIR}"',
'OTHER_LDFLAGS' => '$(inherited) -framework UnityFramework ${PODS_LIBRARIES}'
'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}/../unityExport" "${PODS_CONFIGURATION_BUILD_DIR}"',
'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -framework UnityFramework ${PODS_LIBRARIES}'
}
end