Exemplo n.º 1
0
        public void ToggleWidgetButton()
        {
            if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
            {
                return;
            }

            if (!widgetActive)
            {
                if (AndroidPermissionsManager.CheckBluetoothPermissions())
                {
                    animator.Play("ShowWidget");
                }
                else
                {
                    AndroidPermissionsManager.RequestPermission();
                    return;
                }
                DeviceManager.Instance.ForceUpdateDeviceList();
                DeviceManager.Instance.Scan();
            }
            else
            {
                animator.Play("HideWidget");
                DeviceManager.Instance.ScanStop();
            }

            widgetActive = !widgetActive;
        }
Exemplo n.º 2
0
        public void Submit(string key, PositionType position, List <PathPoint> points, int durationMillis)
        {
            if (androidJavaObject == null)
            {
                return;
            }

            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            try
            {
                float[] x         = new float[points.Count];
                float[] y         = new float[points.Count];
                int[]   intensity = new int[points.Count];
                for (var i = 0; i < points.Count; i++)
                {
                    x[i]         = points[i].X;
                    y[i]         = points[i].Y;
                    intensity[i] = points[i].Intensity;
                }

                androidJavaObject.Call("submitPath",
                                       key, position.ToString(), x, y, intensity, durationMillis);
            }
            catch (Exception e)
            {
                BhapticsLogger.LogError("submitPath() : {0}", e.Message);
            }
        }
Exemplo n.º 3
0
        private void Register(string key, Project project)
        {
            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            var req = new RegisterRequest
            {
                Key     = key,
                Project = project
            };
            var registerRequests = new List <RegisterRequest> {
                req
            };
            var request = PlayerRequest.Create();

            request.Register = registerRequests;
            if (hapticPlayer == null)
            {
                return;
            }


            hapticPlayer.Call("register", request.ToJsonObject().ToString());
        }
Exemplo n.º 4
0
        // calling from the UI Button
        public void ToggleWidgetButton()
        {
            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                AndroidPermissionsManager.RequestPermission();

                return;
            }

            if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Idle") || alwaysActive)
            {
                return;
            }

            widgetActive = !widgetActive;

            if (widgetActive)
            {
                BhapticsAndroidManager.ForceUpdateDeviceList();
                foreach (var controlButton in controllButtons)
                {
                    controlButton.Refresh();
                }


                animator.Play("ShowWidget");

                ShowWidget();
            }
            else
            {
                animator.Play("HideWidget");
                HideWidget();
            }
        }
Exemplo n.º 5
0
        public AndroidHaptic()
        {
            AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

            androidJavaObject =
                new AndroidJavaObject("com.bhaptics.bhapticsunity.BhapticsManagerWrapper", currentActivity);

            AndroidJavaObjectPtr        = androidJavaObject.GetRawObject();
            SubmitRegisteredPtr         = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "submitRegistered");
            SubmitRegisteredWithTimePtr =
                AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "submitRegisteredWithTime");
            RegisterPtr          = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "register");
            RegisterReflectedPtr = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "registerReflected");
            ScanPtr      = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "scan");
            StopScanPtr  = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "stopScan");
            PingAllPtr   = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "pingAll");
            PingPtr      = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "ping");
            UnpairPtr    = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "unpair");
            UnpairAllPtr = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "unpairAll");

            IsRegisteredPtr      = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "isRegistered");
            IsPlayingPtr         = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "isPlaying");
            IsPlayingAnythingPtr = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "isAnythingPlaying");
            IsScanningPtr        = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "isScanning");


            if (AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                deviceList = GetDevices(true);
                StartScan();
            }
        }
Exemplo n.º 6
0
        public void Scan()
        {
            var androidHapticPlayer = BhapticsManager.HapticPlayer as AndroidHapticPlayer;

            if (androidHapticPlayer == null || !AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }
            androidHapticPlayer.StartScan();
        }
