I have put together a small project for WebGL, there is an exit button,(Application.Quit()), but when it is called, the window just freezes.
public void ExitGame()
{
print("exitGame");
Application.Quit();
}
The Application.Quit() method is a great way to quit the game on a desktop game but it can't be use to close a browser tab for example in your case, where you are working with WebGL.
What you could instead try is to redirect the player to a new webpage when the player eventually quits the game.
Quitting is used in desktop apps, and isn't designed for use in WebGL builds. Quitting from a WebGL game isn't possible - you can't close the window.
Related
i wrote a console app in c# that listens for specific keypresses on the keyboard and executes code afterwards. Everything works fine as long as the program is the active program.
But I want the program to run also when I "tabbed" out of it.
In other words: When I'm playing a computer game and I press F1, I want the code of my program to be executed.
Is there an easy way to implement it? Is it even possible with console applications?
Thanks in advance :)
How do I write a function which detects when iPad's screen is off/power button is pressed and also when home button is pressed?
I know OnApplicationFocus() and OnApplicationPause() functions but they run only when I press Power button on the iPad when Run in Background is set to suspend, and when Run in Background is set to exit, these functions stop working when power button is pressed. Is there a workaround?
Use OnApplicationQuit.
From the manual:
Note: iOS applications are usually suspended and do not quit. You
should tick "Exit on Suspend" in Player settings for iOS builds to
cause the game to quit and not suspend, otherwise you may not see this
call. If "Exit on Suspend" is not ticked then you will see calls to
OnApplicationPause instead.
I'm working on an Oculus Go app in Unity and found that quitting the app in the headset does not call onApplicationQuit(). Does anyone know a good workaround for this? I really need to have some code that only executes when the app closes.
I've tried using OnDestroy() as a workaround, but it also is not called when the app is closed. OnPaused() is called when you enter the Oculus dialog that asks if you want to exit, not when you actually select exit.
As you already stated, OnApplicationQuit() is never actually invoked when exiting an app on the Go from the Oculus menu. The app is instead placed into a suspended state for which little can be done. Aside from hooking into native code or some android java plugin (the details thereof are not my forte), there isn't much of a known workaround for this.
Part of this reason is because the workaround really does depend on the needs of the app, saving state or PlayerPrefs can be done in the OnApplicationPause() method.
private void OnApplicationPause(bool isPaused)
{
if (isPaused) {
// ..
PlayerPrefs.Save();
}
}
This is probably the simplest solution, for single player/user games/apps. For multiplayer games, you can subscribe to OVR's connection state changed event and handle the user who just quit from the inversed side:
using Oculus.Platform;
using Oculus.Platform.Models;
// ...
Net.SetConnectionStateChangedCallback((Message<NetworkingPeer> message) => {
if (message.Data.State == PeerConnectionState.Closed) {
Debug.Log("The user MOST LIKELY quit the app.");
}
});
This is not a perfect solution but since OVR doesn't provide anything in their docs and they don't respond to questions on this topic in their forums, this is a decent enough workaround.
The only other option is to encourage users to click on some sort of "Quit" button from within your app which calls UnityEngine.Application.Quit() which will indeed invoke the OnApplicationQuit() method.
Cheers.
If you are developing and publishing for the Oculus GO then you will need to use their Unity SDK which in return provides a function to quit the app properly.
I am guessing you cannot use OnApplicationQuit because in the Oculus Go requirement, the back button must only be used to return the user to the Oculus Go main menu.
First, you need to make sure you have the OVRmanager in your project which you get by downloading and importing the Unity SDK from the Oculus Developer website.
Then use the script below to quit the application and it will send you back to the Oculus Go Main menu when you press the back button on the controller.
if (OVRInput.GetDown(OVRInput.Button.Back)
{
OVRManager.PlatformUIConfirmQuit();
}
I am making a game that has a main home screen (that is a windows form) and i need some code that will just close the xna window but not the form.
I've looked everywhere but can't seem to find an answer. I figured out how to open the form, I just need to close the opened xna window so just my main menu is there and i can start another xna game.
There is an answer to your question here. Essentially, you will need to modify the opacity to hide the game window. The game will still be active.
Edit
my game continues to run in the backgound and so on my main menu i can't start another instance of that game
If you need to completely close the XNA game, the game will need to be launched from the Windows Form application. In your Windows Form application you can use:
Game1 myGame = new Game1();
myGame.Run();
to run the XNA game. Then when you use Game.Exit() (in the XNA application) to close the game, the main menu should still be open in the background.
I am creating a media player object in a simple console application, to play some file. Though the media player is getting launched successfully, when I am using the close() method, the process still runs and media player window does not close. what needs to be done? here is the code I wrote..
WindowsMediaPlayer player= new WindowsMediaPlayer();
player.OpenPlayer("c:\\abc.wmv");
Thread.Sleep(2000);
player.controls.stop();
player.close();
Here the process doesn't exit and file still keeps running. How can I close the application?
The automation interface doesn't have a way to force the player to exit. The less than ideal approach is to kill it:
var prc = Process.GetProcessesByName("wmplayer");
if (prc.Length > 0) prc[prc.Length - 1].Kill();
The better mouse trap is to embed the player into your own GUI, easy to do with Winforms.
I think you need to close the COM object by calling Marshal.ReleaseComObject. COM does not know that you will never be using the player again, so it cannot close the process.
Do not rely on garbage collection for this because it might never happen if there is no memory pressure. Call Marshal.ReleaseComObject manually.