Exemplo n.º 1
0
 public void Create()
 {
     if (_initResult)
     {
         // If there is no current Bluetooth connectivity
         if (BluetoothMultiplayerAndroid.CurrentMode() == BluetoothMultiplayerMode.None)
         {
             // If Bluetooth is enabled, then we can do something right on
             if (BluetoothMultiplayerAndroid.IsBluetoothEnabled())
             {
                 Network.Disconnect();                                                              // Just to be sure
                 BluetoothMultiplayerAndroid.InitializeServer(BluetoothManager.Port);
                 BluetoothManager.Instance._desiredMode = BluetoothMultiplayerMode.Server;
             }
             // Otherwise we have to enable Bluetooth first and wait for callback
             else
             {
                 BluetoothManager.Instance._desiredMode = BluetoothMultiplayerMode.Server;
                 BluetoothMultiplayerAndroid.RequestDiscoverable(60);
             }
         }
         UniversalOnline.Instance.Progress = 10;
         UniversalOnline.Instance.State    = UniversalOnline.States.BTCreate;
     }
     else
     {
         UniversalOnline.Instance.Progress = 10;
         UniversalOnline.Instance.State    = UniversalOnline.States.FailedConnect;
     }
 }
Exemplo n.º 2
0
    void onBluetoothAdapterEnabled()
    {
        switch (desiredMode)
        {
        case BluetoothMultiplayerMode.Server:
            Network.Disconnect();
            BluetoothMultiplayerAndroid.InitializeServer((ushort)Common.Port);
            break;

        case BluetoothMultiplayerMode.Client:
            Network.Disconnect();
            BluetoothMultiplayerAndroid.ShowDeviceList();
            break;
        }
        desiredMode = BluetoothMultiplayerMode.None;
    }
Exemplo n.º 3
0
    private void onBluetoothAdapterEnabled()
    {
        // Resuming desired action after enabling the adapter
        switch (_desiredMode)
        {
        case BluetoothMultiplayerMode.Server:
            Network.Disconnect();
            BluetoothMultiplayerAndroid.InitializeServer(Port);
            break;

        case BluetoothMultiplayerMode.Client:
            Network.Disconnect();
            BluetoothMultiplayerAndroid.ShowDeviceList();
            break;
        }
    }
Exemplo n.º 4
0
 //创建服务器
 public void CreateServer()
 {
     if (initResult)
     {
         if (BluetoothMultiplayerAndroid.CurrentMode() == BluetoothMultiplayerMode.None)
         {
             if (BluetoothMultiplayerAndroid.IsBluetoothEnabled())
             {
                 Network.Disconnect();
                 BluetoothMultiplayerAndroid.InitializeServer((ushort)Common.Port);
             }
             else
             {
                 desiredMode = BluetoothMultiplayerMode.Server;
                 BluetoothMultiplayerAndroid.RequestBluetoothEnable();
             }
         }
     }
 }
    void OnGUI()
    {
        // If initialization was successfull, showing the buttons
        if (_initResult)
        {
            // If there is no current Bluetooth connectivity
            if (BluetoothMultiplayerAndroid.CurrentMode() == BluetoothMultiplayerMode.None)
            {
                if (GUI.Button(new Rect(10, 10, 150, 50), "Create server"))
                {
                    // If Bluetooth is enabled, then we can do something right on
                    if (BluetoothMultiplayerAndroid.IsBluetoothEnabled())
                    {
                        Network.Disconnect(); // Just to be sure
                        BluetoothMultiplayerAndroid.InitializeServer(Port);
                    }
                    // Otherwise we have to enable Bluetooth first and wait for callback
                    else
                    {
                        _desiredMode = BluetoothMultiplayerMode.Server;
                        BluetoothMultiplayerAndroid.RequestBluetoothEnable();
                    }
                }

                if (GUI.Button(new Rect(170, 10, 150, 50), "Connect to server"))
                {
                    // If Bluetooth is enabled, then we can do something right on
                    if (BluetoothMultiplayerAndroid.IsBluetoothEnabled())
                    {
                        Network.Disconnect();                         // Just to be sure
                        BluetoothMultiplayerAndroid.ShowDeviceList(); // Open device picker dialog
                    }
                    // Otherwise we have to enable Bluetooth first and wait for callback
                    else
                    {
                        _desiredMode = BluetoothMultiplayerMode.Client;
                        BluetoothMultiplayerAndroid.RequestBluetoothEnable();
                    }
                }
            }
            else
            {
                // Stop all networking
                if (GUI.Button(new Rect(10, 10, 150, 50), "Disconnect"))
                {
                    if (Network.peerType != NetworkPeerType.Disconnected)
                    {
                        Network.Disconnect();
                    }
                }
            }
            // Showing message if initialization failed for some reason
        }
        else
        {
            GUI.Label(new Rect(10, 10, Screen.width, 100), "Bluetooth not available. Are you running this on Bluetooth-capable Android device and AndroidManifest.xml is set up correctly?");
        }

        if (GUI.Button(new Rect(Screen.width - 100f - 15f, Screen.height - 40f - 15f, 100f, 40f), "Back"))
        {
            // Gracefully closing all Bluetooth connectivity and loading the menu
            try {
                BluetoothMultiplayerAndroid.StopDiscovery();
                BluetoothMultiplayerAndroid.Disconnect();
            } catch {
                //
            }
            Application.LoadLevel("BluetoothMultiplayerAndroidDemoMenu");
        }
    }
