Unity player and Squarespace site

Is it possible to embed a Unity player within a Squarespace site? Inserting the HTML code displays a player window, but I can't seem to be able to upload the Unity file to the same folder. Squarespace defaults uploads to a storage directory. I tried editing the HTML to point to the \storage folder, but that didn't work.

I got it working. Just copy the three 'script' parts out of the Unity generated html, and then the 'object' part at the bottom. The path I used is 'storage/myunityfile.unity', but make sure you change it in all locations (I think there are 4 locations).

EDIT - OK here are more detailed instructions.

Here are the three 'script' part and the one 'object' part.

Part 1:

<script language='VBScript'>
        function DetectUnityWebPlayerActiveX
            on error resume next
            dim tControl, res, ua, re, matches, major
            res = 0
            set tControl = CreateObject("UnityWebPlayer.UnityWebPlayer.1")
            if IsObject(tControl) then
                if tControl.GetPluginVersion() = "2.5.0f5" then
                    ' 2.5.0f5 on Vista and later has an auto-update issue
                    ' on Internet Explorer. Detect Vista (6.0 or later)
                    ' and in that case treat it as not installed
                    ua = Navigator.UserAgent
                    set re = new RegExp
                    re.Pattern = "Windows NT (\d+)\."
                    set matches = re.Execute(ua)
                    if matches.Count = 1 then
                        major = CInt(matches(0).SubMatches(0))
                        if major < 6 then
                            res = 1
                        end if
                    end if
                else
                    res = 1
                end if
            end if
            DetectUnityWebPlayerActiveX = res
        end function
        </script>

Part 2:

<script language="javascript1.1" type="text/javascript">

            function GetUnity () {
                if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1)
                    return document.getElementById("UnityObject");
                else if (navigator.appVersion.toLowerCase().indexOf("safari") != -1)
                    return document.getElementById("UnityObject");
                else
                    return document.getElementById("UnityEmbed");
            }

            function DetectUnityWebPlayer () {
                var tInstalled = false;
                if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1) {
                    tInstalled = DetectUnityWebPlayerActiveX();
                }
                else {
                    if (navigator.mimeTypes && navigator.mimeTypes["application/vnd.unity"]) {
                        if (navigator.mimeTypes["application/vnd.unity"].enabledPlugin && navigator.plugins && navigator.plugins["Unity Player"]) {
                            tInstalled = true;  
                        }
                    }   
                }
                return tInstalled;  
            }

            function GetInstallerPath () {
                var tDownloadURL = "";
                var hasXpi = navigator.userAgent.toLowerCase().indexOf( "firefox" ) != -1;

                // Use standalone installer
                if (1)
                {
                    if (navigator.platform == "MacIntel")
                        tDownloadURL = "http://webplayer.unity3d.com/download_webplayer-2.x/webplayer-i386.dmg";
                    else if (navigator.platform == "MacPPC")
                        tDownloadURL = "http://webplayer.unity3d.com/download_webplayer-2.x/webplayer-ppc.dmg";
                    else if (navigator.platform.toLowerCase().indexOf("win") != -1)
                        tDownloadURL = "http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayer.exe";
                    return tDownloadURL;
                }
                // Use XPI installer
                else
                {
                    if (navigator.platform == "MacIntel")
                        tDownloadURL = "http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayerOSX.xpi";
                    else if (navigator.platform == "MacPPC")
                        tDownloadURL = "http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayerOSX.xpi";
                    else if (navigator.platform.toLowerCase().indexOf("win") != -1)
                        tDownloadURL = "http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayerWin32.xpi";
                    return tDownloadURL;
                }               
            }

            function AutomaticReload () {
                navigator.plugins.refresh();
                if (DetectUnityWebPlayer())
                    window.location.reload();

                setTimeout('AutomaticReload()', 500)
            }

        </script>

Part 3:

