Esempio n. 1
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        if (bluetoothHelper != null)
        {
            bluetoothHelper.DrawGUI();
        }
        else
        {
            return;
        }

        if (!bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(0, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (bluetoothHelper.isDevicePaired())
                {
                    bluetoothHelper.Connect(); // tries to connect
                }
            }
        }

        //if (bluetoothHelper.isConnected())
        //    if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "SetActive"))
        //    {
        //        Camera.SetActive(true);
        //    }
    }
Esempio n. 2
0
    void OnGUI()
    {
        if (BTHelper == null)
        {
            return;
        }


        BTHelper.DrawGUI();

        if (!BTHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (BTHelper.isDevicePaired())
                {
                    BTHelper.Connect();              // tries to connect
                }
            }
        }

        if (BTHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect"))
            {
                BTHelper.Disconnect();
            }
        }
    }
Esempio n. 3
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        if (isDebugOn)
        {
            if (bluetoothHelper != null)
            {
                bluetoothHelper.DrawGUI();
            }
            else
            {
                return;
            }

            if (!bluetoothHelper.isConnected())
            {
                Btn_Connect.interactable    = true;
                Btn_Disconnect.interactable = false;
                Toggle_isConnected.isOn     = false;
            }

            if (bluetoothHelper.isConnected())
            {
                Btn_Connect.interactable    = false;
                Btn_Disconnect.interactable = true;
                Toggle_isConnected.isOn     = true;
            }

            // Screen Debug
            GUIStyle myStyle = new GUIStyle();
            myStyle.fontSize         = 16;
            myStyle.normal.textColor = Color.blue;
            GUI.Label(new Rect(10, 100, 1080, 1920), myLog, myStyle);
        }
    }
Esempio n. 4
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        if (bluetoothHelper != null)
        {
            bluetoothHelper.DrawGUI();
        }
        else
        {
            return;
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect"))
            {
                bluetoothHelper.Disconnect();
                sphere.GetComponent <Renderer>().material.color = Color.blue;
            }
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Send text"))
            {
                //bluetoothHelper.SendData(new byte[] { 0, 1, 2, 3, 4 });
                bluetoothHelper.SendData("Hi From unity");
            }
        }
    }
Esempio n. 5
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        tmp = GUI.TextField(new Rect(Screen.width / 4, Screen.height / 10, Screen.width / 2, Screen.height / 10 - 10), tmp);

        if (bluetoothHelper != null)
        {
            bluetoothHelper.DrawGUI();
        }
        else
        {
            return;
        }

        if (!bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (bluetoothHelper.isDevicePaired())
                {
                    bluetoothHelper.Connect(); // tries to connect
                }
                else
                {
                    write("Cannot connect, device is not found, for bluetooth classic, pair the device\n\tFor BLE scan for nearby devices");
                }
            }
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect"))
            {
                bluetoothHelper.Disconnect();
                write("Disconnected");
            }

            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Turn On"))
            {
                bluetoothHelper.SendData("O");
                write("Sending O");
            }

            if (GUI.Button(new Rect(Screen.width / 2 + Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Turn Off"))
            {
                bluetoothHelper.SendData("F");
                write("Sending F");
            }
        }
    }
Esempio n. 6
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        if (bluetoothHelper != null)
        {
            bluetoothHelper.DrawGUI();
        }
        else
        {
            return;
        }

        if (!bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (bluetoothHelper.isDevicePaired())
                {
                    bluetoothHelper.Connect();              // tries to connect
                }
                else
                {
                    sphere.GetComponent <Renderer>().material.color = Color.magenta;
                }
            }
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect"))
            {
                bluetoothHelper.Disconnect();
                sphere.GetComponent <Renderer>().material.color = Color.blue;
            }
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Send text"))
            {
                bluetoothHelper.SendData(new Byte[] { 0, 0, 85, 0, 85 });
                // bluetoothHelper.SendData("This is a very long long long long text");
            }
        }
    }