public void OnPairDevice()
        {
            var devices = BhapticsAndroidManager.GetDevices();
            int rssi    = -9999;
            int index   = -1;

            for (int i = 0; i < devices.Count; i++)
            {
                if (AndroidUtils.CanPair(devices[i], DeviceType))
                {
                    if (rssi < devices[i].Rssi)
                    {
                        rssi  = devices[i].Rssi;
                        index = i;
                    }
                }
            }

            if (index != -1)
            {
                if (DeviceType == PositionType.Vest)
                {
                    BhapticsAndroidManager.Pair(devices[index].Address);
                }
                else
                {
                    BhapticsAndroidManager.Pair(devices[index].Address, DeviceType.ToString());
                }
            }
        }
 private void OnUnpair()
 {
     if (device.IsPaired)
     {
         BhapticsAndroidManager.Unpair(device.Address);
     }
 }
 private void OnPairSelected()
 {
     if (AndroidUtils.ConvertConnectionStatus(device.ConnectionStatus) == 2)
     {
         BhapticsAndroidManager.Pair(device.Address);
     }
 }
 private void OnPing()
 {
     if (device.IsConnected)
     {
         BhapticsAndroidManager.Ping(device);
     }
 }
예제 #5
0
 private void OnPairSelected()
 {
     if (!(device.IsPaired))
     {
         BhapticsAndroidManager.Pair(device.Address);
     }
 }
예제 #6
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();
            }
        }
예제 #7
0
        public void ShowWidget()
        {
            uiContainer.SetActive(true);
            hideTimer = autoHideTime;

            BhapticsAndroidManager.Scan();
            scanCoroutine = StartCoroutine(LoopScan());
        }
예제 #8
0
        public void Refresh()
        {
            var devices = BhapticsAndroidManager.GetDevices();

            settingObjectPool.DisableAll();
            RefreshPairedDevices(devices);
            RefreshScannedDevices(devices);
        }
 private void OnUnpair()
 {
     if (device.IsConnected ||
         (AndroidUtils.ConvertConnectionStatus(device.ConnectionStatus) == 2 && device.IsPaired))
     {
         BhapticsAndroidManager.Unpair(device.Address);
     }
 }
        void Awake()
        {
            button = GetComponent <Button>();
            unPairButton.GetComponent <Button>().onClick.AddListener(OnUnpairDevice);
            button.onClick.AddListener(OnClickDevice);
            BhapticsAndroidManager.AddRefresh(Refresh);

            BhapticsLogger.LogDebug("start");
        }
