2

I am trying to do the following on Android (then possibly on iOS) and any advices will be appreciated:

Overlaying UnityPlayer view on top of Native Android view where only the 3D objects being drawn and no camera background (transparent background)

My current progress:

So far I managed to use my Unity3D project as library into another Android project and assign UnityPlayer view to a FrameLayout on top of another Android view but the camera background color showing... I tried changing the clear flag option to depth only but it didn't work.

I also managed to use a separate GLSurfaceView which I assigned class extending UnityPlayer and implementing GLSurfaceView.Renderer to as the renderer but I am still getting opaque background.

My code as follows:

// the class extending the player
class CustomUnityPlayer extends UnityPlayer implements GLSurfaceView.Renderer {
    public CustomUnityPlayer(ContextWrapper context) {
        super(context);
    }
    public void onDrawFrame(GL10 gl) {
        super.onDrawFrame(gl);
    }
}

// inside  OnCreate function:
        m_UnityPlayer = new CustomUnityPlayer(this);
        int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
        m_UnityPlayer.init(glesMode, false);

        mUnityView = new GLSurfaceView(getApplication());
        mUnityView.setEGLContextClientVersion(2);
        mUnityView.setZOrderOnTop(true);
        mUnityView.setZOrderMediaOverlay(true);
        mUnityView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
        mUnityView.setRenderer(m_UnityPlayer);
        mUnityView.getHolder().setFormat(PixelFormat.TRANSLUCENT);

        setContentView(R.layout.activity_fullscreen);

        FrameLayout layout = (FrameLayout) findViewById(R.id.UnityView);
        LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
        layout.addView(mUnityView, 0, lp);

Am I missing something and is it even possible? Any help will be much appreciated.

Thanks alot

0

1 Answer 1

1

after some attempts...removing mUnityView.setZOrderMediaOverlay(true); did the trick for me (works on Unity 4.2 and below... not in Unity 4.3 and above)

2
  • I have a question for you Question maker/answerer. I read that it was possible to do what you say in the your question, but as of Unity 4.3 it wasn't possible to have transparent backgrounds in a scene, and if you tried to do that you would get a black background. Did this example you are providing is for Unity 4.2? Is it possible to do this on Unity 4.3+? Thank you.
    – JavaZava
    Jun 24, 2014 at 22:11
  • @JavaZava yes this works only with unity 4.2 and below... not unity 4.3 since they changed how the view is constructed (they moved from java to C++)... i will edit the answer to clarify it
    – YNK
    Jul 9, 2014 at 10:11

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.