Android控件无法在Unity 5.6.x上显示的问题

来源:互联网 发布:高峰于谦 知乎 编辑:程序博客网 时间:2024/06/08 12:35
Android控件无法在Unity 5.6.x上显示的问题


开发的SDK将Android Fragment显示在Unity开发的游戏之上,在Unity5.5及以下都正常,Unity 5.6上用手点击可以响应事件,但就是显示不出来。开发人员尝试很多方法无法解决。

我在Google上找到如下资料,CUnityPlayer继承自UnityPlayer,重写addView方法,将SurfaceView的zOrderOnTop设为false,问题解决。


package com.xxx.yyy;import com.unity3d.player.*;import android.os.Bundle;public class CUnityPlayerActivity    extends UnityPlayerActivity{    @Override    public void onCreate(Bundle bundle) {        requestWindowFeature(1);        super.onCreate(bundle);        getWindow().setFormat(2);        //mUnityPlayer = new UnityPlayer(this);        mUnityPlayer = new CUnityPlayer(this);        setContentView(mUnityPlayer);        mUnityPlayer.requestFocus();    }}



package com.xxx.yyy;import com.unity3d.player.*;import android.content.ContextWrapper;import android.view.SurfaceView;import android.view.View;public class CUnityPlayer    extends UnityPlayer{    public CUnityPlayer(ContextWrapper contextwrapper) {        super(contextwrapper);    }    public void addView(View child) {        if (child instanceof SurfaceView) {            ((SurfaceView)child).setZOrderOnTop(false);        }        super.addView(child);    }}


参考:

https://github.com/gree/unity-webview/issues/163

https://github.com/gree/unity-webview/blob/8b5f7f88c5ee683d6fc74d0fb81edb3f539d80fd/plugins/Android/src/net/gree/unitywebview/CUnityPlayerActivity.java

https://github.com/gree/unity-webview/blob/8b5f7f88c5ee683d6fc74d0fb81edb3f539d80fd/plugins/Android/src/net/gree/unitywebview/CUnityPlayer.java