UnrealEngineHTML5 / Documentation

540 stars 183 forks source link

[question] Communicate from ingame to browser #42

Open ZeusLT opened 4 years ago

ZeusLT commented 4 years ago

I have very similar question to this one:: https://github.com/UnrealEngineHTML5/Documentation/issues/6 , but the opposite of it, is it possible to relay commands from inside the game to the browser running the game, for example I want to make ingame "fullscreen" button and remove/hide the html one so I do not have to deactivate the game frame to go fullscreen.

ZeusLT commented 4 years ago

ok this plugin seems to work: https://github.com/tgraupmann/UE4HTML5SamplePlugin , just needs to be changed a little in "SampleHTML5.js" to remove "Runtime." from "Runtime.dynCall".

Something simple like this should be just included in the main branch.

nickshinpho commented 4 years ago

in #6 -- i've also added instructions on howto:

from C++ calling JS functions (basically everything in the extern "C" .h file)

but, to your specific fullscreen request: (wow, never realized that we never put in a fullscreen mode from c++... ha! ... guess, the F11 and ESC keys was way more common to handle than having the game do that for you automatically...)

anyways, in your c++ function you will need to put something like this:

// in UE4 C++ code:
MAIN_THREAD_EM_ASM( your_fullscreen_function_in_js(); );

then, in your JS code (/Build/HTML/.js.template` is a good place to put this) add:

// your project's JS code
function your_fullscreen_function_in_js() {
    document.getElementById('fullscreen_request').click();
}

or something like that... i didn't test that so you may need to play around with those lines of code to get it to work...

ZeusLT commented 4 years ago

Funny thing, when you enter full screen and run the same function again, it runs the function again but doesn't leave the full screen, which is fine, but when clicking ESC to leave full screen the game window doesn't resize to normal and stays huge with all of the website elements on top, it gets fixed after resizing window, but background stays black

nickshinpho commented 4 years ago

@ZeusLT is this still an issue for you?

if so, can you provide a demo page link exhibiting this behavior?

TheLacrox commented 3 years ago

@nickshinpho I have to say that i'm really interested on it as well, i have been working with unity and webgl, and in unity there is a option to send console commands to the unity app with js, that makes the job easier, because you can trigger events or do a lot of things, I'm working on that right now if i made any progress, i might do a pull request to have it in here by default.