Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package sebastian.noren.androidbridgelibrary;
  2.  
  3. import android.util.Log;
  4.  
  5. import com.unity3d.player.UnityPlayer;
  6.  
  7.  
  8. public class TestingGround {
  9.     private String tag = "unity";
  10.  
  11.     // run a normal method in java from unity
  12.     public void AndroidLogcatMessage(){
  13.         Log.d(tag, "Native Logcat Message!");
  14.     }
  15.  
  16.     //Sending a parameter to a method from unity
  17.     public void NumberSentFromUnity(int number){
  18.         Log.d(tag, "Number sent from unity is: " + number + ", and that number * 2 is: "+ (2*number));
  19.     }
  20.  
  21.     // call and return a number to unity
  22.     public int AddFiveToNUmberFromUnity(int number){
  23.         number +=5;
  24.         return number;
  25.     }
  26.  
  27.     //Calling unity function from java
  28.     public void DoSomthingA(){
  29.         //parameter 1: Unity gameObject, parameter 2: Name of the unityfunction, Paramete+ "other parameters"
  30.         String input = "This is a input x";
  31.         Log.d(tag, "Calling method in unity!");
  32.         UnityPlayer.UnitySendMessage("GameLogic","ChangeTextToA",input);
  33.     }
  34.  
  35.     public void DoSomthingB(){
  36.         UnityPlayer.UnitySendMessage("GameLogic","ChangeTextToB",null);
  37.     }
  38.  
  39.     //Thread that send data to unity after 5 seconds
  40.     public void AndroidThreadToUnity(){
  41.         Thread th = new Thread(new Runnable() {
  42.             @Override
  43.             public void run() {
  44.                 Log.d(tag, "Thread started!");
  45.                 try {
  46.                     Thread.sleep(5000);
  47.                     DoSomthingA();
  48.                 } catch (InterruptedException e) {
  49.                     e.printStackTrace();
  50.                 }
  51.             }
  52.         });
  53.         th.start();
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement