public override void OnStopClient()
        {
            base.OnStopClient();

#if UNITY_ANDROID
            // Stopping all Bluetooth connectivity on Unity networking disconnect event
            AndroidBluetoothMultiplayer.Stop();
#endif
        }
示例#2
0
        protected virtual void OnBluetoothListeningStopped()
        {
            if (_bluetoothNetworkManagerSettings.LogBluetoothEvents)
            {
                Debug.Log("Bluetooth Event - ListeningStopped");
            }

            if (_bluetoothNetworkManagerSettings.StopBluetoothServerOnListeningStopped)
            {
                AndroidBluetoothMultiplayer.Stop();
            }
        }
        private void OnGUI()
        {
#if UNITY_ANDROID
            if (!showGUI)
            {
                return;
            }

            if (Application.platform == RuntimePlatform.Android)
            {
                int       xpos         = 10 + offsetX;
                int       ypos         = 50 + offsetY;
                const int spacing      = 60;
                const int spacingSmall = 24;
                const int buttonHeight = 55;

                bool noConnection = manager.client == null || manager.client.connection == null ||
                                    manager.client.connection.connectionId == -1;

                BluetoothMultiplayerMode bluetoothMultiplayerMode = AndroidBluetoothMultiplayer.GetCurrentMode();
                if (bluetoothMultiplayerMode == BluetoothMultiplayerMode.None && !manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
                {
                    if (noConnection)
                    {
                        if (GUI.Button(new Rect(xpos, ypos, 200, buttonHeight), "Bluetooth Client(C)"))
                        {
                            managerHelper.StartClient();
                        }

                        ypos += spacing;

                        if (GUI.Button(new Rect(xpos, ypos, 200, buttonHeight), "Bluetooth Host(H)"))
                        {
                            managerHelper.StartHost();
                        }
                        ypos += spacing;

                        if (GUI.Button(new Rect(xpos, ypos, 200, buttonHeight), "Bluetooth Server Only(S)"))
                        {
                            managerHelper.StartServer();
                        }
                        ypos += spacing;
                    }
                    else
                    {
                        GUI.Label(new Rect(xpos, ypos, 200, buttonHeight), "Connecting to " + manager.networkAddress + ":" + manager.networkPort + "..");
                        ypos += spacingSmall;

                        if (GUI.Button(new Rect(xpos, ypos, 200, buttonHeight), "Cancel Connection Attempt"))
                        {
                            manager.StopClient();
                        }
                    }
                }
                else
                {
                    if (NetworkServer.active)
                    {
                        string serverMsg = "Server: port=" + manager.networkPort;
                        GUI.Label(new Rect(xpos, ypos, 300, 20), serverMsg);
                        ypos += spacingSmall;
                    }
                    if (manager.IsClientConnected())
                    {
                        GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                        ypos += spacingSmall;
                    }
                }

                if (manager.IsClientConnected() && !ClientScene.ready)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, buttonHeight), "Client Ready"))
                    {
                        ClientScene.Ready(manager.client.connection);

                        if (ClientScene.localPlayers.Count == 0)
                        {
                            ClientScene.AddPlayer(0);
                        }
                    }
                    ypos += spacing;
                }

                if (NetworkServer.active || manager.IsClientConnected())
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, buttonHeight), "Stop (X)"))
                    {
                        manager.StopHost();
                    }
                    ypos += spacing;
                }
                else if (bluetoothMultiplayerMode != BluetoothMultiplayerMode.None)
                {
                    if (bluetoothMultiplayerMode == BluetoothMultiplayerMode.Client)
                    {
                        GUI.Label(new Rect(xpos, ypos, 300, 20), "Connecting to Bluetooth server...");
                        ypos += spacingSmall;
                    }
                    else if (bluetoothMultiplayerMode == BluetoothMultiplayerMode.Server)
                    {
                        GUI.Label(new Rect(xpos, ypos, 300, 20), "Starting Bluetooth server...");
                        ypos += spacingSmall;
                    }
                    if (GUI.Button(new Rect(xpos, ypos, 200, buttonHeight), "Stop (X)"))
                    {
                        AndroidBluetoothMultiplayer.Stop();
                    }
                    ypos += spacing;
                }
            }
            else
            {
                BaseOnGUI();
            }
#else
            BaseOnGUI();
#endif
        }
示例#4
0
 protected void StopAll()
 {
     AndroidBluetoothMultiplayer.Stop();
     _networkManager.StopHost();
 }