コード例 #1
0
ファイル: BluetoothMgr.cs プロジェクト: gbtapps/InBrain
    public void BLEConnect()
    {
        if (m_on && Hot2gApplication.Instance.mode >= Hot2gApplication.eMode.Connecting)
        {
            Hot2gApplication.Instance.DisConnect();
            m_on = false;
        }
        else
        {
            // 接続されていないなら接続する
            if (Hot2gApplication.Instance.mode <= Hot2gApplication.eMode.None)
            {
                Hot2gApplication.Instance.Scan(() => { }, () => { });
                //            Hot2gApplication.Instance.Connecting(IconUpdate, IconUpdate);
            }
            m_on    = true;
            m_timer = 0;
        }

#if false    //  ダイアログの動作テスト
        List <string> DeviceList = new List <string>();
        //        string LastConncetAddress = "None";
        string LastConncetAddress = "Dummy5";
        DeviceList.Add("Dummy");
        DeviceList.Add("Dummy2");
        DeviceList.Add("Dummy3");
        DeviceList.Add("Dummy4");
        DeviceList.Add("Dummy5");
        DeviceList.Add("Dummy6");
        DeviceList.Add("Dummy7");
        DeviceList.Add("Dummy8");
        DeviceList.Add("Dummy9");
        BtDialog.OpenDialog(LastConncetAddress, DeviceList);
#endif
    }
コード例 #2
0
ファイル: BtDialog.cs プロジェクト: gbtapps/InBrain
    static public void OpenDialog(string last, List <string> list)
    {
        if (m_instance != null)
        {
            return;
        }

        m_instance = Instantiate(instance, instance.transform.parent, false);

        list = list.Distinct().ToList <string>();
        m_instance.transform.Find("ConnectBG").gameObject.SetActive(true);
        var baseTransform = m_instance.transform.Find("ConnectBG").Find("ConnectDialog");

        baseTransform.Find("Text").GetComponent <Text>().text = "Last connect:\n" + last;
        var content = baseTransform.Find("Scroll View").Find("Viewport").Find("Content");
        var toggle  = content.Find("Toggle").GetComponent <Toggle>();

        content.GetComponent <ToggleGroup>().allowSwitchOff = true;
        bool isOn  = false;
        bool first = true;

        foreach (var dev in list)
        {
            Toggle newToggle = toggle;
            if (first)
            {
                //  一個目はある奴を使う
                first = false;
            }
            else
            {
                newToggle = Instantiate(toggle, content, false);
                m_instance.m_toggleList.Add(newToggle);
            }
            newToggle.transform.Find("Label").GetComponent <Text>().text = dev;

            //  最後につないでたのをOnに
            if (dev == last)
            {
                newToggle.isOn = true;
                isOn           = true;
            }
            else
            {
                newToggle.isOn = false;
            }
        }
        if (!isOn)
        {
            toggle.isOn = true;
        }

        content.GetComponent <ToggleGroup>().allowSwitchOff = false;

        var button = baseTransform.Find("Ok").GetComponent <Button>();

        button.onClick.AddListener(() =>
        {
            string dev = null;
            foreach (var t in content.GetComponent <ToggleGroup>().ActiveToggles())
            {
                if (t.isOn)
                {
                    dev = t.transform.Find("Label").GetComponent <Text>().text;
                }
            }
            if (dev != null)
            {
                Hot2gApplication.Instance.Connecting(dev, () => { }, () => { }, () => { });
                PlayerPrefs.SetString(BluetoothMgr.cLastConnectSaveKey, dev);
            }
            Destroy(m_instance.gameObject);
            m_instance = null;
        });

        var buttonClose = baseTransform.Find("Close").GetComponent <Button>();

        buttonClose.onClick.AddListener(() =>
        {
            Hot2gApplication.Instance.DisConnect();
            Destroy(m_instance.gameObject);
        });
    }
コード例 #3
0
ファイル: BluetoothMgr.cs プロジェクト: gbtapps/InBrain
    private void Update()
    {
        switch (Hot2gApplication.Instance.mode)
        {
        case Hot2gApplication.eMode.None:
        case Hot2gApplication.eMode.ConnectError:
        case Hot2gApplication.eMode.ScanError:
            if (m_BlueToothButton != null)
            {
                m_BlueToothButton.GetComponent <Image>().sprite = m_BlueToothButtonSprite[0];
                m_BlueToothButton.interactable = true;
            }
            if (m_on)
            {
                m_timer += Time.deltaTime;
                if (m_timer > 7.0f)
                {
                    Hot2gApplication.Instance.Scan(() => { }, () => { });
                    m_timer = 0;
                }
            }
            break;


        case Hot2gApplication.eMode.ScanOK:
            string LastConncetAddress = "None";

            m_timer = 0;

            if (PlayerPrefs.HasKey(cLastConnectSaveKey))
            {
                LastConncetAddress = PlayerPrefs.GetString(cLastConnectSaveKey);
            }

            List <string> DeviceList = Hot2gApplication.Instance.GetScanDeviceList();

#if false
            LastConncetAddress = "None";
            DeviceList.Add("Dummy");
            DeviceList.Add("Dummy2");
            DeviceList.Add("Dummy3");
            DeviceList.Add("Dummy4");
            DeviceList.Add("Dummy5");
            DeviceList.Add("Dummy6");
            DeviceList.Add("Dummy7");
            DeviceList.Add("Dummy8");
            DeviceList.Add("Dummy9");
#endif
            bool flg = false;
            for (int i = 0; i < DeviceList.Count; i++)
            {
                if (DeviceList[i] == LastConncetAddress)
                {
                    Hot2gApplication.Instance.Connecting(LastConncetAddress, () => { }, () => { }, () => { });
                    flg = true;
                }
            }

            if (!flg)
            {
                BtDialog.OpenDialog(LastConncetAddress, DeviceList);
            }

            /*
             * if (DeviceList.Count == 1)
             * {
             *  // 見つかったひとつは前回のデバイスと同じ
             *  if (DeviceList[0] == LastConncetAddress)
             *  {
             *      Hot2gApplication.Instance.Connecting(LastConncetAddress, () => { }, () => { }, () => { });
             *  }
             *  // 見つかったひとつは前回と違う
             *  else
             *  {
             *      BtDialog.OpenDialog(LastConncetAddress, DeviceList);
             *  }
             * }
             * // 複数のデバイスが見つかったぞ
             * else
             * {
             *  BtDialog.OpenDialog(LastConncetAddress, DeviceList);
             * }
             */
            break;

        case Hot2gApplication.eMode.Scan:
        case Hot2gApplication.eMode.Connecting:
        case Hot2gApplication.eMode.InitSetting:
            if (m_BlueToothButton != null)
            {
                m_BlueToothButton.GetComponent <Image>().sprite = m_BlueToothButtonSprite[1];
                m_BlueToothButton.interactable = false;
            }
            break;

        default:
            if (m_BlueToothButton != null)
            {
                m_BlueToothButton.GetComponent <Image>().sprite = m_BlueToothButtonSprite[2];
                m_BlueToothButton.interactable = true;
            }
            m_timer = 0;
            break;
        }
    }