예제 #11
0
        private void Ping()
        {
            if (device == null)
            {
                return;
            }

            BhapticsAndroidManager.Ping(device);
        }
        public void Refresh()
        {
            button = GetComponent <Button>();

            BhapticsLogger.LogDebug("Refresh()");

            var connectedDevices = BhapticsAndroidManager.GetConnectedDevices(DeviceType);

            if (connectedDevices.Count > 0)
            {
                button.image.sprite = pairImage;
                unPairButton.SetActive(true);
                var spriteState = button.spriteState;
                spriteState.highlightedSprite = pairHoverImage;
                button.spriteState            = spriteState;
                canPairImage.gameObject.SetActive(false);

                for (int i = 0; i < pairDeviceCount.childCount; i++)
                {
                    if (!pairDeviceCount.GetChild(i).gameObject.activeSelf)
                    {
                        break;
                    }

                    pairDeviceCount.GetChild(i).gameObject.SetActive(false);
                }

                for (int i = 0; i < connectedDevices.Count; i++)
                {
                    if (pairDeviceCount.GetChild(i) != null)
                    {
                        pairDeviceCount.GetChild(i).gameObject.SetActive(true);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                BhapticsLogger.LogDebug("button + ", " + defaultImage");
                button.image.sprite = defaultImage;
                unPairButton.SetActive(false);
                var spriteState = button.spriteState;
                spriteState.highlightedSprite = defaultHoverImage;
                button.spriteState            = spriteState;
                canPairImage.gameObject.SetActive(BhapticsAndroidManager.CanPairDevice(DeviceType));


                for (int i = 0; i < pairDeviceCount.childCount; i++)
                {
                    pairDeviceCount.GetChild(i).gameObject.SetActive(false);
                }
            }
        }
예제 #13
0
        private void OnDisable()
        {
            if (scanCoroutine != null)
            {
                StopCoroutine(scanCoroutine);
                scanCoroutine = null;
            }

            BhapticsAndroidManager.RemoveRefresh(Refresh);
        }
예제 #14
0
 public void HideWidget()
 {
     uiContainer.SetActive(false);
     if (scanCoroutine != null)
     {
         BhapticsAndroidManager.ScanStop();
         StopCoroutine(scanCoroutine);
         scanCoroutine = null;
     }
 }
예제 #15
0
        private void Awake()
        {
#if !UNITY_ANDROID
            return;
#endif

            if (Instance == null)
            {
                Instance = this;
            }
        }
예제 #16
0
        void Awake()
        {
            if (Instance != null)
            {
                DestroyImmediate(this);
                return;
            }

            Instance = this;
            name     = "[bHapticsAndroidManager]";
        }
        private void OnUnpairDevice()
        {
            var pairedDevices = BhapticsAndroidManager.GetPairedDevices(DeviceType);

            foreach (var pairedDevice in pairedDevices)
            {
                if (pairedDevice.IsConnected)
                {
                    BhapticsAndroidManager.Unpair(pairedDevice.Address);
                }
            }
        }
        public void OnClickDevice()
        {
            var connectedDevices = BhapticsAndroidManager.GetConnectedDevices(DeviceType);

            if (connectedDevices.Count > 0)
            {
                OnPingDevice();
            }
            else
            {
                OnPairDevice();
            }
        }
 private void OnSwap()
 {
     if (device.IsConnected)
     {
         BhapticsAndroidManager.TogglePosition(device.Address);
         if (AndroidUtils.IsLeft(device.Position))
         {
             toggleButton.image.sprite = leftSide;
         }
         else
         {
             toggleButton.image.sprite = rightSide;
         }
     }
 }
예제 #20
0
        private void OnEnable()
        {
            if (alwaysActive)
            {
                scanCoroutine = StartCoroutine(LoopScan());
            }
            else
            {
                if (animator != null)
                {
                    animator.Play("HideWidget", -1, 1);
                }
            }

            BhapticsAndroidManager.AddRefresh(Refresh);
        }
예제 #21
0
        private void ToRight()
        {
            if (device == null)
            {
                return;
            }

            if (IsLeft(device.Position))
            {
                BhapticsAndroidManager.TogglePosition(device.Address);
            }
            else
            {
                Ping();
            }
        }
예제 #22
0
        void Awake()
        {
            for (int i = 0; i < deviceListSize; i++)
            {
                var go = Instantiate(devicePrefab, devicesContainer.transform);
                go.gameObject.SetActive(false);
                controllers.Add(go);
            }

            BhapticsAndroidManager.AddRefreshAction(Refresh);

            if (helpButton != null)
            {
                helpButton.onClick.AddListener(OnHelp);
            }

            if (helpCloseButton != null)
            {
                helpCloseButton.onClick.AddListener(CloseHelpNotification);
            }

            if (bHpaticsLinkButton != null)
            {
                bHpaticsLinkButton.onClick.AddListener(OpenLink);
            }

            if (deviceListNextPageButton != null)
            {
                deviceListNextPageButton.onClick.AddListener(NextPage);
            }

            if (deviceListBackPageButton != null)
            {
                deviceListBackPageButton.onClick.AddListener(BackPage);
            }

            if (mainPanel != null)
            {
                defaultMainPanelSize = mainPanel.sizeDelta;
                mainPanelCollider    = mainPanel.GetComponent <BoxCollider>();
            }

            if (devicesContainer != null)
            {
                defaultDeviceContainerSize = defaultMainPanelSize;
            }
        }
예제 #23
0
        public void Refresh()
        {
            var devices = BhapticsAndroidManager.GetDevices();

            if (settingObjectPool != null)
            {
                settingObjectPool.DisableAll();
            }

            RefreshPairedDevices(devices);
            RefreshScannedDevices(devices);

            foreach (var controlButton in controllButtons)
            {
                controlButton.Refresh();
            }
        }
예제 #24
0
        void Start()
        {
            if (WidgetSetting == null)
            {
                BhapticsLogger.LogError("[bhaptics] WidgetSetting is null");
            }

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

            Refresh();
        }
예제 #25
0
        // calling from the UI Button
        public void ToggleWidgetButton()
        {
            if (!BhapticsAndroidManager.CheckPermission())
            {
                if (Bhaptics_Setup.instance != null && Bhaptics_Setup.instance.Config.UseOnlyBackgroundMode)
                {
                    if (BhapticsAlertManager.Instance != null)
                    {
                        BhapticsAlertManager.Instance.ShowAlert();
                    }

                    return;
                }



                BhapticsAndroidManager.RequestPermission();
                return;
            }

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

            widgetActive = !widgetActive;

            if (widgetActive)
            {
                animator.Play("ShowWidget");

                ShowWidget();
                BhapticsAndroidManager.AddRefreshAction(Refresh);
            }
            else
            {
                animator.Play("HideWidget");
                HideWidget();

                BhapticsAndroidManager.RemoveRefreshAction();
            }
        }
예제 #26
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);
        }
예제 #27
0
        private IEnumerator LoopScan()
        {
            while (true)
            {
                BhapticsAndroidManager.Scan();

                if (!alwaysActive)
                {
                    if (hideTimer < 0f)
                    {
                        scanCoroutine = null;
                        animator.Play("HideWidget");
                        HideWidget();
                        widgetActive = !widgetActive;
                        break;
                    }
                    else
                    {
                        hideTimer -= 0.5f;
                    }
                }
                yield return(new WaitForSeconds(0.5f));
            }
        }
 private void OnDisable()
 {
     CancelInvoke();
     BhapticsAndroidManager.RemoveRefresh(Refresh);
 }
 private void OnEnable()
 {
     InvokeRepeating("BlinkCanPair", 0f, 0.1f);
     BhapticsAndroidManager.AddRefresh(Refresh);
 }
 public void OnPingDevice()
 {
     BhapticsAndroidManager.Ping(DeviceType);
 }