Skip to content

Instantly share code, notes, and snippets.

@EricBatlle
Last active August 18, 2020 07:31
Show Gist options
  • Save EricBatlle/ccc237f5c6db69cd0fd0c1d61cff1836 to your computer and use it in GitHub Desktop.
Save EricBatlle/ccc237f5c6db69cd0fd0c1d61cff1836 to your computer and use it in GitHub Desktop.
Template with default functionality of Java classes for making fragmented plugins on Unity
package com.eric.nativetoolkit;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import com.unity3d.player.UnityPlayer;
import androidx.annotation.Nullable;
public class NativeToolkitFragment extends Fragment
{
//Tag to follow logcats
private static final String TAG = "NativeToolkit";
// Singleton instance.
public static NativeToolkitFragment instance;
//UNITY CONTEXT
String gameObjectName;
String resultCallbackName = "OnResult";
public static void SendUnityResults(String results)
{
UnityPlayer.UnitySendMessage(instance.gameObjectName, instance.resultCallbackName, results);
Log.d(TAG, results);
}
public static void SetUp(String gameObjectName)
{
instance = new NativeToolkitFragment();
instance.gameObjectName = gameObjectName; // Store 'GameObject' reference
UnityPlayer.currentActivity.getFragmentManager().beginTransaction().add(instance, NativeToolkitFragment.TAG).commit();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
public static String getMessage()
{
return "Hello World!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment