博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【原】unity调Android(一)
阅读量:6998 次
发布时间:2019-06-27

本文共 1104 字,大约阅读时间需要 3 分钟。

public class MainActivity extends Activity {

       private UnityPlayer m_UnityPlayer;
    @Override
    public 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);
        // Add the Unity view
        FrameLayout layout = (FrameLayout) findViewById(R.id.frameLayout2);    
        LayoutParams lp = new LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        layout.addView(m_UnityPlayer.getView(), 0, lp);
    }
}

main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frameLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />
</FrameLayout>

转载地址:http://rpavl.baihongyu.com/

你可能感兴趣的文章