- Home /
How to execute SendMessage when the Web Player is in an object DOM?
I need to work in Linux, and since the Web Player is not supported on Linux, I inserted a case for "unsupported" in the observeProgress function. It inserts a DOM like this:
<object id="UnityObject" width="100%" height="100%">
<embed id="UnityEmbed" src="/game.unity3d"
width="100%" height="100%" type="application/vnd.unity"
pluginspage="http://www.unity3d.com/unity-web-player-2.x" />
</object>
And displays a disclaimer that the plugin is unsupported. This way, I can still test the game with PipeLight without having to fire up a Windows VM.
Unfortunately, there are various SendMessage calls in JavaScript to the UnityObject2 object, and Application.ExternalCall calls from within the Web Player. I have no idea how to handle these when Unity3D has been loaded within an < object > DOM, and not with the UnityObject2 class. Does anyone know what the solution is?
Answer by Vax4566 · Mar 17, 2014 at 02:30 AM
I ended up inserting a jQuery function that loads either UnityObject2 or UnityObject depending on the platform. Afterwards, you can just get the Unity plugin and use SendMessage by just grabbing the DOM.
if(navigator.platform.toUpperCase().indexOf('WIN') !== -1
|| navigator.platform.toUpperCase().indexOf('MAC') !== -1) {
$.getScript("http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js")
.done(function() {
var unityConfig = new UnityObject2(config);
//...
unityConfig.initPlugin($("#unitygame")[0], game);
});
} else {
$.getScript("http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js")
.done(function(){
unityObject.embedUnity("unitygame", game, config.width, config.height);
});
}
//...
var u = $("#unitygame embed")[0];
u.SendMessage("function", "param");
Your answer
Follow this Question
Related Questions
Post my game on the Blog 1 Answer
External call to a method not on the WebPlayer.html 1 Answer
custom webplayer not building project 0 Answers
How to wait for unity webplayer to load and then invoke its function? 0 Answers
Unity 3.0 Webplayer at 100% 7 Answers