Exemplo n.º 7
0
        public void Ping(string address)
        {
            var androidHapticPlayer = BhapticsManager.HapticPlayer as AndroidHapticPlayer;

            if (androidHapticPlayer == null || !AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            androidHapticPlayer.Ping(address);
        }
Exemplo n.º 8
0
        public AndroidHaptic()
        {
            AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

            hapticPlayer = new AndroidJavaObject("com.bhaptics.bhapticsunity.BhapticsManagerWrapper", currentActivity);
            TurnOnVisualization();
            if (AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                deviceList = GetDevices(true);
                StartScan();
            }
        }
Exemplo n.º 9
0
        public void StopScan()
        {
            if (androidJavaObject == null)
            {
                return;
            }

            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            CallNativeVoidMethod(StopScanPtr, EmptyParams);
        }
Exemplo n.º 10
0
        public void SubmitRegistered(string key, int startTimeMillis)
        {
            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            if (androidJavaObject == null)
            {
                return;
            }

            CallNativeVoidMethod(SubmitRegisteredWithTimePtr, new object[] { startTimeMillis });
        }
Exemplo n.º 11
0
        public static void Scan()
        {
            var androidHapticPlayer = BhapticsManager.GetHaptic() as AndroidHaptic;

            if (androidHapticPlayer == null || !AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            if (!androidHapticPlayer.IsScanning())
            {
                androidHapticPlayer.StartScan();
            }
        }
Exemplo n.º 12
0
        public void TurnOff()
        {
            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            if (androidJavaObject != null)
            {
                try
                {
                    androidJavaObject.Call("turnOffAll");
                }
                catch (Exception e)
                {
                    BhapticsLogger.LogError("turnOffAll() : {0}", e.Message);
                }
            }
        }
Exemplo n.º 13
0
        void Start()
        {
            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                BhapticsLogger.LogError("bhaptics requires bluetooth permission.");
            }


            if (WidgetSetting == null)
            {
                BhapticsLogger.LogError("[bhaptics] WidgetSetting is null");
            }

            if (!alwaysActive)
            {
                animator.Play("HideWidget", -1, 1);
            }

            BhapticsAndroidManager.AddRefresh(Refresh);
        }
Exemplo n.º 14
0
        private void SubmitRequest(SubmitRequest submitRequest)
        {
            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            var request = PlayerRequest.Create();

            request.Submit.Add(submitRequest);
            if (hapticPlayer != null)
            {
                try
                {
                    hapticPlayer.Call("submit", request.ToJsonObject().ToString());
                }
                catch (Exception e)
                {
                    BhapticsLogger.LogError("SubmitRequest() : {0}", e.Message);
                }
            }
        }
Exemplo n.º 15
0
        private void SubmitRequest(string key, string altKey,
                                   float intensity, float duration, float offsetAngleX, float offsetY)
        {
            if (androidJavaObject == null)
            {
                return;
            }

            if (!AndroidPermissionsManager.CheckBluetoothPermissions())
            {
                return;
            }

            SubmitRegisteredParams[0] = key;
            SubmitRegisteredParams[1] = altKey;
            SubmitRegisteredParams[2] = intensity;
            SubmitRegisteredParams[3] = duration;
            SubmitRegisteredParams[4] = offsetAngleX;
            SubmitRegisteredParams[5] = offsetY;

            CallNativeVoidMethod(SubmitRegisteredPtr, SubmitRegisteredParams);
        }
Exemplo n.º 16
0
        private void OnEnable()
        {
            if (alwaysActive)
            {
                if (!AndroidPermissionsManager.CheckBluetoothPermissions())
                {
                    AndroidPermissionsManager.RequestPermission();
                }

                scanCoroutine = StartCoroutine(LoopScan());
            }
            else
            {
                if (animator != null)
                {
                    animator.Play("HideWidget", -1, 1);
                }
            }

            if (BhapticsAndroidManager.Instance != null)
            {
                BhapticsAndroidManager.Instance.RefreshUIAddListener(Refresh);
            }
        }