Exemplo n.º 6
0
    void OnClick()
    {
        switch (Type)
        {
        case EMenuButton.MODE_PLAY:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            MenuManager.Instance.openModePlay();
            break;

        case EMenuButton.ABOUT:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            MenuManager.Instance.openAbout();
            break;

        case EMenuButton.SETTING:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            MenuManager.Instance.openSetting();
            break;

        case EMenuButton.MORE_GAME:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            Application.OpenURL(GameConfig.LinkMoreGame);
            break;

        case EMenuButton.RATE:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            Application.OpenURL(GameConfig.LinkRate);
            break;

        case EMenuButton.BACK_FROM_SETTING:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            MenuManager.Instance.openMenu();
            break;

        case EMenuButton.BACK_FROM_ABOUT:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            MenuManager.Instance.panelAbout.SetActive(false);
            MenuManager.Instance.openMenu();
            break;

        case EMenuButton.PLAYER_1:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            SceneState.Instance.State = ESceneState.ADVENTURE;
            MenuManager.Instance.toLevelScene();
            break;

        case EMenuButton.PLAYER_2:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            SceneState.Instance.State = ESceneState.BLUETOOTH;
            MenuManager.Instance.toBluetooth();
            break;

        case EMenuButton.BACK_FROM_MODE:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            MenuManager.Instance.backFromMode();
            break;

        case EMenuButton.CREATE_SERVER:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            if (BluetoothManager.Instance.initResult)
            {
                if (BluetoothMultiplayerAndroid.CurrentMode() == BluetoothMultiplayerMode.None)
                {
                    if (BluetoothMultiplayerAndroid.IsBluetoothEnabled())
                    {
                        BluetoothManager.Instance.disconnectNetWork();
                        if (BluetoothMultiplayerAndroid.InitializeServer(GameConfig.Port))
                        {
                            BluetoothManager.Instance.desiredMode = BluetoothMultiplayerMode.Server;
                            DeviceService.Instance.openToast("You have create server!");
                            MenuManager.Instance.toLevelScene();
                        }
                    }
                    else
                    {
                        BluetoothManager.Instance.desiredMode = BluetoothMultiplayerMode.Server;
                        BluetoothMultiplayerAndroid.RequestBluetoothEnable();
                    }
                }
                else if (BluetoothMultiplayerAndroid.CurrentMode() == BluetoothMultiplayerMode.Server)
                {
                    MenuManager.Instance.toLevelScene();
                }
                else
                {
                    DeviceService.Instance.openToast("You are client!");
                }
            }
            else
            {
                DeviceService.Instance.openToast("Device can't support bluetooth!");
            }
            break;

        case EMenuButton.CONNECT_SERVER:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            if (BluetoothManager.Instance.initResult)
            {
                if (BluetoothMultiplayerAndroid.CurrentMode() == BluetoothMultiplayerMode.None)
                {
                    if (BluetoothMultiplayerAndroid.IsBluetoothEnabled())
                    {
                        BluetoothManager.Instance.disconnectNetWork();
                        if (BluetoothMultiplayerAndroid.ShowDeviceList())
                        {
                            DeviceService.Instance.openToast("You have connect to server!");
                            BluetoothManager.Instance.desiredMode = BluetoothMultiplayerMode.Client;
                            MenuManager.Instance.toLevelScene();
                        }
                    }
                    else
                    {
                        BluetoothManager.Instance.desiredMode = BluetoothMultiplayerMode.Client;
                        BluetoothMultiplayerAndroid.RequestBluetoothEnable();
                    }
                }
                else if (BluetoothMultiplayerAndroid.CurrentMode() == BluetoothMultiplayerMode.Server)
                {
                    DeviceService.Instance.openToast("You are server!");
                }
                else
                {
                    MenuManager.Instance.toLevelScene();
                }
            }
            else
            {
                DeviceService.Instance.openToast("Device can't support bluetooth");
            }
            break;

        case EMenuButton.BACK_FROM_SERVER:
            audio.volume = (float)PlayerInfo.Instance.userInfo.volumeSound / 100;
            audio.PlayScheduled(0.5f);

            MenuManager.Instance.backFromServer();

            Network.Disconnect();
            BluetoothManager.Instance.desiredMode = BluetoothMultiplayerMode.None;
            break;

        default:
            break;
        }
    }