android中的黑屏统一子视图

时间:2015-06-25 04:07:49

标签: android unity3d subview

我尝试将Unity场景用作我的Android应用的子视图。我确实喜欢这个教程http://forum.unity3d.com/threads/using-unity-android-in-a-sub-view.98315/。但我遇到了问题。我的屏幕是黑色的

enter image description here

这是我的java代码 MainActivity

<div class="container">
    <h3>Welcome</h3>
    <div class="port">
        <div id="vertical-title" class="col-left">
            <img src="http://www.placehold.it/60x650" class="img-responsive" alt="" />
        </div>

        <div class="col-right">
            <div class="row">
                <div class="col-half">
                    <img src="http://www.placehold.it/550x325" class="img-responsive" alt="" />
                </div>
                <div class="col-half">
                    <img src="http://www.placehold.it/550x325" class="img-responsive" alt="" />
                </div>
            </div>

            <div class="row">
                <div class="col-half">
                    <img src="http://www.placehold.it/550x325" class="img-responsive" alt="" />
                </div>
                <div class="col-half">
                    <img src="http://www.placehold.it/550x325" class="img-responsive" alt="" />
                </div>
            </div>
        </div>
    </div>
</div>

的Manifest.xml

h3 {
    color: blue;
    margin: 5px;
}

.row {
    width: 100%;
}

.img-responsive {
    width: 100%;
}

.col-left {
    max-width: 60px;
    float: left;
}

.col-right {
    max-width: calc(100% - 60px);
    float: left;
}

.col-half {
    width: 49%;
    margin-left: 4px;
    float: left;
}

@media (max-width: 500px) {
    .col-half {
        width: 100%;
    }
}

和我的布局 activity_main.xml

package com.duy;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;

import com.unity3d.player.UnityPlayer;

public class MainActivity extends Activity {

    UnityPlayer m_UnityPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        m_UnityPlayer = new UnityPlayer(this);
        int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
        m_UnityPlayer.init(glesMode, false);

        FrameLayout layout = (FrameLayout) findViewById(R.id.unityView);
        LayoutParams lp = new LayoutParams(600, 800);
        layout.addView(m_UnityPlayer.getView(), 0, lp);

    }
    public void onWindowFocusChanged(boolean hasFocus)
    {
        super.onWindowFocusChanged(hasFocus);
        m_UnityPlayer.windowFocusChanged(hasFocus);
    }

}

你能帮我解决这个问题。非常感谢你!

2 个答案:

答案 0 :(得分:0)

Yor在代码中指定布局参数,如此

LayoutParams lp = new LayoutParams(600, 800);

如果删除此行,它可能会正常工作.. :))

答案 1 :(得分:0)

发现答案只是在清单文件中Unity项目的android库(unityLib)活动标签中添加此行

android:process=":UnityKillsMe"

并且还必须实现onWindowFocusChangedListener

onWindowFocusChanged(){m_UnityPlayer.windowFocusChanged(hasFocus);}

它将被解决 https://gamedev.stackexchange.com/questions/134347/android-black-screen-with-unity-app-in-subview