Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TRemedio · Oct 27, 2014 at 10:42 PM · webplayerhtmltemplate

WebPlayer HTML Object Resize (with Aspect Ratio)

Hello everyone, good afternoon.

My name is Remedio and I'm having some issues on setting up a proper WebPlayer HTML where it would be resizable at runtime but following an Aspect Ratio pre-defined.

First of all I have searched for two days for something that would help me, but so far I only found solutions to Resizable with 100% of the window size (which uses only CSS properties, not Javascript) - With full screen resizable I have a template working perfectly.

Ok,let me show you my current code:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
 
         <title>Window Title</title>
 
 
         <script type='text/javascript' src='https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/jquery.min.js'></script>
         <script type="text/javascript">
         <!--
         var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
         if (document.location.protocol == 'https:')
             unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
         document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
         -->
         </script>
 
 
         <script type="text/javascript">
         <!--
             var nome_arquivo = "gameName.unity3d";
             var disableRightClick = true;
             var disableFullScreen = true;
             var desiredWidth = 16;
             var desiredHeight = 9;
 
     
             var larguraFinal = 0;
             var alturaFinal = 0;
             CalculateUnitySize();
 
             var config = {
                 width: larguraFinal, 
                 height: alturaFinal,
                 params: { enableDebugging:"0" }                
             };
 
             config.params["disableContextMenu"] = disableRightClick;
             config.params["disableFullscreen"] = disableFullScreen;
                 
             var u = new UnityObject2(config);
             
             jQuery(function() {
 
                 var $missingScreen = jQuery("#unityPlayer").find(".missing");
                 var $brokenScreen = jQuery("#unityPlayer").find(".broken");
                 $missingScreen.hide();
                 $brokenScreen.hide();
 
                 u.observeProgress(function (progress) {
                     switch(progress.pluginStatus) {
                         case "broken":
                             $brokenScreen.find("a").click(function (e) {
                                 e.stopPropagation();
                                 e.preventDefault();
                                 u.installPlugin();
                                 return false;
                             });
                             $brokenScreen.show();
                         break;
                         case "missing":
                             $missingScreen.find("a").click(function (e) {
                                 e.stopPropagation();
                                 e.preventDefault();
                                 u.installPlugin();
                                 return false;
                             });
                             $missingScreen.show();
                         break;
                         case "installed":
                             $missingScreen.remove();
                         break;
                         case "first":
                         break;
                     }
                 });
                 u.initPlugin(jQuery("#unityPlayer")[0], nome_arquivo);
             });
 
             function CalculateUnitySize()
             {    
                 var alturaTela = window.innerHeight;
                 var larguraTela = window.innerWidth;
     
                         if (desiredHeight > desiredWidth) 
                 {
                                 if (larguraTela > alturaTela * (desiredWidth / desiredHeight)) 
                     {
                                 alturaFinal = alturaTela;
                                 larguraFinal = parseInt(alturaFinal * (desiredWidth / desiredHeight));
                         }
                         else
                         {
                                 larguraFinal = larguraTela;
                                 alturaFinal = parseInt(larguraFinal * (desiredHeight / desiredWidth));
                         }
                 }
                 else
                     {
                     if(alturaTela > larguraTela * (desiredHeight / desiredWidth))        
                         {
                                 larguraFinal = larguraTela;
                                 alturaFinal = parseInt(larguraFinal * (desiredHeight / desiredWidth));
                         }
                         else
                     {
                                 alturaFinal = alturaTela;
                                 larguraFinal = parseInt(alturaFinal * (desiredWidth / desiredHeight));
                         }
                     }
             }
         -->
         </script>
 
         <style type="text/css">
         <!--
         body {
             font-family: Helvetica, Verdana, Arial, sans-serif;
             background-color: #000000;
             color: white;
             text-align: center;
         }
         a:link, a:visited {
             color: #000;
         }
         a:active, a:hover {
             color: #666;
         }
         p.header {
             font-size: small;
         }
         p.header span {
             font-weight: bold;
         }
         p.footer {
             font-size: x-small;
         }
         div.missing {
             margin: auto;
             position: relative;
             top: 50%;
             width: 193px;
         }
         div.missing a {
             height: 63px;
             position: relative;
             top: -31px;
         }
         div.missing img {
             border-width: 0px;
         }
         -->
         </style>
     </head>
     <body>
         <body marginheight="0" topmargin="0" vspace="0" marginwidth="0" leftmargin="0" hspace="0" style="margin:0; padding:0">
         <center>
             <div class="content">
                 <div id="unityPlayer">
                     <div class="missing">
                         <a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
                             <img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
                         </a>
                     </div>
                 </div>
             </div>
         </center>
     </body>
 </html>

This is working perfectly when I only start the browser (it will calculate the correct Aspect Ration and show the object of the right size). However, if I manipulate the window (resize, maximize, etc) the object will have the original size.

What I need is figure how to call that "CalculateUnitySize()" function of mine everytime the browser detects it has been resized. I have no idea how to do that. And also, how to inform the Unity object that it must resize too.

Please help me :)

Thanks in advance for everyone.

Remedio

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TRemedio · Oct 28, 2014 at 05:48 PM 0
Share

So, I found that I can add:

 window.onresize = CalculateUnitySize;

In my script. It works great, as it is triggered every time the browser is resized (and returns the correct values). The issue now is only to pass those values to the unity object itself.

Some people say to use:

 document.getElementById('unityPlayer').style.width=larguraFinal;
 document.getElementById('unityPlayer').style.height=alturaFinal;


But the object ins't updated at all!

Any help please!

avatar image TRemedio · Oct 31, 2014 at 03:19 PM 0
Share

Okay, only as a headsup what I'm currently doing is having a 100% area of the browser player and then, inside Unity object itselft I use cameras to give me the Aspect Ratio I want (with other cameras rendering the letter box or pillar box areas).

$$anonymous$$ore details on how to use those cameras can be found here: http://gamedesigntheory.blogspot.ie/2010/09/controlling-aspect-ratio-in-unity.html

avatar image Ben-BearFish · Oct 12, 2015 at 07:08 PM 0
Share

@Remedio.tv Did you ever figure out how to pass those values to the UnityObject, or are you using the Unity Camera to change the Aspect Ratio?

Also, could you share your solution?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Hosting a game on dropbox 1 Answer

Post my game on the Blog 1 Answer

External call to a method not on the WebPlayer.html 1 Answer

How to wait for unity webplayer to load and then invoke its function? 0 Answers

custom webplayer not building project 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges