Utiliser Unity comme sous-vue me donne un écran noir

9

J'utilise Unity avec Android et cela fonctionne lorsque la vue est en plein écran, mais lorsque je la transforme en sous-vue, l'écran n'affiche rien.

entrez la description de l'image ici

Cela fonctionne en plein écran:

entrez la description de l'image ici

Intent intent = new Intent(this, UnityPlayerActivity.class);
intent.putExtra("arguments", "data from android");
startActivity(intent);

Ces questions sont également sans réponse:

J'ai essayé les solutions dont ils disposent, mais aucune ne semble avoir fonctionné.

Afficher la scène Unity en tant que sous-vue dans le studio Android

/gamedev/134347/android-black-screen-with-unity-app-in-subview

Sous-vue de l'unité de l'écran noir dans Android

Mon manifeste MainActivity / Unity actuel:

@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>
DIRTY DAVE
la source
Quelle version d'Unity utilisez-vous? Unity a retravaillé l'intégralité de l'intégration Android dans la version 2019.3.0. Les anciennes réponses ne fonctionneront pas avec la nouvelle intégration.
aalmigthy
J'utilise 2019.3.0f6 donc assez nouveau. Ah ça a du sens, mais j'ai cherché et je n'arrive pas à trouver une solution à cela.
DIRTY DAVE
Veuillez fournir votre code complet de classe MainActivity.
0xBFE1A8
1
Selon le blog de l'unité sur l'unité en tant que bibliothèque, seul le plein écran est pris en charge par atm.
LumbusterTick
1
Voici le lien vers les explications indiquant que seul le plein écran est pris en charge: forum.unity.com/threads/… et voici l'androïde spécifique: forum.unity.com/threads/…
HoloLady

Réponses:

0

vous pouvez y parvenir en utilisant uniquement la disposition du cadre, MainActivitydevrait être étendu comme Activitynon UnityPlayerActivity. Ajoutez ces deux lignes à l'activité dans le AndroidManifest.xml.

<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />

Le code de travail est:

main.xml

    <?xml version="1.0" encoding="utf-8"?>  
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        android:layout_width="match_parent" android:layout_height="match_parent"  
        android:rowCount="3"  
        android:columnCount="10">  

        <FrameLayout  
            android:layout_width="match_parent"  
            android:layout_height="250dip"  
            android:id="@+id/fl_forUnity"  
            android:background="#ff00ff15"  
            android:layout_column="4"  
            android:layout_row="0"  
            android:layout_alignParentTop="true"  
            android:layout_centerHorizontal="true">  

        </FrameLayout>  

        <Button  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Rotate Right"  
            android:id="@+id/bt_rotRight"  
            android:layout_column="4"  
            android:layout_row="2"  
            android:layout_alignTop="@+id/bt_stop"  
            android:layout_toRightOf="@+id/bt_stop"  
            android:layout_toEndOf="@+id/bt_stop"  
            android:layout_marginLeft="30dp" />  

        <Button  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Rotate Left"  
            android:id="@+id/bt_rotLeft"  
            android:layout_column="9"  
            android:layout_row="2"  
            android:layout_alignTop="@+id/bt_stop"  
            android:layout_toLeftOf="@+id/bt_stop"  
            android:layout_toStartOf="@+id/bt_stop"  
            android:layout_marginRight="30dp" />  

        <Button  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Stop"  
            android:id="@+id/bt_stop"  
            android:layout_below="@+id/fl_forUnity"  
            android:layout_centerHorizontal="true"  
            android:layout_margin="10dip" />  

    </RelativeLayout>  

UnityPlayerActivity.java

    import android.widget.FrameLayout;  
    import android.widget.Button;  

    public class UnityPlayerActivity extends Activity  
    {  
        protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code  

        //Declare a FrameLayout object  
        FrameLayout fl_forUnity;  

        //Declare the buttons  
        Button bt_rotLeft;  
        Button bt_rotRight;  
        Button bt_stop;  

        // Setup activity layout  
        @Override protected void onCreate (Bundle savedInstanceState)  
        {  
            requestWindowFeature(Window.FEATURE_NO_TITLE);  
            super.onCreate(savedInstanceState);  

            getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy  

            mUnityPlayer = new UnityPlayer(this);  
            if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))  
            {  
                setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);  
                getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,  
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);  
            }  

            //setContentView(mUnityPlayer);  
            //Set the content to main  
            setContentView(R.layout.main);  

            //Inflate the frame layout from XML  
            this.fl_forUnity = (FrameLayout)findViewById(R.id.fl_forUnity);  

            //Add the mUnityPlayer view to the FrameLayout, and set it to fill all the area available  
            this.fl_forUnity.addView(mUnityPlayer.getView(),  
                    FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);  

            //Initialize the buttons from the XML file  
            this.bt_rotLeft = (Button) findViewById(R.id.bt_rotLeft);  
            this.bt_rotRight = (Button) findViewById(R.id.bt_rotRight);  
            this.bt_stop = (Button) findViewById(R.id.bt_stop);  

            /*Send a brodcast a message to the 'Main Camera' game object, passing L, R according to the 
            pressed buttons.*/  
            this.bt_rotLeft.setOnClickListener(new View.OnClickListener() {  
                @Override  
                public void onClick(View v) {  
                    UnityPlayer.UnitySendMessage("Main Camera", "ReceiveRotDir", "L");  
                }  
            });  

            this.bt_rotRight.setOnClickListener(new View.OnClickListener() {  
                @Override  
                public void onClick(View v) {  
                    UnityPlayer.UnitySendMessage("Main Camera", "ReceiveRotDir", "R");  
                }  
            });  

            this.bt_stop.setOnClickListener(new View.OnClickListener() {  
                @Override  
                public void onClick(View v) {  
                    UnityPlayer.UnitySendMessage("Main Camera", "ReceiveRotDir", " ");  
                }  
            });  

            mUnityPlayer.requestFocus();  
        }  

J'espère que les URL de référence ci-dessous pourraient vous aider. L' unité et Android CustomLayout et l' unité et sous-vue Android

Pankti Shah
la source