unity嵌入安卓界面,如何显示状态

1、unity导出安卓时配置

2、安卓代码中,在onResume中设置

复制代码
package com.honda.dic.settings.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import androidx.fragment.app.Fragment;

import com.unity3d.player.UnityPlayer;

public class UnityContentFragment extends Fragment {

    public static UnityPlayer mUnityPlayer;
    View view;
    public UnityContentFragment() {
        // 必须有一个无参数构造函数
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUnityPlayer = new UnityPlayer(requireActivity());
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = mUnityPlayer.getView();
        if(view.getParent()!=null)
        {
            ((ViewGroup)view.getParent()).removeAllViews();
        }
        view.getViewTreeObserver().addOnWindowFocusChangeListener((has)->mUnityPlayer.windowFocusChanged(has));
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        mUnityPlayer.resume();

        UnityPlayer.currentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        UnityPlayer.currentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        View decorView = UnityPlayer.currentActivity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
    }

    @Override
    public void onPause() {
        super.onPause();
        mUnityPlayer.pause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mUnityPlayer.quit();
    }
}
相关推荐
PyHaVolask16 小时前
CSRF跨站请求伪造
android·前端·csrf
走在路上的菜鸟17 小时前
Android学Flutter学习笔记 第五节 Android视角认知Flutter(插件plugins)
android·学习·flutter
学嵌入式的小杨同学17 小时前
顺序表(SqList)完整解析与实现(数据结构专栏版)
c++·算法·unity·游戏引擎·代理模式
2501_9159214317 小时前
如何在苹果手机上面进行抓包?iOS代理抓包,数据流抓包
android·ios·智能手机·小程序·uni-app·iphone·webview
程序猿多布18 小时前
HybridCLR热更打包后AOT泛型函数实例化缺失处理
unity·hybridclr·aot generic
_李小白18 小时前
【Android 美颜相机】第五天:GPUImageFilterTools
android·数码相机
冬奇Lab18 小时前
【Kotlin系列05】集合框架:从Java的冗长到函数式编程的优雅
android·kotlin·编程语言
冬奇Lab18 小时前
稳定性性能系列之十四——电量与网络优化:Battery Historian与弱网处理实战
android·性能优化·debug
Coffeeee18 小时前
了解一下Android16更新事项,拿捏下一波适配
android·前端·google
用户416596736935518 小时前
深入解析安卓 ELF 16KB 页对齐:原生编译与脚本修复的权衡
android