I am writing a component for Unity3D. I am asking this question here because I think it is more of an Android question than a Unity3D question.
Unity3D allows developers to write what are called Plugins. Unity has its own Activity that the app runs in. A plugin can interact with that activity. The Unity activity has a ViewGroup and View in it with a canvas. I want to add a new View into the ViewGroup of Unity. I want this new view to be centered on the screen and not cover up any of the existing canvas except for where it lives in the middle of the screen. I figure it will take about the full width and about 1/4 of the center of the screen. The question is how to do this. Currently I am using a Fragment because the view I am trying to insert must be used as a Fragment. This Fragment shows up and works just fine. I can see the UI. The problem is it completely covers the Unity activity window. There are a couple things to note about the code below. Thanks to other developers for the code to find the Unity View. I have to set the Id of the leaf view because it is -1 if I don't. Maybe that is part of the problem. Maybe I am getting the wrong view? My Fragment does show up, so.... I think I will need to use some kind of Layout and set the settings on it. If that is the way, please point me to the way to do that. Again, I want my Fragment view to float on top of the Unity view and be centered on the screen taking of the full width, but not height. Here is the code I have so far that shows the fragment, but covers the whole screen: private View getLeafView(View view) { if (view instanceof ViewGroup) { ViewGroup vg = (ViewGroup)view; for (int i = 0; i < vg.getChildCount(); ++i) { View chview = vg.getChildAt(i); View result = getLeafView(chview); if (result != null) return result; } return null; } else { return view; } } public void Init(String videoId, String objectName, int heightOffset) { UnityPlayer.currentActivity.runOnUiThread(new Runnable() { public void run() { ViewGroup rootView = (ViewGroup)UnityPlayer.currentActivity.findViewById(android.R.id.content); // find the first leaf view (i.e. a view without children) // the leaf view represents the topmost view in the view stack View topMostView = getLeafView(rootView); if (topMostView != null) { // let's add a sibling to the leaf view ViewGroup leafParent = (ViewGroup)topMostView.getParent(); if (leafParent != null) { leafParent.setId(0x20348); MyFragment fragment = new MyFragment(); FragmentManager fragmentManager = UnityPlayer.currentActivity.getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(leafParent.getId(), fragment); fragmentTransaction.commit(); } } } }); } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.