Last active
August 18, 2020 07:31
-
-
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
This file contains 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
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