Пример #1
0
    async Task OnInitialise(bool advertise = true)
    {
        if (this.bluetoothLEManager == null)
        {
            this.bluetoothLEManager = new BluetoothLEManager();
        }

        if (advertise)
        {
            await this.bluetoothLEManager.SetupBluetoothAdvertisement();
        }
        else
        {
            await this.bluetoothLEManager.SetupBluetoothWatcher();
        }

        if (this.bluetoothLEManager.isConnected)
        {
            if (advertise)
            {
                OutputBluetoothConnectionMessage("[Broadcaster] Connection has been established. Enjoy the sharing!");
            }
            else
            {
                OutputBluetoothConnectionMessage("[Watcher] Connection has been established. Enjoy the sharing!");
            }

            CurrentState = SharingServiceState.ConnectionEstablished;

            await this.bluetoothLEManager.ReadAndDispatchMessageLoopAsync(this.MessageHandler);
        }
    }
Пример #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="messageType"></param>
    /// <param name="messageBody"></param>
    void MessageHandler(TransferMessageType messageType, object messageBody)
    {
        switch (messageType)
        {
        case TransferMessageType.WorldAnchor:
            CurrentState = SharingServiceState.ReadyToImportChangedAnchor;
            ReceiveNewAnchor((byte[])messageBody);
            break;

        case TransferMessageType.Event:
            CurrentState = SharingServiceState.ReadyToImportEventHandler;
            var rawData = System.Text.Encoding.UTF8.GetString((byte[])messageBody);

            var items = rawData.Split('|');
            switch (items[0])
            {
            case "SelectStock":
                var panel      = GameObject.Find("No1Panel");
                var controller = panel.GetComponentInChildren <No1PanelController>();

                controller.SelectStock(items[1], items[2], items[3], Convert.ToBoolean(items[4]), items[5], items[6], items[7]);

                break;

            case "ShowNextPanel":
                var panel2      = GameObject.Find("No2Panel");
                var controller2 = panel2.GetComponentInChildren <No2PanelController>();

                controller2.ShowNextPanel();
                break;
            }

            break;
        }

        CurrentState = SharingServiceState.ConnectionEstablished;

        //if (messageType == TransferMessageType.String)
        //{
        //    OutputDebugInfo(messageBody.ToString());
        //}
        //else if (messageType == TransferMessageType.Buffer)
        //{
        //    ReceiveNewAnchor((byte[])messageBody);
        //}
    }