Search Unity

Where can I find a list of unityObject methods (functions)?

Discussion in 'Scripting' started by rotaercz, Jan 27, 2011.

  1. rotaercz

    rotaercz

    Joined:
    Mar 28, 2009
    Posts:
    34
    In the HTML file there is the following javascript...

    Code (csharp):
    1.  
    2. unityObject.embedUnity("unityPlayer", "WebPlayer/WebPlayer.unity3d", 760, 456);
    3.  
    .embedUnity is one of them... can anyone point me in the right direction regarding this documentation?
     
  2. popmog78

    popmog78

    Joined:
    Jan 19, 2011
    Posts:
    154
  3. popmog78

    popmog78

    Joined:
    Jan 19, 2011
    Posts:
    154
  4. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
  5. rotaercz

    rotaercz

    Joined:
    Mar 28, 2009
    Posts:
    34
    Thank you everyone for the replies and yes FizixMan, that was what I was asking about. Hmm... I'm trying to figure out how to change the width height (the 760, 456 values in the sample code), is there no function to do this in javascript?
     
  6. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    The way I handled sizing (at least in Unity 2.6.1) was to have the Unity plugin embedded HTML define its width/height as 100%. I didn't need to resize it manually via JavaScript (just let it fill its container), but I suppose at that point if you have the plugin wrapped with a div you can control that div's width and height properties which in turn Unity will size itself to fit.
     
    Last edited: Feb 1, 2011
  7. rotaercz

    rotaercz

    Joined:
    Mar 28, 2009
    Posts:
    34
    I've tried changing the div's width/height properties but it doesn't seem to do anything. Hmmm.... I think I'll have to keep experimenting.
     
  8. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    What does your embedding HTML/JavaScript code look like?
     
  9. rotaercz

    rotaercz

    Joined:
    Mar 28, 2009
    Posts:
    34
    Code (csharp):
    1.  
    2. <script type="text/javascript" language="javascript">
    3.     // unity related
    4.     function GetUnity() {
    5.         if (typeof unityObject != "undefined") {
    6.             return unityObject.getObjectById("unityPlayer");
    7.         }
    8.         return null;
    9.     }
    10.    
    11.     if (typeof unityObject != "undefined") {
    12.         unityObject.embedUnity("unityPlayer", "WebPlayer/WebPlayer.unity3d", 760, 456);
    13.     }
    14.  
    15. function ToggleWidth(targetLayer, w) {
    16.         var elem, vis;
    17.        
    18.         if( document.getElementById ) // this is the way the standards work
    19.             elem = document.getElementById( targetLayer );
    20.         else if( document.all ) // this is the way old msie versions work
    21.             elem = document.all[targetLayer];
    22.         else if( document.layers ) // this is the way nn4 works
    23.             elem = document.layers[targetLayer];
    24.         vis = elem.style;
    25.        
    26.         vis.width = w;
    27.     }
    28. </script>
    29.  
    30. <div id="unityPlayer" style="width:360px;height:456px;">
    31.             <div class="missing">
    32.                 <a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
    33.                     <img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
    34.                 </a>
    35.             </div>
    36.         </div>
    37.  
     
    Last edited: Feb 1, 2011
  10. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    Ahh, I did not bother with using the "embedUnity()" method. I handled the HTML manually, so my embed tags have its width/height listed as 100%, whereas that embedUnity you're passing a fixed 760x456.

    Maybe you can try:

    unityObject.embedUnity("unityPlayer", "WebPlayer/WebPlayer.unity3d", "100%", "100%");


    Is this the same UnityObject as from http://www.unifycommunity.com/wiki/index.php?title=UnityObject?
     
  11. rotaercz

    rotaercz

    Joined:
    Mar 28, 2009
    Posts:
    34
    Yeah, I actually tried that but it doesn't work. Could you provide an example of doing it manually? It'd be really helpful.
     
  12. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    Well, I just had it write out the HTML. I think this was how Unity 2.6.1 created the published HTML files and I just extracted it from there:

    Code (csharp):
    1. var unityHtml = '<object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="100%" height="100%"> \n' +
    2.                                 '  <param name="src" value="main.unity3d" /> \n' +
    3.                                 '  <embed id="UnityEmbed" src="main.unity3d" width="100%" height="100%" type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" ' +
    4.                                 '/> \n' +
    5.                                 '</object>';
    6.  
    7.                 document.getElementById("UnityWrapper").innerHTML = unityHtml;
    Notice the 100% for width/height. In my code I have a div:

    Code (csharp):
    1. <div id="UnityWrapper" />
    Theoretically, you should be able to alter that div's width/height and it should propagate to the Unity window.
     
  13. rotaercz

    rotaercz

    Joined:
    Mar 28, 2009
    Posts:
    34
    Thank you for all the help!

    I did actually figure out a different way. You can get access to the object and modify the style this way... Thanks again! :)

    Code (csharp):
    1.  
    2. function GetUnity() {
    3.         if (typeof unityObject != "undefined") {
    4.             return unityObject.getObjectById("unityPlayer");
    5.         }
    6.         return null;
    7.     }
    8.  
    9. GetUnity().style.width = 1;
    10. GetUnity().style.height = 1;
    11.  
    12.