Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sebastian.noren.androidbridgelibrary;
- import android.util.Log;
- import com.unity3d.player.UnityPlayer;
- public class TestingGround {
- private String tag = "unity";
- // run a normal method in java from unity
- public void AndroidLogcatMessage(){
- Log.d(tag, "Native Logcat Message!");
- }
- //Sending a parameter to a method from unity
- public void NumberSentFromUnity(int number){
- Log.d(tag, "Number sent from unity is: " + number + ", and that number * 2 is: "+ (2*number));
- }
- // call and return a number to unity
- public int AddFiveToNUmberFromUnity(int number){
- number +=5;
- return number;
- }
- //Calling unity function from java
- public void DoSomthingA(){
- //parameter 1: Unity gameObject, parameter 2: Name of the unityfunction, Paramete+ "other parameters"
- String input = "This is a input x";
- Log.d(tag, "Calling method in unity!");
- UnityPlayer.UnitySendMessage("GameLogic","ChangeTextToA",input);
- }
- public void DoSomthingB(){
- UnityPlayer.UnitySendMessage("GameLogic","ChangeTextToB",null);
- }
- //Thread that send data to unity after 5 seconds
- public void AndroidThreadToUnity(){
- Thread th = new Thread(new Runnable() {
- @Override
- public void run() {
- Log.d(tag, "Thread started!");
- try {
- Thread.sleep(5000);
- DoSomthingA();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- });
- th.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement