【发布时间】:2020-06-11 10:50:16
【问题描述】:
我在 Android 上使用 Unity,它在视图全屏时工作,但是当我将它变成子视图时,屏幕不显示任何内容。
它可以全屏显示:
Intent intent = new Intent(this, UnityPlayerActivity.class);
intent.putExtra("arguments", "data from android");
startActivity(intent);
这些问题也没有答案:
我已经尝试过他们提供的解决方案,但似乎都没有奏效。
Display Unity Scene as Sub View in android studio
https://gamedev.stackexchange.com/questions/134347/android-black-screen-with-unity-app-in-subview
Black screen unity subview in android
我当前的 MainActivity/Unity Manifest:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_UnityPlayer = new UnityPlayer(this);
int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
m_UnityPlayer.init(glesMode, trueColor8888);
setContentView(R.layout.activity_main);
FrameLayout layout = (FrameLayout) findViewById(R.id.frameLayout2);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layout.addView(m_UnityPlayer.getView(), 0, lp);
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" android:screenOrientation="landscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="android.notch_support" android:value="true" />
</activity>
<meta-data android:name="unity.splash-mode" android:value="0" />
<meta-data android:name="unity.splash-enable" android:value="True" />
<meta-data android:name="notch.config" android:value="portrait|landscape" />
<meta-data android:name="unity.build-id" android:value="46e01524-60a4-48fa-9d28-b231f5db3c5d" />
</application>
<uses-feature android:glEsVersion="0x00030000" />
<uses-feature android:name="android.hardware.vulkan.version" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
【问题讨论】:
-
您使用的是什么 Unity 版本? Unity 在 2019.3.0 版本中重新设计了整个 Android 集成。旧的答案不适用于新的集成。
-
我使用的是 2019.3.0f6,非常新。啊,有道理,但我一直在寻找,似乎无法找到解决方案。
-
请提供完整的 MainActivity 类代码。
-
根据unity blog on unity as a library ,atm 只支持全屏。
-
这里是说明只支持全屏的链接:forum.unity.com/threads/…,这是具体的安卓版本:forum.unity.com/threads/…