Hi all! When working with WebGL build I'm trying to enable full screen mode. When working with the standard template no problem. I put in the GUI button and by pressing it launched different versions of the scripts. 1. Code (CSharp): Screen.fullScreen = !Screen.fullScreen; 2. Code (CSharp): Screen.SetResolution(Display.main.systemWidth, Display.main.systemHeight, true, 30); 3. A call to an external script, didn't work Code (CSharp): Application.ExternalEval("SetFullscreen(1)"); Everything works and switches to full screen mode correctly. The problem is that it requires not 1 but 2 clicks of the mouse. The first button, the second click in any area of the browser, then starts a full screen mode. Tell me, is there the possibility to switch to fullscreen mode of the game, with 1 click on the button standard template. Thank you!
I don't think there is a way around it, unless you switch to Fullscreen by default, then the user will only have to click once
Screen.fullScreen = !Screen.fullScreen Hello it_ra. Switching to fullscreen in a browser requires special privileges and can only be performed from an event handler initiated by the user. The problem is that Unity UI events go through an intermediate input queue, and are processed some time after their corresponding JavaScript handlers exit. Still there is a workaround for this. You should just use onPointerDown event instead of onClick. Create a UI Button, add a Event - Event Trigger component for this button, add Pointer Down event to the Event Trigger component, assign your function (with Screen.fullScreen = !Screen.fullScreen) to the Pointer Down event. Now it should work with a single click. How this trick works: As soon as the user pushes the UI button down, an onclick JavaScript event is registered for the whole page, so when user releases the mouse button somewhere over the page, a pure JavaScript onclick event handler is executed, where it is now possible to execute a privileged operation. In case of switching fullscreen mode, you don't need to implement any JavaScript handlers yourself, because those are already included by Emscripten. However, if you need to perform some other privileged operation on button click (i.e. open a popup, open a file opening dialog etc.), you may just add a corresponding JavaScript plugin, which will perform the onclick handling (see the window.open example here https://forum.unity3d.com/threads/popup-blocker-and-pointerdown-pointerclick.383233/#post-2491032)
For those who are wondering how you can make this work in the newer Unity's (starting from 2017 I think), this is how you get the fullscreen WebGL working on Android for Chrome and Firefox (iOS does not support fullscreen like it does on Android): JSLib Code (JavaScript): var LibraryPageTool = { GoFullscreen: function() { var viewFullScreen = document.getElementById('#canvas'); var ActivateFullscreen = function() { if (viewFullScreen.requestFullscreen) /* API spec */ { viewFullScreen.requestFullscreen(); } else if (viewFullScreen.mozRequestFullScreen) /* Firefox */ { viewFullScreen.mozRequestFullScreen(); } else if (viewFullScreen.webkitRequestFullscreen) /* Chrome, Safari and Opera */ { viewFullScreen.webkitRequestFullscreen(); } else if (viewFullScreen.msRequestFullscreen) /* IE/Edge */ { viewFullScreen.msRequestFullscreen(); } viewFullScreen.removeEventListener('touchend', ActivateFullscreen); } viewFullScreen.addEventListener('touchend', ActivateFullscreen, false); } }; mergeInto(LibraryManager.library, LibraryPageTool); CSharp Code (CSharp): using UnityEngine; #if UNITY_WEBGL && !UNITY_EDITOR using System.Runtime.InteropServices; #endif public class PageTool : MonoBehaviour { #if UNITY_WEBGL && !UNITY_EDITOR [DllImport("__Internal")] private static extern void GoFullscreen(); public static void ActivateFullscreen() { GoFullscreen(); } #else public static void ActivateFullscreen() {} #endif } As you can see 'canvas' has changed to '#canvas' in the newer WebGL builds. Also, just replace the 'touchend' with 'click' or 'mouseup' if you want this to work on desktop browsers. I hope this can help someone.
Thanks, where should this code go? Is it enough to put it in a c# script attached to the main camera?
this might be useful. https://github.com/leon-do/unity-webgl-fullscreen-dark-template Feedback (or a pr) will be useful!
@alexsuvorov This does not work consistently on version 2020.1 beta anymore. Sometimes it works, but sometimes I get the message
I can confirm this. OnMousDown and Input.GetMouseButtonDown(0) still seem to work but you have to implement the check if that's above your ui element manually it seems.
GET / GET /TemplateData/style.css GET /TemplateData/UnityProgress.js GET /%UNITY_WEBGL_LOADER_URL% ERROR: GET /%UNITY_WEBGL_LOADER_URL% URIError: URI malformed GET /%UNITY_WEBGL_LOADER_URL% ERROR: GET /%UNITY_WEBGL_LOADER_URL% URIError: URI malformed I am getting this error Unity version is 2021.1.6f1 Build link - https://drive.google.com/file/d/1wOld77KwtlE9tNM_aEPR_w_ynwfDgB5g/view?usp=sharing Could you please check and get back
It looks like that template was developed for Unity 2019.x syntax and earlier (https://github.com/leon-do/unity-we...b6832cf9/FullDarkThemeTemplate/index.html#L12). Unity 2020.1 introduced a new template syntax. That template will need to be updated to that format. Maybe the developer is able to help with that. A good way is to use the default or minimal template from Unity 2020.1 as a basis.
One more thing, is any settings specifically to be made for build working in Safari - for both Mac OS and iOS, having issue. With all other browsers in mobile (Android/iOS) and desktop for Mac and Windows are working. Build itself not get loaded. your browser does not support graphics api webgl 2.0 which is required for this content
This is a known issue with Apple. They have decided not to adopt WebGL 2 API in Safari browser. Even though the API is counting towards being 5 years old, they have decided to not provide the functionality. Unfortunately there is nothing we can do, we have pleaded them to add support for it for several years. There is a tech preview version of WebGL 2 available in Safari, but we do not know if/when it will ship. Maybe they think that it would compete with Apple's App Store too much if they enabled WebGL 2 in Safari.
By default, will get a full screen without a footer in WebGL build. -> Open the index.html file to edit -> Copy the following code inside the body Code (JavaScript): <body> <div class="webgl-content" style="display: table; width: 100%; height: 100%;"> <div id="unityContainer"></div> </div> <script> var mywidth = innerWidth; var myheight = innerHeight; document.getElementById("unityContainer").style.width = mywidth + "px"; document.getElementById("unityContainer").style.height = myheight + "px"; </script> </body>
Thank you for your prompt reply. I'm just using the demo scene "fullscreenwebGL" that you supply. It has a "pointerdown" on the "Enter" button. It detects full screen (or not fs) correctly and displays the appropriate button but the buttons don't work.
Is it like this on your scene? Change to Something must've gone wrong when I last updated this asset. Please confirm if this is the issue.
@dradb I saw your review on the store. Can you tell me if the solution above fixes the problem? I tried here and it works. I will update the plugin. EDIT Oh it's because on Unity 2019 you can't select static methods in the inspector...ok will fix asap. EDIT It's fixed, I submitted to the store.
Thanks Mark. Yes I saw that "missing". Do you know how long it takes to get through? Still showing the old version.
@Marks4 I am using your fullscreen asset in my game. It was made in 2019.4.23. Its working in a separate project. But when i import in my original project it is not working even though pointerdown is properly implemented in the button
My plugin was broken on Unity 2021, I recently updated it. I have a few questions. Are you using the latest version of my plugin? What Unity version are you using? Can you make a sample scene with the problem and share it? Reach out to me at marjob14@gmail.com to discuss further.
1. I have recently updated you plugin 2.I’m using unity 2019.4.23 3.While i build the sample scene from the same unity version the plugin is working but in my original project it shrinks the screen, I will share you the scenario in your mail. Thanks for replying