在android Studio项目中,当我切换到另一个也包含UnityPlayer的Activity时,UnityPlayer在subActivity上显示BlackScreen。
我在Arcore项目中,我使用Android Studio拥有良好的界面并且易于实现,我使用的是最新的Unity版本和Android Studio,以及每个最新的android librairy(Androidx)。 我需要在另一个活动上打开Unity视图,但似乎无法正常工作。而在Google上进行的每项研究都使我回答谁不能解决我的问题,或者在我的manifest.xml上添加一个android:process,但无法使其正常工作。
与mUnityPlayer相关的所有代码 Manifest.xml的两个活动:
<form class="form-ad" action="{{ route('jobs.store') }}" method="post" >
我的应用程序的MainActivity:
[...]
<activity
android:name=".MainActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="false"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:theme="@style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
</activity>
<activity
android:name=".ViewerPlaneActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="false"
android:label=""
android:screenOrientation="landscape"
android:theme="@style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
</activity>
[...]
子活动:
public class MainActivity extends AppCompatActivity {
[...]
public UnityPlayer mUnityPlayer;
public static UnityPlayerActivity currentActivity;
private boolean switchToAnAnotherUnityAct=false;
[...]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mUnityPlayer = new UnityPlayer(this);
setContentView(R.layout.viewer_view_simple_viewer);
replaceUnityPlayerOnFrameLayout();
mUnityPlayer.getView().requestFocus();
currentActivity = this;
[...]
}
private void replaceUnityPlayerOnFrameLayout(){
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
if( mUnityPlayer.getView().getParent()==null)
frameLayout.addView(mUnityPlayer.getView());
}
@Override
protected void onDestroy() {
if(!switchToAnAnotherUnityAct)mUnityPlayer.destroy();
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
if(!switchToAnAnotherUnityAct)mUnityPlayer.pause();
}
@Override
protected void onResume() {
super.onResume();
if(!switchToAnAnotherUnityAct){
mUnityPlayer.resume();
replaceUnityPlayerOnFrameLayout();
}
}
@Override
protected void onStart() {
super.onStart();
mUnityPlayer.start();
switchToAnAnotherUnityAct=false;
}
@Override
protected void onStop() {
super.onStop();
if(!switchToAnAnotherUnityAct)mUnityPlayer.stop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mUnityPlayer.lowMemory();
}
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if (level == TRIM_MEMORY_RUNNING_CRITICAL) {
mUnityPlayer.lowMemory();
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
public void onClickSizeSettings(View view) {
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.removeAllViews();
switchToAnAnotherUnityAct=true;
Intent intent = new Intent(this, ViewerPlaneActivity.class);
this.startActivity(intent);
}
[...]
比我期望的结果要好得多,就是看到显示了UnityPlayer,但是我只有一个黑屏。零错误。
我确切地说,我没有在UnityPlayer工作并正确显示查看器的MainActivity上返回问题。只是SecondViewer,在这里我有一个黑屏,希望能看到统一的东西来显示我的飞机和相机。
感谢您的帮助。
答案 0 :(得分:0)
最后,我没有找到解决问题的方法,因此我在主布局上使用了两个ViewStub。