I have a waiting room in unity with photon and when there are enough players a countodown starts, only problem is if the master client is using IOS and they check notification or are not in the app then the game will never starts when it hits 0 until they come back in the game. Is there a way to run the code and force it to start while in the background?
If this is not possible can I use OnApplicationPause() to run code if the OnApplicationPause is more than a certain time(say 5 seconds). So basically if the user leaves for 5 seconds then I would kick them out of the scene and send them to another scene.
Thanks.
I don't know about IOS Unity but in android, you can use a Service to run script in the background
Start android service from Unity3D code
I think this is another way to solve your problem:
When OnApplicationPause() is called, you can send a signal to your
server to run a timer.
When this timer reaching elapse time, your server will kick the pause
guy out of room.
It would better if you run a timer in server instead of client (user's device not work well, there is some case that you can't handle, etc)
Related
I'm building an app in Unity3D for iOS. I have huge problems with lag, but for some reason the lag disappears for like 5 seconds after I suspend the app by pulling down the iOS top menu or pressing the home button and then get back to the app again.
What happens when I suspend the app? How does Unity freeze the app? What functions are called? What happens memory-wise etc?
When user press home button or leave Application/Game in any way. It will pause whatever is happening in your game. All of the Update() FixedUpdate() and LateUpdate() methods would pause as well. It will call OnApplicationFocus and OnApplicationPause methods at two times (leaving app and coming back to app). You can implement these methods to do Application state specific behaviour. Having said that, lag in game is related to your scripting logic. I would suggest you to Optimise your app for IOS devices. Here are some useful links for you:
iOS Specific Optimizations
Practical Guide to Optimization for Mobiles
Optimizing graphics performance
IPhone Optimization Tips
I'm working on a Win Phone 8.1 App that uses the background audio player, but I'm having trouble, particularly when it comes to the cancellation event. I want to debug it myself to learn but I can't seem to find a way to manually cancel the background task other than to pause and wait 5 minutes while the app is suspended, something impossible while debugging.
Is there a way to do so cleanly (ie. Not artificially increasing memory usage)?
There come two ways to my mind, both quite easy to do:
invoke BackgroundMediaPlayer.Shutdown from your code
while debugging, hit Start, find Music app, open, start playing an audio file - hence there can be only one Instance of MediaPlayer, yours will be cancelled.
my question is the following: currently i have several coroutines running in my game for android/iOS but when i send the game to background in order to try other things with the phone those coroutines stop and only resume after i get back to the game; is there any way to make the coroutines continue running while the game is in background?
Android will suspend your application by design. Co-routines run in the same thread as your Updates so making a distinction between the two in terms of running in the foreground is not too likely. Having said that there are ways around this. You could build a plugin that talks to the android platform or use OnApplicationPause and calculate the time passed in the application and do whatever it is you were wanting to do in the time frame between. The first requiring you do something along the lines of building a plugin
and the second using the following
public void OnApplicationPause(bool paused) {
if(paused) {
// Game is paused, remember the time
} else {
// Game is unpaused, calculate the time passed since the game was paused and use this time to calculate build times of your buildings or how much money the player has gained in the meantime.
}
}
for more info see
this or this.
Also note that building a plugin requires a Pro Licence
Additional Co-Routine resources
Co-Routine Execution Order
Co-Routine Scheduler
Deep Explaination of Co-Routines
You can't make something permanently run in the background. The OS will event eventually pause it. Only VOIP, Media Player or GPS are allowed. Everything else only get an extended time frame until pause.
For iOS you can change "Application does not run in background" in info.plist
Use Application.runInBackground = true;
See Unity Docs Application.runInBackground
around a week ago, I submitted an online Background Radio Streaming app for the Windows Phone store. The app was quite good (as I used the Emulator to test it, it was good on all the possible sectors) but when I submitted it for certification, it failed.
According the the error log, if someone is already playing a Music from Music + Video hub and then tries to open this app, both of the apps Crash and stop unexpectedly.
So far I understood, it is because the Music of Music + Video hub is also Background Music and for playing 2 Background Musics at the same time, the apps are Crashing. It can be some other reason but the described one seemed more logical to me.
So, is there anyone who can tell me how to change the state of the app of Music + Video hub? I want to pause or stop the app of Music + Video hub for the time being so that both of the states of the app are not same. In that way, the apps won't clash with each other in the background.
Can anyone help me in this regard?
Use gameHasControl to check for other BAP using music:
bool gameHasControl = Microsoft.Xna.Framework.Media.MediaPlayer.GameHasControl;
if (!gameHasControl)
{
MessageBox.Show("stopping other player"); // normally you should ask if to do that
BackgroundAudioPlayer.Instance.Stop();
}
Once it is Stopped, when you start your BAP, then old instance invokes Shutdown(), and your BAP will be new Instance, which you can normally use. The same is when your BAP is in memory and you start to play from Music+Video Hub.
Only watch out, because when you use XNA, you sometimes need to do:
FrameworkDispatcher.Update();
Otherwise your App will sometimes crash. Good luck.
EDIT - after comment
To make it work you need to add a reference to Microsoft.Phone.BackgroundAudio or use like this:
Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer.Instance.Stop();
BackgroundAudioPlayer is a Singleton which you are allowed to use - in this case - Stop it playing (of course give the choice to the User).
I need to port an Android app which has a widget to WP8.
In Android the widget shows a countdown which is updated in the background automatically - even when the user has quit the app.The countdown starts at a certain pre-programmed time and just counts down - all donw without the user having to start the app in Android.
Is there some kind of similar functionality on WP8 with the tiles?
The app does not interact with internet and does not receive any external messages like email that can cuase the countdown to work. It needs to all happen automatically.
This is not possible in WP8 (or WP7).
At best you can update your app's tile on the homescreen once every half hour (best-case!). It sounds like you want to update more frequently than that.