Skip to content

Instantly share code, notes, and snippets.

@tracend
Created July 10, 2012 08:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/3082093 to your computer and use it in GitHub Desktop.
Save tracend/3082093 to your computer and use it in GitHub Desktop.
[DEPRECATED]: Dead simple method to include Unity3D web player(s) using jQuery. Project moved to : http://github.com/makesites/jquery-unity3d

$.unity3d()

One-liner to embed / interact with Unity3D files using jQuery

Usage

Target the container you want the unity3d file embedded and call the plugin the traditional way:

$(target).unity3d(); 

The unity3d() method accepts the following options:

  • width - the width of the embedded file (default: 600)
  • height - the height of the embedded file (default: 450)
  • file - the location of the embedded file (default: "WebPlayer.unity3d")
  • params - an object containing extra parameters for the embed code. Currently only "disableContextMenu" is supported...

If no options are passed the default ones will be used

API

In addition, there are a set number of methods to interact with the unity3d file:

  • $.unity3d.get(id) : Returns the unity3d object with the specified id
{
"name": "jquery-unity3d",
"version": "0.2.0",
"main": ["./jquery.unity3d.js"],
"dependencies": {
"jquery": "~1.8.2"
}
}
<!doctype html>
<html>
<head>
<title>Unity Web Player</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery.unity3d.js"></script>
<script type="text/javascript">
$(function(){
$("#unityPlayer").unity3d({
file : "http://cdn.unitypeeps.com/files/501aec1bb58a0.unity3d"
});
});
</script>
</head>
<body>
<div id="unityPlayer">
<div class="missing">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
<img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
</a>
</div>
</div>
</body>
</html>
/**
* unity3d - jQuery plugin to embed Unity3D files
* Created by: Makis Tracend (@tracend)
*
* Licensed under the MIT licenses:
* http://www.opensource.org/licenses/mit-license.php
*
**/
(function( $ ) {
$.unity3d = function(options, container) {
var $this = $(this);
var settings = $.extend( {
width : 600,
height : 450,
file : "WebPlayer.unity3d",
params: {
disableContextMenu: false
}
}, options);
// save settings for other methods
$(this).data('settings', settings);
$(this).data('container', container);
var methods = {
init : function( $this ){
var self = this;
// load the unity object script
$.getScript("http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js", function () {
self.embed( $this );
});
},
embed : function( $this ){
var settings = $this.data('settings'),
container = $this.data('container');
// extract embed parameters
var params = settings.params,
width = settings.width,
height = settings.height,
file = settings.file,
id = container.attr("id");
unityObject.embedUnity( id, file, width, height, params);
},
destroy : function( $this ) {
var settings = $this.data('settings');
data.settings.remove();
$this.removeData('settings');
}
}
//initialize
//$.unity3d.init( settings );
methods.init( $this );
return this;
}
// API
$.unity3d.get = function(id) {
if (typeof unityObject != "undefined") {
return unityObject.getObjectById(id);
}
return null;
};
// extending jQuery namespace
$.fn.unity3d = function(options) {
return this.each(function() {
(new $.unity3d(options, $(this)));
});
};
})(jQuery);
//Helper
function unity3d(options) {
return jQuery.unity3d(options);
}
{
"name": "unity3d",
"version": "0.2.0",
"title": "jQuery Unity3D",
"description": "One-liner to embed / interact with Unity3D files using jQuery",
"keywords": [
"unity3d",
"3d",
"graphics",
"games",
"visuals"
],
"author": {
"name": "Makesites",
"url": "http://makesites.org"
},
"maintainers": [
{
"name": "Makis Tracend",
"email": "makis@makesit.es",
"url": "http://github.com/tracend"
}
],
"bugs": "https://github.com/makesites/jquery-unity3d/issues",
"homepage": "https://github.com/makesites/jquery-unity3d",
"docs": "https://github.com/makesites/jquery-unity3d",
"download": "http://plugins.jquery.com/unity3d",
"licenses": [
{
"type": "MIT License",
"url": "http://makesites.org/licenses/MIT"
}
],
"dependencies": {
"jquery": "~1.8.2"
}
}
@tracend
Copy link
Author

tracend commented Mar 1, 2013

Note this gist is now DEPRECATED.

Project moved to : http://github.com/makesites/jquery-unity3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment