Ok so I made it on my own (as it is the trend when you ask something that is a littl emore than “How do I access other scripts?”).
So basically, I need to start an activity that is kept in a plugin.
First I create the unity project, in this case a simple GUI button.
void OnGUI()
{
if (GUI.Button(new Rect(0,0, 200, 200), "Login"))
{
// to get the activity
var androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var jo = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
// Accessing the class to call a static method on it
var jc = new AndroidJavaClass("com.example.fboomplug.StartActivity");
// Calling a Call method to which the current activity is passed
jc.CallStatic("Call", jo);
}
}
Once you got that, add a Plugin folder and Android within it, export the project as Android project, BuildSettings and click Google Android project and place it where you want it.
Then open up Eclipse (or else for that matters) and import the newly created project.
Next, create a new project which will be your plug-in and start modifying some of it like this:
public class StartActivity extends Activity {
private String TAG = "Plug.StartActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"Activity created");
}
public static void Call(Activity activity)
{
// Creating an intent with the current activity and the activity we wish to start
Intent myIntent = new Intent(activity, StartActivity.class);
activity.startActivity(myIntent);
}
}
You will get some error that UnityPlayerActivity is not found, you need to find the unity-class.jar which is in your Unity folder
C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androidplayer\development\bin
and add it to your libs folder. You also need to add the jar reference to the project.Properties->Android BuildPath->Librairies->Add Jars.
Now right click on the plugin project, Properties->Android->IsLibrary-> Apply/Ok
At this stage, you need to build the Project, RightClick-> BuildProject, the lib folder will now contain a plugin.jar, you can drag and drop it into the libs folder of the Unity project which should be open in your package explorer.
You still to indicate the manifest that a second activity is about to get launch.
Open the manifest.xml of the Unity project and add an activity line within application tags:
<activity android:name = "com.example.plugin.StartActivity"></activity>
You may have to clean the project and rebuild all projects every now and then to clear the errors (Eclipse is being a b*%&itch) and also for any modification done to the plug in you need to build the plug and drag the new jar into the unity project.
Now connect a device and press run. Unity should start and the button will show, press it and a black screen shows up. This is your new activity.
Open the logcat in Eclipse to see the printing confirming the onCreate method was called.
If you have any recommendation to this, add a comment and we can all edit that answer for future users.
You’re welcome.