コード例 #1
0
ファイル: TrainingBlink.cs プロジェクト: AhnBCILab/P300BCIWTS
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Q))
     {
         SceneManager.LoadScene("Menu");
     }
     current_time += Time.deltaTime;
     if (targetChange == 6 && current_time < 10.0f)
     {
         if (current_time > 5.0f)
         {
             theSender.send(finish);
             theSender.close();
         }
         if (current_time > 5.0f)
         {
             SceneManager.LoadScene("Menu");
         }
     }
     //Restart blinking
     if (current_time > 5.0f && blinkstate == true)
     {
         blinkstate = false;
         but0       = true;
         but1       = true;
         but2       = true;
         but3       = true;
         but4       = true;
         but5       = true;
         blinkcnt   = 0;
         BlinkButton();
     }
     else if (current_time > 41.0f)
     {
         current_time = 0.0f;
         blinkstate   = true;
     }
 }
コード例 #2
0
ファイル: EuropeBlink.cs プロジェクト: AhnBCILab/P300BCIWTS
    public void BlinkButton()
    {
        if (blinkcnt < BlinkCount)
        {
            rndnum = UnityEngine.Random.Range(0, 6);
            if (rndnum == 0 && Button0 == true)
            {
                Button0        = false;
                buttonIndexNum = 1;
                theSender.send(buttonIndexNum);
                pubimg = Iceland;

                if (isBlinking)
                {
                    return;
                }
                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 0 && Button0 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 1 && Button1 == true)
            {
                Button1        = false;
                buttonIndexNum = 2;
                theSender.send(buttonIndexNum);
                pubimg = London;

                if (isBlinking)
                {
                    return;
                }

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 1 && Button1 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 2 && Button2 == true)
            {
                Button2        = false;
                buttonIndexNum = 3;
                theSender.send(buttonIndexNum);
                pubimg = Paris;

                if (isBlinking)
                {
                    return;
                }

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 2 && Button2 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 3 && Button3 == true)
            {
                Button3        = false;
                buttonIndexNum = 4;
                theSender.send(buttonIndexNum);
                pubimg = Barcelona;

                if (isBlinking)
                {
                    return;
                }

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 3 && Button3 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 4 && Button4 == true)
            {
                Button4        = false;
                buttonIndexNum = 5;
                theSender.send(buttonIndexNum);
                pubimg = Rome;

                if (isBlinking)
                {
                    return;
                }

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 4 && Button4 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 5 && Button5 == true)
            {
                Button5        = false;
                buttonIndexNum = 6;
                theSender.send(buttonIndexNum);
                pubimg = Firenze;

                if (isBlinking)
                {
                    return;
                }

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 5 && Button5 == false)
            {
                BlinkButton();
            }

            if (Button0 == false && Button1 == false && Button2 == false && Button3 == false && Button4 == false && Button5 == false)
            {
                Button0 = true;
                Button1 = true;
                Button2 = true;
                Button3 = true;
                Button4 = true;
                Button5 = true;
            }
        }
        else
        {
            System.Threading.Thread.Sleep(1000);
            theSender.send(finish);
            output = InputName.theListener.receive();
            theSender.send(start);
            theSender.close();
            System.Threading.Thread.Sleep(1000);
            FileStream   f      = new FileStream(Application.dataPath + "/StreamingAssets/" + InputName.patient_id + ".txt", FileMode.Append, FileAccess.Write);
            StreamWriter writer = new StreamWriter(f, System.Text.Encoding.Unicode);
            writer.WriteLine("Order: " + random + " / Result: " + output + "\n");
            writer.Close();
            switch (output)
            {
            case "1":
                SceneManager.LoadScene("Iceland");
                break;

            case "2":
                SceneManager.LoadScene("London");
                break;

            case "3":
                SceneManager.LoadScene("Paris");
                break;

            case "4":
                SceneManager.LoadScene("Barcelona");
                break;

            case "5":
                SceneManager.LoadScene("Rome");
                break;

            case "6":
                SceneManager.LoadScene("Firenze");
                break;

            default:
                break;
            }
        }
    }
