Example #1
0
        private void StartBluetoothClient(Action onReadyAction)
        {
#if !UNITY_EDITOR
            _clientAction = onReadyAction;

            // If Bluetooth is enabled, immediately open the device picker
            if (AndroidBluetoothMultiplayer.GetIsBluetoothEnabled())
            {
                StopAll();
                // Open device picker dialog
                if (_customDeviceBrowser != null)
                {
                    _customDeviceBrowser.Open();
                }
                else
                {
                    AndroidBluetoothMultiplayer.ShowDeviceList();
                }
            }
            else
            {
                // Otherwise, we have to enable Bluetooth first and wait for callback
                _desiredMode = BluetoothMultiplayerMode.Client;
                AndroidBluetoothMultiplayer.RequestEnableBluetooth();
            }
#else
            onReadyAction();
#endif
        }
Example #2
0
        protected virtual void OnBluetoothAdapterEnabled()
        {
            if (_bluetoothNetworkManagerSettings.LogBluetoothEvents)
            {
                Debug.Log("Bluetooth Event - AdapterEnabled");
            }

            // Resuming desired action after enabling the adapter
            switch (_desiredMode)
            {
            case BluetoothMultiplayerMode.Server:
                StopAll();
                AndroidBluetoothMultiplayer.StartServer((ushort)_networkManager.networkPort);
                break;

            case BluetoothMultiplayerMode.Client:
                StopAll();
                // Open device picker dialog
                if (_customDeviceBrowser != null)
                {
                    _customDeviceBrowser.Open();
                }
                else
                {
                    AndroidBluetoothMultiplayer.ShowDeviceList();
                }
                break;
            }

            _desiredMode = BluetoothMultiplayerMode.None;
        }