Skip to content

Instantly share code, notes, and snippets.

@rkandas
Created February 20, 2020 07:18
Show Gist options
  • Save rkandas/c7625e3ced6e13fd6de72206124323b2 to your computer and use it in GitHub Desktop.
Save rkandas/c7625e3ced6e13fd6de72206124323b2 to your computer and use it in GitHub Desktop.
public class UnityFragment extends Fragment {
protected UnityPlayer mUnityPlayer;
FrameLayout frameLayoutForUnity;
public UnityFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mUnityPlayer = new UnityPlayer(getActivity());
View view = inflater.inflate(R.layout.fragment_unity, container, false);
this.frameLayoutForUnity = (FrameLayout) view.findViewById(R.id.frameLayoutForUnity);
this.frameLayoutForUnity.addView(mUnityPlayer.getView(),
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
mUnityPlayer.requestFocus();
mUnityPlayer.windowFocusChanged(true);
return view;
}
@Override
public void onDestroy() {
mUnityPlayer.quit();
super.onDestroy();
}
@Override
public void onPause() {
super.onPause();
mUnityPlayer.pause();
}
@Override
public void onResume() {
super.onResume();
mUnityPlayer.resume();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment