WebGLInput icon indicating copy to clipboard operation
WebGLInput copied to clipboard

Full screen in Unity 2020?

Open DevNoam opened this issue 4 years ago • 7 comments

<div class="fullscreen" onclick="gameInstance.SetFullscreen(1)"></div Is not appears on Unity 2020 Index.html.

Is there other solution to enable Full screen support for Unity 2020?

DevNoam avatar Oct 01 '20 10:10 DevNoam

in Unity2020 WebGL Template you can find the fullscreen code fullscreenButton.onclick = () => { unityInstance.SetFullscreen(1); };

you can try to change this to fullscreenButton.onclick = () => { document.makeFullscreen('unity-container'); };

kou-yeung avatar Oct 02 '20 06:10 kou-yeung

in Unity2020 WebGL Template you can find the fullscreen code fullscreenButton.onclick = () => { unityInstance.SetFullscreen(1); };

you can try to change this to fullscreenButton.onclick = () => { document.makeFullscreen('unity-container'); };

Its working, but the full screen is not a true full screen:

Untitled

DevNoam avatar Oct 02 '20 07:10 DevNoam

previously in the index.html file there is the line var container = document.querySelector("#unity-container" could it be that we need to refer to the unity-container with the # in front (I tried this but Chrome went bananas)

garethdenyer avatar Jan 23 '21 12:01 garethdenyer

I found some success getting the fullscreen to scale properly when I manually adjusted the width and height properties of the surrounding div and canvas elements: <div style="width: 1001px; height: 630px; border:0; margin:0; background-color: rgb(109,25,13);">

<div id="unity-container">
  <canvas id="unity-canvas" width =  "1001" height= "580"></canvas>
  <div id="unity-loading-bar">
    <div id="unity-logo"></div>
    <div id="unity-progress-bar-empty">
      <div id="unity-progress-bar-full"></div>
    </div>
  </div>
 </div>
</div>

EDIT: This caused problems for me when users zoom in or out of the webpage, so it's not a permanent solution.

mmoy92 avatar Jan 25 '21 09:01 mmoy92

mmoy92 - thanks very much for that lead

garethdenyer avatar Jan 30 '21 20:01 garethdenyer

Is there any method to detect exiting full-screen mode through index html file in webgl build

guru-1234 avatar Jul 20 '22 11:07 guru-1234

@guru-1234 FYR: https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenchange_event you can try document.fullscreenElement to handled the event

kou-yeung avatar Jul 23 '22 00:07 kou-yeung

I found some success getting the fullscreen to scale properly when I manually adjusted the width and height properties of the surrounding div and canvas elements: <div style="width: 1001px; height: 630px; border:0; margin:0; background-color: rgb(109,25,13);">

<div id="unity-container">
  <canvas id="unity-canvas" width =  "1001" height= "580"></canvas>
  <div id="unity-loading-bar">
    <div id="unity-logo"></div>
    <div id="unity-progress-bar-empty">
      <div id="unity-progress-bar-full"></div>
    </div>
  </div>
 </div>
</div>

EDIT: This caused problems for me when users zoom in or out of the webpage, so it's not a permanent solution.
``` } else {
    // Desktop style: Render the game canvas in a window that can be maximized to fullscreen:

   // canvas.style.width = "960px";
    //canvas.style.height = "600px";
  }

deactivate This

113kangkang avatar Jun 16 '23 08:06 113kangkang

The problem seems to have been solved. Change canvas.style.width and height to the size of the screen when in full screen, and then to the initial size when exiting full screen. At this point, it can be used normally in the full-screen state. Of course, you also need to change the full-screen click method to:

 fullscreenButton.onclick = () => {
            //unityInstance.SetFullscreen(1);
           document.makeFullscreen('unity-container');
          };
  document.addEventListener('fullscreenchange', handleFullscreenChange);
      function handleFullscreenChange() {
      var isFullscreen = document.fullscreenElement !== null;
      if (isFullscreen) {
        console.log('Entered fullscreen mode');
        canvas.style.width = screen.width+ 'px';
        canvas.style.height = screen.height+ 'px';
      } else {
        console.log('Exited fullscreen mode');
        canvas.style.width = "1366px";
        canvas.style.height = "768px";
      }
      }

Xinayin avatar Jan 20 '24 10:01 Xinayin