<script language="javascript1.1" type="text/javaScript">
                var hasUnity = DetectUnityWebPlayer();
                var brokenUnity = false;
                if (hasUnity) {

                    document.write('<object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="600" height="450"> 
');
                    document.write('  <param name="src" value="storage/FlythroughExample.unity3d" /> 
');
                    document.write('  <embed id="UnityEmbed" src="storage/FlythroughExample.unity3d" width="600" height="450" type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" /> 
');
                    document.write('</object>');

                    // if Unity does not define to GetPluginVersion on Safari on 10.6, we presume the plugin
                    // failed to load because it is not compatible with 64-bit Safari.
                    if (navigator.appVersion.indexOf("Safari") != -1
                        && navigator.appVersion.indexOf("Mac OS X 10_6") != -1
                        && document.getElementById("UnityEmbed").GetPluginVersion == undefined)
                        brokenUnity = true;

                    // 2.5.0 cannot auto update on ppc. Treat as broken.
                    else if (document.getElementById("UnityEmbed").GetPluginVersion() == "2.5.0f5" 
                        && navigator.platform == "MacPPC")
                        brokenUnity = true;
                }
                if (!hasUnity || brokenUnity) {

                    var installerPath = GetInstallerPath();
                    if (installerPath != "") {
                        // Place a link to the right installer depending on the platform we are on. The iframe is very important! Our goals are:
                        // 1. Don't have to popup new page
                        // 2. This page still remains active, so our automatic reload script will refresh the page when the plugin is installed
                        document.write('<div align="center" id="UnityPrompt"> 
');
                        if (brokenUnity)
                            document.write('  <a href= ' + installerPath + '><img src="http://webplayer.unity3d.com/installation/getunityrestart.png" border="0"/></a> 
');
                        else
                            document.write('  <a href= ' + installerPath + '><img src="http://webplayer.unity3d.com/installation/getunity.png" border="0"/></a> 
');
                        document.write('</div> 
');

                        // By default disable ActiveX cab installation, because we can't make a nice Install Now button
//                      if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1)
                        if (0)
                        {   
                            document.write('<div id="InnerUnityPrompt"> <p>Title</p>');
                            document.write('<p> Contents</p>');
                            document.write("</div>");

                            var innerUnityPrompt = document.getElementById("InnerUnityPrompt");

                            var innerHtmlDoc =
                                '<object id="UnityInstallerObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="320" height="50" codebase="http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayer.cab#version=2,0,0,0">
' + 
                                '</object>';

                            innerUnityPrompt.innerHTML = innerHtmlDoc;
                        }

                        document.write('<iframe name="InstallerFrame" height="0" width="0" frameborder="0"></iframe>
');
                    }
                    else {
                        document.write('<div align="center" id="UnityPrompt"> 
');
                        if (brokenUnity)
                            document.write('  <a href="javascript: window.open("http://www.unity3d.com/unity-web-player-2.x"); "><img src="http://webplayer.unity3d.com/installation/getunityrestart.png" border="0"/></a> 
');
                        else
                            document.write('  <a href="javascript: window.open("http://www.unity3d.com/unity-web-player-2.x"); "><img src="http://webplayer.unity3d.com/installation/getunity.png" border="0"/></a> 
');
                        document.write('</div> 
');
                    }

                    // hide broken player
                    if (brokenUnity)
                        document.getElementById("UnityEmbed").height = 0;

                    // Reload when detected unity plugin - but only if no previous plugin is installed 
                    // - in that case a browser restart is needed.
                    if (!brokenUnity)
                        AutomaticReload();
                }

            </script>

Part 4:

<object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="600" height="450" codebase="http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayer.cab#version=2,0,0,0">
                    <param name="src" value="storage/FlythroughExample.unity3d" />
                    <embed id="UnityEmbed" src="storage/FlythroughExample.unity3d" width="600" height="450" type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" />
                    <noembed>
                        <div align="center">
                            This content requires the Unity Web Player

                            <a href="http://www.unity3d.com/unity-web-player-2.x">Install the Unity Web Player today!</a>
                        </div>
                    </noembed>
                </object>

Now, if you search for 'flythrough' in those code parts you'll see the path to my Unity file FlythroughExample.unity3d. Because of the way squarespace stores stuff, when you add files they go to "storage/FlythroughExample.unity3d" so that is the path you have to replace in the scripts.

Remember to replace all paths. The third 'script' part has two paths to replace and the 'object' part has two paths.

Then when you're in the Squarespace editor writing your blog or whatever you hit the little cog button 'insert code block' and add them one by one. You can probably just paste all four in but I'm not sure about that.

My project for this week hopefully is to modify this so that it displays an image first, then when you click it will load the Unity file. But I'm very busy at the moment so we'll see if I have time [Loads Modern Warfare 2] ;-)

OK, I finally got around to working out how to Load-On-Demand the Unity Webplayer (show an image until the user clicks), plus I made things easier to implement for Squarespace blogs (but also for other blogs if they are similar).

I won't repeat everything here. I posted a topic over on the Unity forums here. That's basically a copy of my blog post here which has a little demo to show you it working.

Once you set up the unityscript.js file somewhere in your Squarespace storage, you should be able to add Unity Webplayer files very easily following the template I've provided.