项目场景:
由Android端显示unity3D
问题描述
要求显示页面不能显示unity3D的loading,并且要快速显示,大概时间为500ms
原因分析:
unity3D的过场动画我们unity的同学已经去掉了,但问题也出来了,会有很长一段时间黑屏现象,并且显示黑屏时间很长,这是因为只是去掉了动画效果,而没有去掉动画时长导致的
解决方案:
初始化WindowManager
private void initWindow(){
mWM = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
mParams = new WindowManager.LayoutParams();
//需要提供一个语音弹框的层级和类型
mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
mParams.format = PixelFormat.RGBA_8888;
mParams.flags =
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
mParams.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
mParams.x = 0;
mParams.y = 0;
mParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;//横屏
mParams.width = 400;
mParams.height = 600;
mRootView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.layout_vpa, null);
}
需要显示unity时就调用showVpa
private void showVpa(){
if (mPlayer == null) {
mPlayer = new WindowUnityPlayer(this);
mRootView.addView(mPlayer);
}
if (!mIsAdd) {
mPlayer.requestFocus();
mWM.addView(mRootView, mParams);
mPlayer.resume();
mIsAdd = true;
}
}
需要隐藏时调用hideVpa
private void hideVpa(){
if (mPlayer == null){
return;
}
if (mIsAdd) {
mPlayer.pause();
// mPlayer.destroy();
mWM.removeViewImmediate(mRootView);
mIsAdd = false;
}
}