Skip to content

Commit 2a10663

Browse files
committed
feat(release): initial release
0 parents  commit 2a10663

File tree

6 files changed

+206
-0
lines changed

6 files changed

+206
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Olivier Louvignes
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Cordova SecureDeviceIdentifier #
2+
by [Olivier Louvignes](http://olouv.com)
3+
4+
## DESCRIPTION ##
5+
6+
* This plugin provides a simple way to integrate and communicate with an Unity view.
7+
8+
* This plugin is built for Cordova >= v2.1.0 with ARC, it has been tested to work without ARC.
9+
10+
## PLUGIN SETUP FOR IOS ##
11+
12+
Using this plugin requires [Cordova iOS](https://github.com/apache/incubator-cordova-ios).
13+
14+
1. `cordova plugin add io.mgcrea.Unity`
15+
16+
## JAVASCRIPT INTERFACE (IOS/ANDROID) ##
17+
18+
// After device ready, create a local alias
19+
var Unity = cordova.plugins.Unity;
20+
21+
Unity.show({x: 200, y: 200, width: 512, height: 384});
22+
Unity.sendMessage("foo;bar");
23+
Unity.hide();
24+
25+
* Check [source](https://github.com/mgcrea/cordova-unity/tree/master/www/Unity.js) for additional configuration.
26+
27+
## BUGS AND CONTRIBUTIONS ##
28+
29+
Patches welcome! Send a pull request. Since this is not a part of Cordova Core (which requires a CLA), this should be easier.
30+
31+
Post issues on [Github](https://github.com/mgcrea/cordova-unity/issues)
32+
33+
The latest code (my fork) will always be [here](https://github.com/mgcrea/cordova-unity/tree/master)
34+
35+
## LICENSE ##
36+
37+
The MIT License (MIT)
38+
39+
Copyright (c) 2015 Olivier Louvignes
40+
41+
Permission is hereby granted, free of charge, to any person obtaining a copy
42+
of this software and associated documentation files (the "Software"), to deal
43+
in the Software without restriction, including without limitation the rights
44+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45+
copies of the Software, and to permit persons to whom the Software is
46+
furnished to do so, subject to the following conditions:
47+
48+
The above copyright notice and this permission notice shall be included in all
49+
copies or substantial portions of the Software.
50+
51+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57+
SOFTWARE.
58+
59+
## CREDITS ##
60+
61+
Contributors :
62+
63+
* [Olivier Louvignes](http://olouv.com), author.
64+

plugin.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version='1.0' encoding='utf-8' ?>
2+
<plugin id="io.mgcrea.Unity" version="0.1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<name>Unity</name>
4+
<js-module name="Unity" src="www/Unity.js">
5+
<clobbers target="cordova.plugins.Unity" />
6+
</js-module>
7+
<platform name="ios">
8+
<config-file parent="/*" target="config.xml">
9+
<feature name="Unity">
10+
<param name="ios-package" value="Unity" />
11+
</feature>
12+
</config-file>
13+
<source-file src="src/ios/Unity.m" />
14+
</platform>
15+
</plugin>

src/ios/Unity.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/********* Unity.m Cordova Plugin Implementation *******/
2+
3+
#import <Cordova/CDV.h>
4+
#import "UI/UnityView.h"
5+
#import "UnityAppController.h"
6+
7+
@interface Unity : CDVPlugin {
8+
UnityAppController* _appDelegate;
9+
UnityView* _unityView;
10+
UIView* _rootView;
11+
}
12+
13+
@property (nonatomic, strong) UIViewController* unityViewController;
14+
- (void)coolMethod:(CDVInvokedUrlCommand*)command;
15+
- (void)show:(CDVInvokedUrlCommand*)command;
16+
@end
17+
18+
@implementation Unity
19+
20+
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView
21+
{
22+
DLog(@"initWithWebView: theWebView");
23+
self = [super initWithWebView:theWebView];
24+
if (self) {
25+
_appDelegate = (UnityAppController *)[[UIApplication sharedApplication] delegate];
26+
_unityView = _appDelegate.unityView;
27+
_rootView = _appDelegate.rootView;
28+
}
29+
return self;
30+
}
31+
32+
- (void)show:(CDVInvokedUrlCommand*)command
33+
{
34+
CDVPluginResult* pluginResult = nil;
35+
36+
float x = [[command argumentAtIndex:0] floatValue];
37+
float y = [[command argumentAtIndex:1] floatValue];
38+
float width = [[command argumentAtIndex:2] floatValue];
39+
float height = [[command argumentAtIndex:3] floatValue];
40+
DLog(@"show: [%f,%f,%f,%f]", x, y, width, height);
41+
42+
CGRect unityFrame = CGRectMake(x, y, width, height);
43+
_unityView.frame = unityFrame;
44+
[_rootView addSubview:_unityView];
45+
46+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES];
47+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
48+
}
49+
50+
- (void)hide:(CDVInvokedUrlCommand*)command
51+
{
52+
CDVPluginResult* pluginResult = nil;
53+
DLog(@"hide:");
54+
55+
[_unityView removeFromSuperview];
56+
57+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES];
58+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
59+
}
60+
61+
- (void)sendMessage:(CDVInvokedUrlCommand*)command
62+
{
63+
CDVPluginResult* pluginResult = nil;
64+
NSString* message = [command.arguments objectAtIndex:0];
65+
DLog(@"sendMessage: [%@]", message);
66+
67+
UnitySendMessage("DeviceCommunication", "MobileToUnity", [message UTF8String]);
68+
69+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES];
70+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
71+
}
72+
73+
@end

www/Unity.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
var exec = require('cordova/exec');
4+
5+
function defaults(object, source) {
6+
if(!object) object = {};
7+
for(var prop in source) {
8+
if(typeof object[prop] === 'undefined') {
9+
object[prop] = source[prop];
10+
}
11+
}
12+
return object;
13+
}
14+
15+
exports.show = function(options, success, error) {
16+
defaults(options, {
17+
x: 200,
18+
y: 200,
19+
width: 512,
20+
height: 384
21+
});
22+
var args = [options.x, options.y, options.width, options.height];
23+
exec(success, error, 'Unity', 'show', args);
24+
};
25+
26+
exports.hide = function(arg0, success, error) {
27+
exec(success, error, 'Unity', 'hide', [arg0]);
28+
};
29+
30+
exports.sendMessage = function(message, success, error) {
31+
exec(success, error, 'Unity', 'sendMessage', [message + '']);
32+
};

0 commit comments

Comments
 (0)