コード例 #3
0
    // It minimizes the repeated blinking of the same button by making the 6 buttons blink once within each sequence(6 times) unconditionally.
    // The variables controlling this is Button0 to Button5.
    public void BlinkButton() 
    {
        ////////////////////////////////////////////// If the total number of blinks has not been reached, /////////////////////////////////////////////////
        if (blinkcnt < BlinkCount)
        {
            rndnum = UnityEngine.Random.Range(0, 6); // Randomly generate one of the values ​​from 0 to 5
            if (rndnum == 0 && Button0 == true) // If the generated random number is 0 and Button0 is true,
            {
                Button0 = false; // Change Button0 to false to indicate that the button0 is blinking
                buttonIndexNum = 1; // Assign Button0 identifier to send to OpenViBE
                theSender.send(buttonIndexNum); // Send the identifier to OpenViBE
                pubimg = NorthAmerica; // 

                if (isBlinking) // If the previous button is not blinking successfully, isBlinking is true
                    return; // Therefore, the system will stop through the return command.
                if (pubimg != null)
                {
                    isBlinking = true; // Indication of starting button blinking
                    InvokeRepeating("ToggleState", startDelay, interval); // Code to make the actual button blink
                }
            }
            else if (rndnum == 0 && Button0 == false)
            {
                BlinkButton(); // Call BlinkButton again.
            }
            else if (rndnum == 1 && Button1 == true) // Same as the first if statement
            {
                Button1 = false;
                buttonIndexNum = 2;
                theSender.send(buttonIndexNum);
                pubimg = Europe;

                if (isBlinking)
                    return;

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 1 && Button1 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 2 && Button2 == true)
            {
                Button2 = false;
                buttonIndexNum = 3;
                theSender.send(buttonIndexNum);
                pubimg = Asia;

                if (isBlinking)
                    return;

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }
            }
            else if (rndnum == 2 && Button2 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 3 && Button3 == true)
            {
                Button3 = false;
                buttonIndexNum = 4;
                theSender.send(buttonIndexNum);
                pubimg = SouthAmerica;

                if (isBlinking)
                    return;

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }

            }
            else if (rndnum == 3 && Button3 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 4 && Button4 == true)
            {
                Button4 = false;
                buttonIndexNum = 5;
                theSender.send(buttonIndexNum);
                pubimg = Africa;

                if (isBlinking)
                    return;

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }

            }
            else if (rndnum == 4 && Button4 == false)
            {
                BlinkButton();
            }
            else if (rndnum == 5 && Button5 == true)
            {
                Button5 = false;
                buttonIndexNum = 6;
                theSender.send(buttonIndexNum);
                pubimg = Oceania;

                if (isBlinking)
                    return;

                if (pubimg != null)
                {
                    isBlinking = true;
                    InvokeRepeating("ToggleState", startDelay, interval);
                }

            }
            else if (rndnum == 5 && Button5 == false)
            {
                BlinkButton();
            }

            // If all buttons blink, set the boolean value to true so that each button can blink again.
            if (Button0 == false && Button1 == false && Button2 == false && Button3 == false && Button4 == false && Button5 == false)
            {
                Button0 = true;
                Button1 = true;
                Button2 = true;
                Button3 = true;
                Button4 = true;
                Button5 = true;
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////// If the total number of flashes has been reached, /////////////////////////////////////////////////
        else
        {
            InputName.Try = InputName.Try + 1;
            System.Threading.Thread.Sleep(1000); // Wait for 1 second. This latency is absolutely necessary to use the epoch for the last button blink.
            theSender.send(finish); // Send a marker to inform OpenViBE that blinking is over
            output = InputName.theListener.receive(); // Receive classification result from OpenViBE
            theSender.send(start); // Send a marker to inform OpenViBE that blinking will be re-started in next trial.
            theSender.close(); // Release a sender instance for the system reliability.
            System.Threading.Thread.Sleep(1000);

            // Write in the text file whether the classification result matched the target presented in current trial.
            FileStream f = new FileStream(Application.dataPath + "/StreamingAssets/" + InputName.patient_id + ".txt", FileMode.Append, FileAccess.Write);
            StreamWriter writer = new StreamWriter(f, System.Text.Encoding.Unicode);
            writer.WriteLine("Order: " + random + " / Result: " + output);
            writer.Close();
            //////////////////////////////////////////////////////////////////////////////////////////////////////////

            switch (output) // Scene movement according to target and classification result.
            {
                case "1":
                    SceneManager.LoadScene("NorthAmerica");
                    break;
                case "2":
                    SceneManager.LoadScene("Europe");
                    break;
                case "3":
                    SceneManager.LoadScene("Asia");
                    break;
                case "4":
                    SceneManager.LoadScene("SouthAmerica");
                    break;
                case "5":
                    SceneManager.LoadScene("Africa");
                    break;
                case "6":
                    SceneManager.LoadScene("Oceania");
                    break;
                default:
                    break;
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }