3 'remoto!stdlib:js/panes/pane.js',
4 'remoto!stdlib:js/include/utils.js',
5 'remoto!stdlib:js/include/objectRegistry.js',
6 'remoto!stdlib:js/panes/panes/unityPane.css',
34 pane.call(
this,layout);
36 this._type =
"unityPane";
51 this._progress =
null;
52 this._instance =
null;
53 this._createUnityInstance =
null;
57 this._unityActivate =
null;
58 this._unityDeactivate =
null;
60 this._subscriptions = {};
65 if (this._html)
return this._html;
69 var h = this._content;
70 h.addClass(
"unityPane");
72 var c = $(
"<canvas class='unityCanvas'>").appendTo(this._content);
73 c.attr(
"tabindex",
"-1");
74 c.bind(
"mouseenter mousemove",
function() { c.focus(); } );
95 if (!this._config.urlPrefix || !
this._config.config)
96 console.error(
"unityPane subscription did not contain a url");
98 var
url = this._config.urlPrefix +
"/" + this._config.config;
100 if (
url !== this._url)
105 var jqxhr = $.get( this._url )
106 .done( this.configLoaded.bind(
this) )
107 .fail( this.configLoadFail.bind(
this,
this._url) );
109 this._html.trigger(
"paneLoadStart");
115 console.error(
"unityPane applyRequestError",arguments);
121 console.error(
"FIXME: unityPane applyDiff()",arguments);
144 this._config.devicePixelRatio = this._config.scale;
149 $.getScript( this._config.loaderUrl )
150 .done(
function( data, textStatus, jqxhr )
152 if (textStatus ===
"success")
156 THIS._createUnityInstance = window.createUnityInstance;
157 delete window.createUnityInstance;
161 THIS._createUnityInstance(THIS._canvas, THIS._config, THIS.loadProgress.bind(THIS) )
162 .then( THIS.loadComplete.bind(THIS) )
163 .
catch( THIS.loadError.bind(THIS) );
166 THIS.configLoadFail(THIS._config.loaderUrl);
168 .fail( this.configLoadFail.bind(
this,
this._config.loaderUrl ) );
173 console.error(
"Failed to load unity setup: ",
url);
178 console.error(
"unity load error",arguments);
185 console.log(
"FIXME create progress widget!",
progress);
189 console.log(
"unityPane load progress: ",
progress);
192 unityPane.prototype.loadComplete =
function(unityInstance)
196 this._instance = unityInstance;
201 var sessionInfo = this._config.sessionInfo;
203 this.toUnity = unityInstance.Module[
"asmLibraryArg"][
"toUnity"].bind(
this);
204 this._unityActivate = unityInstance.Module[
"asmLibraryArg"][
"activatePane"].bind(
this);
205 this._unityDeactivate = unityInstance.Module[
"asmLibraryArg"][
"deactivatePane"].bind(
this);
206 unityInstance.Module[
"asmLibraryArg"][
"registerPane"]( this.fromUnity.bind(
this), sessionInfo, this.vfsClientRunning.bind(
this) );
217 unityPane.prototype.vfsClientRunning =
function()
220 this._html.trigger(
"paneLoadComplete");
223 unityPane.prototype.quitComplete =
function()
226 console.log(
"Unity quit complete!",arguments);
229 unityPane.prototype.fromUnity =
function(request)
233 var command = request.command;
234 var attributes = request.attributes;
238 case "subscribe":
for (var p in attributes)
241 if (p in this._subscriptions)
242 this._subscriptions[p].increment(attributes[p]);
244 this._subscriptions[p] =
new unitySubscription(p,attributes[p],
this);
249 case "unsubscribe":
for (var p in attributes)
256 console.log(
"can't unsubscribe yet!",p,attributes[p]);
261 default: console.error(
"Unknown command: "+command);
270 if (this._unityActivate)
271 this._unityActivate();
276 this._active =
false;
278 if (this._unityDeactivate)
279 this._unityDeactivate();
284 console.error(
"the unityPane::toUnity method will be overridden once the instance has loaded.");
289 for (var s in this._subscriptions)
290 this._subscriptions[s].destroy();
291 this._subscriptions = {};
294 { this._instance.Quit( this.quitComplete.bind(
this) );
295 this._instance.Module[
"asmLibraryArg"][
"_unregisterPane"]();
301 this._instance =
null;
302 this._createUnityInstance =
null;
303 this._unityActivate =
null;
304 this._unityDeactivate =
null;
315 function unitySubscription(
path,count,instance)
318 this._count = count * 1 || 1;
319 this._instance = instance;
324 unitySubscription.prototype.applySubscription =
function(data,
metadata)
329 command:
"subscribe",
337 this._instance.toUnity(c);
340 unitySubscription.prototype.applyDiff =
function(diff,
user)
353 this._instance.toUnity(c);
356 unitySubscription.prototype.increment =
function(c)
359 { this._count += c * 1;
364 unitySubscription.prototype.decrement =
function(d)
366 console.log(
"FIXME: can't decrement yet");
369 unitySubscription.prototype.destroy =
function()
message(m)
Change the message of an existing arrowMessage.
getter id
returns the number of milliseconds since midnight January 1, 1970 UTC
setter scale
Set a scale value for rendering.
registerObject(id, o, nosubscribe)
Register an object in the registry, and call the pathAddedCallback.
unregisterObject(id, o, silent, nounsubscribe, now)
Unregister an object from the registry.
Create a pane which will be mounted into a paneManager layout.
applyRequestError(command, id, reason)
deactivate()
If a deactivate method is present on this pane's _object, call it.
applySubscription(data, metadata)
deactivate()
Deactivate this element and call deactivate on all its children.
setter config
a setter DOCME
getter path
a getter DOCME
progress(c, t, f, w, hoc)
The unityPane will load a WebGL-compiled Unity project into a pane.
Utility functions for javascript clients.
cleanPath(path)
Clean and normalize a resource path.
copyObject(source, dest)
Create a deep copy of a JSON object, extending the destination object recursively.
resolveContextValues(o, ctx)
Recursively resolve any context values in an object.