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();
}
Related
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.
How do i save current scene state and load it later?
I'm making a game where you are building a bridge and then press start to run over it with a car and if you fail you have a restart button that reloads the scene from origin state(without anything built on it). However, i want the player to be able to press an "Edit" button that will go back to the state right before you pressed "start" so you can keep building on your bridge without having to rebuild the whole bridge over and over again. So, how do i do this?
If you don't want to code it yourself, you can use the PlayerPrefs of Unity. If you don't know how to use it look at the documentation (https://docs.unity3d.com/ScriptReference/PlayerPrefs.html) or you can also find tuto on Youtube, even some examples.
I am making a WebRTC application and the allow permission to use camera pops up. I know there is no way to remove that but is there a way to automate the clicking of the allow button using selenium on the client's side? because the 90% of the clients are not clicking the allow button, even though we put an instruction to click the allow button and that it is safe to click it but still they are not clicking it and some clicked deny.
Currently my only solution is by letting the client download a c# application and all it does is restart the browser with --use-fake-ui-for-media-stream, but I think its not a good idea. So if there is a way to automate the clicking of allow button please tell me. Thanks guys, your help is greatly appreciated.
You can try out http://testrtc.com/
They use Selenium internally, with a focus on testing WebRTC services. They make sure the allow button gets pressed (=overridden) and replace the camera and microphone with virtual devices and media files of your choosing.
This is related to my other question.
I used the OnStructureChanged event to detect that the 'Help' window popped up in the 3rd party application that my application is writing data to. I need my application to pause while the end user resolves the data issue in the 3rd party application, then I need my application to resume once the end user closes the 'Help' window. (Either I need to detect that the 'Help' window was closed or I need to display a message box and use the DialogResult to trigger my application to resume).
I've never encountered something like this before. I don't know if it's possible to do what I want to do. If it is possible, I don't know where to start.
Advice?
UPDATES:
I have only used Threading once before and I think it was a fairly "easy peasy" usage, I pulled it off without much effort, considering I'd never used Threading before. I'm playing around with Threading for this issue right now. There's a good chance I've implemented it incorrectly, but my app isn't functioning correctly anymore...I don't know if I'm even playing with the correct tool.
I had to just keep moving with the project - deadlines, you know...
I ended up using UI Automation to detect the "Help" window, then I showed a message box giving instructions to the end user. I check the MessageBox's DialogResult and continue processing based on that. It might not be the "best" way to skin the cat, but I'm a noob and I have a deadline, so I did what I needed to do to keep moving.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Windows Phone 7 close application
How do I programmatically close a WP7 application?
You can always call an exit by doing this at your landing page use this code on click of your application back button:
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}
This will remove back entries from the stack, and you will press a back button it will close the application without any exception.
Acknowledging known solutions to provide "Exit" buttons, currently I do not see a compelling reason to implement an "exit" from a WP7 application.
The platform is fully capable of managing closure of apps. The more apps don't provide an exit, the quicker users will become accustomed to not thinking about app house keeping, and let the platform manage it.
The user will just navigate their device using start, back, etc.
If the user wants out of the current app to go do something else quickly - easy - they just hit start.
.Exit(), whilst available for xna, really isn't required anymore either. There was a cert requirement during CTP that games had to provide an exit button. This is now gone.
Non game apps never had the need to implement this.
The more this topic's discussed (and it really has been given a good run around the block), the more the indicators to me suggest there is no need to code an exit.
It should also be mentioned the app cert reqts are specific that apps should not have unhandled exceptions.
There isn't really a good way to do it. There is a nice explanation/overview of your options here.
For short, if this is a Silverlight app (not XNA), it is not supported. You can simply throw an unhandled exception, and the app will quit. I wouldn't recommend that, it seems like a hack and a rather crude way of doing it.
Here is a way to make it look nicer, but at the end of the day it still throws an exception. I don't know if the application certification process looks at whether you are throwing unhandled exceptions, but I guess it could be an issue.
Simplest thing to do is simulate back from your root/home page. I'm guessing this is exactly what apps (those which have quit button) like Fruit Ninja do.
if ( NavigationService.CanGoBack )
{
NavigationService.GoBack();
}
Btw, above snippet works for a silverlight app.
Another way to exit the application is calling the exit function of the Game class of Microsoft Xna framework.
For example:
Microsoft.Xna.Framework.Game game = new Microsoft.Xna.Framework.Game();
game.Exit();
private void exitBUtton_ONclick(object sender, RoutedEventArgs e)
{
throw new Exception("ExitAppException");
}