Hey guys,
does anyone know how to implement/embed the unity webplayer into a rails application?
I have tried several things now, the webplayer does show up, but it won’t load for some reason …
any ideas?
Cheers
zem
Hey guys,
does anyone know how to implement/embed the unity webplayer into a rails application?
I have tried several things now, the webplayer does show up, but it won’t load for some reason …
any ideas?
Cheers
zem
Did anyone solve this problem?
There really isn’t a problem to solve.
If you are just rendering a webplayer on a page, add the embedding code to your view (or write a helper or partial), just like you would any other html content. No different than embedding flash player other media.
I had a similar problem and solved it (Rails 4, Unity 4).
You need to understand the Rails asset pipeline a bit, so I recommend reading this: The Asset Pipeline — Ruby on Rails Guides
You probably built a web version of your game and opened the game.html that came alongside the game.unity3d and everything worked fine, right?
Then you tried using the same html and put the .unity3d in the same folder as the html (probably in the app/views directory) and then it didn’t work. The unity canvas was there but didn’t load. Well, at least that was what I did!
The reason it doesn’t work is because assets such as images (.jpg, .png) as well as our game.unity3d won’t be loaded in the Rails server. That’s why Rails got an /assets folder, you should put your assets there, and they will be loaded. So, I put my .unity3d in the /assets/game (yes you can create a folder there and it will be included) and then to get its reference I used the erb asset_path
. Don’t use the path string directly (eg. "/assets/game/game.unity3d), first because it’s a bad practice, and second because in the production environment the assets get a hash appended to their names.
So, here’s what I did:
1 - Copied the html unity generated to embed the game, and pasted it inside the view’s html where I wanted the game.
2 - Changed the line of code trying to load the game in the same directory and changed it to load from the assets
here is the line where the plugin load’s the game.unity3d according to the path provided in the second argument:
u.initPlugin(jQuery("#unityPlayer")[0], "game.unity3d");
So I put this, instead:
u.initPlugin(jQuery("#unityPlayer")[0], "<%= asset_path "game.unity3d" %>" );
(And, of course, change the “game.unity3d” to whatever name you got from your build.)
3 - Put the game in the /assets/game folder, but it could be directly in the /assets or /assets/images or whatever folder inside /assets you want!
4 - In the controller action for that view I wrote render layout: false, so Rails won’t try to write any layout’s header, because we should have the unity’s configuration header html. I’m not sure this step is necessary, you should try with and without.
That’s it, that should do!