Beispiel #1
0
        private IEnumerator ProcessData()
        {
            while (true)
            {
                yield return(new WaitForEndOfFrame());

                try
                {
                    string result = serialPort.ReadLine();

                    // Tests
                    //string result = SimulateReadLine();

                    string[] resultData = result.Split(';');

                    ArdKeyCode[] keyCodes = (ArdKeyCode[])Enum.GetValues(typeof(ArdKeyCode));
                    for (int i = 0; i < keyCodes.Length; i++)
                    {
                        ArdKeyCode keyCode = keyCodes[i];
                        ArdButton  button  = buttons[keyCode];
                        int        data    = int.Parse(resultData[i]);

                        button.ProcessData(data);
                    }

                    string leituraSensor = resultData[resultData.Length - 1];
                    Debug.Log("Leitura Sensor: " + leituraSensor);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
        }
Beispiel #2
0
        private IEnumerator ProcessData()
        {
            while (true)
            {
                yield return(new WaitForEndOfFrame());

                try
                {
                    string result = serialPort.ReadLine();

                    // Tests
                    //string result = SimulateReadLine();

                    string[] resultData = result.Split(';');

                    ArdKeyCode[] keyCodes = (ArdKeyCode[])Enum.GetValues(typeof(ArdKeyCode));
                    for (int i = 0; i < keyCodes.Length; i++)
                    {
                        ArdKeyCode keyCode = keyCodes[i];
                        ArdButton  button  = buttons[keyCode];
                        data = int.Parse(resultData[i]);

                        button.ProcessData(data);
                    }

                    data = int.Parse(resultData[keyCodes.Length - 1]);

                    if (data != null)
                    {
                        //print("Data: " + data);
                        if (data <= 256)
                        {
                            PlayerPrefs.SetInt("Dificuldade", 1);
                        }
                        else if (data > 256 && data <= 512)
                        {
                            PlayerPrefs.SetInt("Dificuldade", 2);
                        }
                        else if (data > 512 && data <= 768)
                        {
                            PlayerPrefs.SetInt("Dificuldade", 3);
                        }
                        else if (data > 768)
                        {
                            PlayerPrefs.SetInt("Dificuldade", 4);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
        }
Beispiel #3
0
        private void Update()
        {
            // Test for pausing the game
            if (GetKeyDown(ArdKeyCode.BUTTON_START))
            {
                Debug.Log("Pausar");
                Time.timeScale = Time.timeScale != 0 ? 0 : 1;
            }

            ArdKeyCode[] keyCodes = (ArdKeyCode[])Enum.GetValues(typeof(ArdKeyCode));
            for (int i = 0; i < keyCodes.Length; i++)
            {
                ArdKeyCode keyCode  = keyCodes[i];
                ArdButton  button   = buttons[keyCode];
                GameObject buttonRb = buttonsRbs[i];


                Rigidbody rbDown  = buttonRb.transform.GetChild(0).GetComponent <Rigidbody>();
                Rigidbody rbPress = buttonRb.transform.GetChild(1).GetComponent <Rigidbody>();
                Rigidbody rbUp    = buttonRb.transform.GetChild(2).GetComponent <Rigidbody>();

                if (GetKeyDown(keyCode) &&
                    rbDown.velocity == Vector3.zero)
                {
                    rbDown.AddForce(forca * Vector3.up);
                }
                else if (GetKeyUp(keyCode) &&
                         rbUp.velocity == Vector3.zero)
                {
                    rbUp.AddForce(forca * Vector3.up);
                }

                if (GetKey(keyCode) &&
                    rbPress.velocity == Vector3.zero)
                {
                    rbPress.AddForce(forca * Vector3.up);
                }
            }
            Debug.Log("Tamanho rb:" + buttonsRbs.Length);
        }
Beispiel #4
0
        private IEnumerator ProcessData()
        {
            while (true)
            {
                yield return(new WaitForEndOfFrame());

                try
                {
                    string result = serialPort.ReadLine();

                    // Tests
                    // string result = SimulateReadLine(); // funcionou com o teste teclado

                    Debug.Log(result);
                    Debug.Log("teste");

                    string[] resultData = result.Split(';');

                    ArdKeyCode[] keyCodes = (ArdKeyCode[])Enum.GetValues(typeof(ArdKeyCode));
                    Debug.Log("Tamanho vetor: " + keyCodes.Length);
                    for (int i = 0; i < keyCodes.Length; i++)
                    {
                        ArdKeyCode keyCode = keyCodes[i];
                        ArdButton  button  = buttons[keyCode];
                        data = int.Parse(resultData[i]);

                        button.ProcessData(data);
                    }


                    PlayerStats.forcaLuz = data;
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
        }
Beispiel #5
0
        private void Awake()
        {
            try
            {
                serialPort = new SerialPort(port, baudRate)
                {
                    ReadTimeout = 100
                };
                serialPort.Open();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }

            foreach (ArdKeyCode keyCode in Enum.GetValues(typeof(ArdKeyCode)))
            {
                ArdButton button = new ArdButton(keyCode);

                buttons.Add(keyCode, button);
            }

            StartCoroutine(ProcessData());
        }