Skip to content

Instantly share code, notes, and snippets.

@Chronojam
Created July 8, 2013 01:09
Show Gist options
  • Save Chronojam/5945585 to your computer and use it in GitHub Desktop.
Save Chronojam/5945585 to your computer and use it in GitHub Desktop.

Revisions

  1. Chronojam created this gist Jul 8, 2013.
    40 changes: 40 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    @"
    <html>
    <body style='font-family: Helvetica, Arial, sans-serif;'>
    <h1>Awesomium Rocks!</h1>
    <p>This web-page was loaded with HTML directly from within Unity3D.</p>

    <h2>Environment Info</h2>
    <dl>
    <dt>Unity Version</dt><dd id='stat1'></dd>
    <dt>Unity Platform</dt><dd id='stat2'></dd>
    <dt>Inside Editor?</dt><dd id='stat3'></dd>
    </dl>

    <p>The above info was passed to the web-page via a shared JS object.</p>

    <h2>Callback Example</h2>

    <p>The above button is hooked up to a Unity script via a shared JS callback.</p>

    <script type='text/javascript'>
    document.getElementById('stat1').innerText = App.unityVersion;
    document.getElementById('stat2').innerText = App.unityPlatform;
    document.getElementById('stat3').innerText = App.insideEditor;

    var socket = new WebSocket('ws://localhost:8182/');

    socket.onopen = function () {
    socks.opened();
    console.log('Connected to game');
    };

    socket.onmessage = function(packet) {
    document.body.innerHTML = packet['key'];
    //packet.key would also work.
    };
    //document.body.innerHTML = App.portNumber;
    </script>
    </body>
    </html>
    "