Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by natasou · Sep 11, 2016 at 05:18 PM · androidunity 5integer

2 unity projects in one android studio

Hello everybody! Has anyone tried to import two unity projects in one android studio project? I managed to import one unity project as fragment in android studio (and it works fine!!).. when I import a second unity project both of the unity scenes are not working... I think that maybe the problem is that both projects use the same libs/structure/names (for example munityplayer)! Can anyone help me... ?thanks in advance!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image saraTAK · Nov 06, 2016 at 11:51 AM 0
Share

Hi, can you please tell me how you managed to import unity into a fragment in android.Any help is appreciated.Thanks :)

avatar image tlambeir · Jun 27, 2017 at 10:20 AM 0
Share

Did you ever solve this? I'm trying the same thing but also have the library issue.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by natasou · Nov 06, 2016 at 02:17 PM

hi Sara!

first you have to export unity and your scenes as android and check google development. Afterwards, you open any android project. 1.File ->new->import module ... and you select your unity project. 2.Open the gradle of your unity project (ex.build.gradle( Module:unity)) and you delete "apply plugin:..." and applicationId and instead you add at the top "apply plugin: 'com.android.library'" 3.You go to File->project structure and in modules you select your app.Then in dependencies, you press the + -> module dependency and you select your unity project. 4.In java UnityPlayerActivity you extend the activity as Fragment, and you add this code:

public class UnityPlayerActivity extends Fragment {

 protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
 private static final String ARG_SECTION_NUMBER = "section_number";
 public static UnityPlayerActivity newInstance(int sectionNumber) {
     UnityPlayerActivity fragment = new UnityPlayerActivity();
     Bundle args = new Bundle();
     args.putInt(ARG_SECTION_NUMBER, sectionNumber);
     fragment.setArguments(args);
     return fragment;
 }
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                          Bundle savedInstanceState)
 {
     getActivity().getWindow().takeSurface(null);
     getActivity().setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
     getActivity().getWindow().setFormat(PixelFormat.RGB_565);
     mUnityPlayer = new UnityPlayer(getActivity());
     if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) {
         getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
     }
     int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
     boolean trueColor8888 = false;
     mUnityPlayer.init(glesMode, trueColor8888);
     mUnityPlayer.windowFocusChanged(true);
     mUnityPlayer.setX((float)-5);
     View playerView = mUnityPlayer.getView();
     return playerView;
 }
 // Quit Unity
 @Override public void onDestroy ()
 {
     mUnityPlayer.quit();
     super.onDestroy();
 }
 // Pause Unity
 @Override public void onPause()
 {
     super.onPause();
     mUnityPlayer.pause();
 }
 // Resume Unity
 @Override public void onResume()
 {
     super.onResume();
     mUnityPlayer.resume();
 }
 // This ensures the layout will be correct.
 @Override public void onConfigurationChanged(Configuration newConfig)
 {
     super.onConfigurationChanged(newConfig);
     mUnityPlayer.configurationChanged(newConfig);
 }
 // Notify Unity of the focus change.
 public void onWindowFocusChanged(boolean hasFocus)
 {
     super.getActivity().onWindowFocusChanged(hasFocus);
     mUnityPlayer.windowFocusChanged(hasFocus);
 }
 // For some reason the multiple keyevent type is not supported by the ndk.
 // Force event injection by overriding dispatchKeyEvent().
 public boolean dispatchKeyEvent(KeyEvent event)
 {
     if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
         return mUnityPlayer.injectEvent(event);
     return super.getActivity().dispatchKeyEvent(event);
 }
 // Pass any events not handled by (unfocused) views straight to UnityPlayer
 public boolean onKeyUp(int keyCode, KeyEvent event)     { return mUnityPlayer.injectEvent(event); }
 public boolean onKeyDown(int keyCode, KeyEvent event)   { return mUnityPlayer.injectEvent(event); }
 public boolean onTouchEvent(MotionEvent event)          { return mUnityPlayer.injectEvent(event); }
 /*API12*/ public boolean onGenericMotionEvent(MotionEvent event)  { return mUnityPlayer.injectEvent(event); }

}*

  1. In UnityPlayerActivity you change protected void to public void! And that's it.. you can use unity as fragment in any activity. Hope it helps...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

quit game if no internet access on android 1 Answer

How to save and load a json file on android 1 Answer

Upgrade from 5.0.1 to 5.1.2f1, can't build in android now 1 Answer

pick image from android gallery 3 Answers

Failed to re-package resources. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges