public void UpdateButtonAction()
 {
     if (b_Loggin)
     {
         Debug.Log(TAG + "Update-Button hit");
     }
     if (!b_initialized)
     {
         b_initialized = true;
         m_status      = "Initializing native plugin";
         BluetoothLEPlugin.Initialize(b_Loggin);
                     #if UNITY_ANDROID
         StartCoroutine(StartDelayedScan(0));
                     #elif UNITY_IPHONE && !UNITY_EDITOR
         StartCoroutine(StartDelayedScan(0.2f));
                     #elif UNITY_STANDALONE_OSX || UNITY_EDITOR
         StartCoroutine(StartDelayedScan(0.2f));
                     #endif
     }
     else
     {
         clearMAC();
         if (m_heartrate != null)
         {
             m_heartrate.Reset();
             m_status = "disconnecting HeartRate";
             m_heartrate.Disconnect();
         }
         else
         {
             OnDeviceDisconnected(8, null);
         }
     }
 }
Exemplo n.º 2
0
    void OnGUI()
    {
        GUI.skin = m_skin;
        GUIStyle labelStyle = GUI.skin.GetStyle("Label_left");

                #if UNITY_ANDROID
        labelStyle.fontSize = 31;                 //set in Asset->Resources->Menu: in Inspector: Button->Overflow->Font Size; same for Label
                #elif UNITY_IPHONE && !UNITY_EDITOR
        labelStyle.fontSize = 25;
                #elif UNITY_STANDALONE_OSX || UNITY_EDITOR
        labelStyle.fontSize = 15;
                #endif
        //Height of Label on Bottom
        float labelHeight = m_skin.GetStyle("Label").CalcHeight(new GUIContent(m_status), Screen.width - 20);
        GUI.Label(new Rect(10, Screen.height - labelHeight, Screen.width - 20, labelHeight), m_status);
        if (m_state == MenuState.START)
        {
            Vector2 calcSize = m_skin.GetStyle("Button").CalcSize(new GUIContent("Update"));
            if (GUI.Button(new Rect(Screen.width / 2 - calcSize.x / 2 - 10, 10, calcSize.x + 20, calcSize.y + 20), "Update"))
            {
                m_state         = MenuState.SCANNING;
                m_currentDevice = null;
                UpdateButtonAction();
            }
        }
        else if (m_state == MenuState.SCANNING)
        {
            //Width(.x) and Height(.y) of "Stop Scan"-Button:
            Vector2 calcSize = m_skin.GetStyle("Button").CalcSize(new GUIContent("Update"));
            if (GUI.Button(new Rect(Screen.width / 2 - calcSize.x / 2 - 10, 10, calcSize.x + 20, calcSize.y + 20), "Update"))
            {
                m_currentDevice = null;
                UpdateButtonAction();
            }
            m_scrollDistance = GUI.BeginScrollView(new Rect(10, 10 + calcSize.y + 20 + 50, Screen.width - 20, Screen.height - (10 + calcSize.y + 20 + 50 + labelHeight + 50)), m_scrollDistance, new Rect(0, 0, Screen.width - 20, m_adresses.Count * (70 + calcSize.y)));
            //Width of the Scrollview: Screen.width-20
            //Height of the Scrollview:  Screen.height - (10+calcSize.y+20+50+labelHeight+50)
            float f_ScrollFill = 0;
            if ((m_adresses.Count * (70 + calcSize.y)) >= (Screen.height - (10 + calcSize.y + 20 + 50 + labelHeight + 50)))
            {
                f_ScrollFill = 110;
            }
            int index = 0;
            //Width(.x) and Height(.y) of "Connect"-Button:
            calcSize = m_skin.GetStyle("Button").CalcSize(new GUIContent("Connect"));
            foreach (BleDevice kv in m_adresses)
            {
                //Height of Label with Devicenames
                labelHeight = m_skin.GetStyle("Label").CalcHeight(new GUIContent("DDD"), 300);
                GUI.Label(new Rect(0, (calcSize.y + 20 - labelHeight) / 2 + index * (calcSize.y + 20 + 50), Screen.width - (20 + f_ScrollFill) - calcSize.x - 70, labelHeight), kv.Name, m_skin.FindStyle("Label_left"));
                if (GUI.Button(new Rect(Screen.width - (20 + f_ScrollFill) - (calcSize.x + 20), index * (calcSize.y + 20 + 50), calcSize.x + 20, calcSize.y + 20), "Connect"))
                {
                    m_currentDevice = kv;
                    m_state         = MenuState.START;
                }
                index++;
            }
            GUI.EndScrollView();
            if (m_currentDevice != null)
            {
                ConnectDevice(m_currentDevice);
            }
            //} else if (m_state == MenuState.BINDING) {
        }
        else if (m_state == MenuState.CONNECTED)
        {
            Vector2 calcSize = m_skin.GetStyle("Button").CalcSize(new GUIContent("Disconnect"));                                  //org update instead of Disconnect
            if (GUI.Button(new Rect(Screen.width / 2 - calcSize.x / 2 - 10, 10, calcSize.x + 20, calcSize.y + 20), "Disconnect")) //org update instead of Disconnect
            {
                m_currentDevice = null;
                s_LabelText     = "";
                clearMAC();
                if (m_heartrate != null)
                {
                    m_heartrate.Reset();                    //unsubscribing BleDeviceEvents
                    m_status = "disconnecting HeartRate";
                    m_heartrate.Disconnect();
                }
                else
                {
                    OnDeviceDisconnected(8, null);
                }
            }
            float tmpHeight = labelHeight;
            //Height of whole content:
            labelHeight      = m_skin.GetStyle("Label_left").CalcHeight(new GUIContent(s_LabelText), Screen.width - 20);
            m_scrollDistance = GUI.BeginScrollView(new Rect(10, 10 + calcSize.y + 20 + 50, Screen.width - 20, Screen.height - (10 + calcSize.y + 20 + 50 + tmpHeight + 50)), m_scrollDistance, new Rect(0, 0, Screen.width - 20, labelHeight));
            GUI.Label(new Rect(0, 0, Screen.width - 20, labelHeight), s_LabelText, m_skin.GetStyle("Label_left"));
            GUI.EndScrollView();
        }
    }