Esempio n. 1
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;
        }
Esempio n. 2
0
        protected virtual void StartBluetoothHost(Action onReadyAction)
        {
#if !UNITY_EDITOR
            _hostAction = onReadyAction;

            // If Bluetooth is enabled, immediately start the Bluetooth server
            if (AndroidBluetoothMultiplayer.GetIsBluetoothEnabled())
            {
                AndroidBluetoothMultiplayer.RequestEnableDiscoverability(_bluetoothNetworkManagerSettings.DefaultBluetoothDiscoverabilityInterval);
                StopAll(); // Just to be sure
                AndroidBluetoothMultiplayer.StartServer((ushort)_networkManager.networkPort);
            }
            else
            {
                // Otherwise, we have to enable Bluetooth first and wait for callback
                _desiredMode = BluetoothMultiplayerMode.Server;
                AndroidBluetoothMultiplayer.RequestEnableDiscoverability(_bluetoothNetworkManagerSettings.DefaultBluetoothDiscoverabilityInterval);
            }
#else
            onReadyAction();
#endif
        }