赞
踩
添加返回主界面的方法
给按钮绑定点击事件
将Unity界面注册进去
- package com.hy.testdemo;
-
- import androidx.appcompat.app.AppCompatActivity;
-
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
-
- import com.unity3d.player.UnityPlayer;
-
- public class MainActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
-
- public void ButtonClick(View view)
- {
- Intent intent=new Intent(this,TestUnityActivity.class);
- startActivity(intent);
- }
- }
- package com.hy.testdemo;
-
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.KeyEvent;
-
-
- public class TestUnityActivity extends UnityPlayerActivity {
- @Override
- protected void onCreate(Bundle bundle) {
- super.onCreate(bundle);
- }
-
- public boolean onKeyDown(int i, KeyEvent keyEvent)
- {
- if(i==KeyEvent.KEYCODE_BACK)
- {
-
- Intent intent=new Intent(this,MainActivity.class);
- startActivity(intent);
- finish();
- }
- return super.onKeyDown(i,keyEvent);
- }
-
- }
- <?xml version="1.0" encoding="utf-8"?>
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
-
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="159dp"
- android:layout_marginTop="341dp"
- android:layout_marginEnd="159dp"
- android:layout_marginBottom="342dp"
- android:onClick="ButtonClick"
- android:text="测试"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
-
- </androidx.constraintlayout.widget.ConstraintLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.hy.testdemo">
-
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/Theme.Testdemo">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".TestUnityActivity"></activity>
- </application>
-
- </manifest>
- <resources>
- <string name="app_name">testdemo</string>
- <string name="game_view_content_description">Game view</string>
- </resources>
- defaultConfig {
-
- ndk {
- abiFilters 'armeabi-v7a', 'x86'
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。