使用Application.Quit时,手机游戏会重新启动 [英] Mobile game restarts when using Application.Quit
问题描述
好的,所以我将旧的4.6 Unity项目升级到Unity 5.0.总体而言,该过程相对而言比较轻松,但是现在当我为Android进行构建时,退出按钮不起作用.
Okay, so I upgrade my old 4.6 Unity project into Unity 5.0. Overall, the process was relatively painless, but now my Quit button doesn't work when I build for Android.
我通过logcat收到一条非常奇怪的消息:
And I get a very odd message via logcat:
E/Unity (23691): RenderTexture warning: Destroying active render texture. Switching to main context.
E/Unity (23691):
E/Unity (23691): (Filename: Line: 295)
E/Unity (23691):
我在GameController脚本中的退出代码非常简单:
My quit code in my GameController script is pretty simple:
public void Quit () {
Application.Quit();
}
void OnApplicationQuit () {
if (showAds) { //just in case
adController.DestroyAll();
}
}
我应该找什么?这是纹理问题吗?我确实有一个自定义着色器,但是该游戏之前在Unity 4.6上运行良好.
What should I be looking for? Is it a texture issue? I do have a custom shader, but the game worked fine with Unity 4.6 before.
推荐答案
因此,所有内容都可以追溯到Unity5以及它如何集成Admob等较早的插件.显然,Android构建不再需要ProxyActivity.因此,我从 AndroidManifest.xml 文件中完全删除了以下内容:
So, it all went back to Unity5 and how it integrates older plugins like Admob. Apparently, there is no ProxyActivity needed anymore for Android builds. So I completely removed the following out of the AndroidManifest.xml file:
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
然后将<intent-filter>
移到UnityPlayerActivity中:
And then moved the <intent-filter>
into the UnityPlayerActivity:
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
现在 Application.Quit()没问题!
完成 AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.example.admobtest" android:versionName="1.0" android:versionCode="1">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<!-- Mobile Ads Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
<!-- meta-data tag for Google Play services -->
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
<meta-data android:name="android.app.lib_name" android:value="unity" />
</activity>
<activity android:name="com.unity3d.player.VideoPlayer" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
</activity>
<!-- Google Mobile Ads Activity -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<!-- PurpleBrain AdBuddiz Activity -->
<activity android:name="com.purplebrain.adbuddiz.sdk.AdBuddizActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent">
</activity>
</application>
<uses-feature android:glEsVersion="0x00020000" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
</manifest>
这篇关于使用Application.Quit时,手机游戏会重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!