Created
February 20, 2020 07:18
-
-
Save rkandas/c7625e3ced6e13fd6de72206124323b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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