예제 #1
0
        //Should run on the Main Thread, because BluetoothAdapter.instentiate_singleton()
        private BtBridge()
        {
            ajc         = null;
            PluginReady = false;
            Debug.LogWarning("set Unity called? BtBridge()");

                        #if !UNITY_EDITOR && UNITY_ANDROID
            if (Application.platform == RuntimePlatform.Android)
            {
                try {
                    using (AndroidJavaClass ajcClazz = new AndroidJavaClass(BridgePackage)) {
                        if (!IsAndroidJavaClassNull(ajcClazz))
                        {
                            ajc         = ajcClazz.CallStatic <AndroidJavaObject> ("getInstance", unity_game_object_name);
                            PluginReady = !IsAndroidJavaObjectNull(ajc);
                        }
                    }
                } catch
                {
                    instance = null;                    //with that App will try again, when calling the Instance property
                    Debug.LogError("Bluetooth initialization failure. Probably the file *.jar not present in directory (Assets->Plugins->*.jar) ");
                    throw;
                }
            }
                        #endif
        }
예제 #2
0
        /* TEST
         * public byte[] test (byte[] x)
         * {
         *
         *      if (!PluginReady)
         *              return new byte[]{};
         *
         *      return ajc.Call<byte[]> ("TEST", x);
         * }
         */


        //THIS METHOD SHOULD BE CALLED AFTER EVERYTHING RELATED TO BLUETOOTH NEEDS TO BE ENDED
        public void OnDestroy()
        {
            if (PluginReady)
            {
                ajc.Call(ON_DESTROY);
            }

            try {
                if (ajc != null)
                {
                    ajc.Dispose();
                }
            } catch (UnityException) {
            }

            instance = null;            //This will dispose this instance. And will create a new one if needed next time.
        }