thieumao

Test Plugin Android for Unity

Jul 8th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class HelloAndroid : MonoBehaviour {
  6.  
  7.     public InputField inputField;
  8.     public Button sendButton;
  9.     public Text text;
  10.     private Animator animator;
  11.  
  12. #if UNITY_ANDROID
  13.     AndroidJavaClass androidClass;
  14. #endif
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18. #if UNITY_ANDROID
  19.         AndroidJNI.AttachCurrentThread();
  20.         androidClass = new AndroidJavaClass("com.example.hellounity.HelloUnity");
  21. #endif
  22.         sendButton.onClick.AddListener(()=>HandleSendButton());
  23.         animator = GetComponent<Animator>();
  24.     }
  25.  
  26.     private void HandleSendButton(){
  27.         string text = inputField.text;
  28.         //send it to device
  29. #if UNITY_ANDROID
  30.         string infor = androidClass.CallStatic<string>("getInforString", text);
  31.         this.text.text = infor+": ";
  32. #endif
  33.     }
  34.  
  35.     // Update is called once per frame
  36.     void Update () {
  37.        
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment