예제 #1
0
 /// <summary>
 /// Ends the pause. Called by End_Pause_Button
 /// </summary>
 public void EndPause()
 {
     LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_PAUSE_END);
     checkingTime = true;
     paused       = false;
     UI_Game();
 }
예제 #2
0
 /// <summary>
 /// Listens for and applies snap action (positions block at the top of the game field)
 /// </summary>
 void CheckSnap()
 {
     //Snap orientated group to top of play field
     if (CustomInput("down"))
     {
         //Don't allow snap if orientation is wrong
         if (!FindObjectOfType <FamiliarizationController>().CorrectOrientation())
         {
             return;
         }
         //Check for correct orientation
         orientation = false;
         bool snap = true;
         while (snap)
         {
             //Check if block is at the top
             foreach (Transform child in transform)
             {
                 if (Grid.ToGrid(child.position).y == snapPos)
                 {
                     snap = false;
                 }
             }
             //Move down one and update if still snapping
             if (snap)
             {
                 transform.position += new Vector3(0, -1, 0);
                 UpdateGrid();
             }
         }
         LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_FAMI_BLOCK_POS,
                                          FamiliarizationController.PositionAverage(transform).ToString());
         SwapGhosts();
     }
 }
예제 #3
0
    /// <summary>
    /// Sets the counter balance ID (1,2,3, or 4). Called by CounterBalance_ID_InputField
    /// </summary>
    /// <param name="val">ID value</param>
    public void SetCounterBalanceID(string val)
    {
        int id;

        Int32.TryParse(val, out id);
        LoggerCSV.GetInstance().counterBalanceID = id;
    }
예제 #4
0
    /// <summary>
    /// Checks the password. Called by Admin_InputField
    /// </summary>
    /// <param name="s">String to check against passoword</param>
    public void CheckPassword(string s)
    {
        if (s == password)
        {
            LoggerCSV logger = LoggerCSV.GetInstance();
            logger.AddEvent(LoggerCSV.EVENT_UNABLE);
            if (logger.gameMode == LoggerCSV.BCI_MODE)
            {
                logger.AddEvent(LoggerCSV.EVENT_END_BCI);
            }
            else
            {
                logger.AddEvent(LoggerCSV.EVENT_END_NORMAL);
            }

            //Reset Persistnent master
            if (logger.gameMode == LoggerCSV.BCI_MODE)
            {
                GameObject master = GameObject.Find("Persistent_Master");
                Destroy(master.GetComponent <EmotivControl>());
                Destroy(master.GetComponent <EmoFacialExpression>());
            }
            //Reset Logger
            logger.inSession = false;
            logger.SaveCSV();
            logger.ResetCSV();
            SceneManager.LoadScene(0);
        }
        else
        {
            btnAdmin.gameObject.SetActive(true);
            ifAdmin.text = string.Empty;
            ifAdmin.gameObject.SetActive(false);
        }
    }
예제 #5
0
 /// <summary>
 /// Controls animation of TrainingCube
 /// </summary>
 void Update()
 {
     //Neutral action = dont move
     //Right
     if (action == ACTION_RIGHT)
     {
         if (transform.localPosition.x < startPos + offset)
         {
             transform.Translate(speed * Time.deltaTime * 10, 0, 0);
         }
         if (UI.rightTrial && transform.position.x > startPos + 5)
         {
             LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_TRAINING_TRIAL_PASS_R);
             UI.UpdateUI("done right");
         }
     }
     //Left
     else if (action == ACTION_LEFT)
     {
         if (transform.localPosition.x > startPos - offset)
         {
             transform.Translate(-speed * Time.deltaTime * 10, 0, 0);
         }
         if (UI.leftTrial && transform.position.x < startPos - 5)
         {
             LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_TRAINING_TRIAL_PASS_L);
             UI.UpdateUI("done left");
         }
     }
 }
예제 #6
0
 /// <summary>
 /// Starts the game. Called by Start_Button
 /// </summary>
 public void StartGame()
 {
     if (LoggerCSV.GetInstance().participantID < 1)
     {
         StartCoroutine(ShowMessage("Please Enter a Valid Participant ID", 1.5f));
         return;
     }
     if (Array.IndexOf(counterBalnaceOptions, LoggerCSV.GetInstance().counterBalanceID) < 0)
     {
         StartCoroutine(ShowMessage("Please Enter a Valid Participant Group", 1.5f));
         return;
     }
     //Start saving data automatically
     LoggerCSV.GetInstance().inSession = true;
     if (LoggerCSV.GetInstance().gameMode == LoggerCSV.NORMAL_MODE)
     {
         LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_START_NORMAL);
         SceneManager.LoadScene(2);
     }
     else
     {
         GameObject master = GameObject.Find("Persistent_Master");
         master.AddComponent <EmotivControl>();
         master.AddComponent <EmoFacialExpression>();
         LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_START_BCI);
         SceneManager.LoadScene(1);
     }
 }
예제 #7
0
    /// <summary>
    /// Checks for user input
    /// </summary>
    void Update()
    {
        if (LoggerCSV.GetInstance().gameMode == LoggerCSV.BCI_MODE)
        {
            emotivLag += Time.deltaTime;
        }

        if (!FamiliarizationController.paused)
        {
            if (orientation)
            {
                CheckRotate();
                CheckSnap();
            }
            else
            {
                CheckMoveLeft();
                CheckMoveRight();

                CheckFallDown();
            }
            if (!completed)
            {
                UpdateGhost();
            }
        }
    }
예제 #8
0
 /// <summary>
 /// Starts the pause. Called by Pause_Button
 /// </summary>
 public void StartPause()
 {
     LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_PAUSE_START);
     checkingTime = false;
     paused       = true;
     UI_Pause("pause");
 }
예제 #9
0
    /// <summary>
    /// Initiates trainging of mental command, called by Left_Button, Right_Button, and Neutral_Button
    /// </summary>
    /// <param name="type">Command to be trained ("Neutral","Left","Right")</param>
    public void TrainAction(string type)
    {
        LoggerCSV logger = LoggerCSV.GetInstance();

        trainType = type;
        EdkDll.IEE_MentalCommandAction_t toTrain = EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL;
        cube.SetAciton(cube.ACTION_RESET);
        switch (type)
        {
        case "Left":
            toTrain = EdkDll.IEE_MentalCommandAction_t.MC_LEFT;
            logger.AddEvent(LoggerCSV.EVENT_TRAINING_L);
            break;

        case "Right":
            toTrain = EdkDll.IEE_MentalCommandAction_t.MC_RIGHT;
            logger.AddEvent(LoggerCSV.EVENT_TRAINING_R);
            break;

        default:
            logger.AddEvent(LoggerCSV.EVENT_TRAINING_N);
            break;
        }

        StartCoroutine(UI.UpdateSlider());

        EmoMentalCommand.EnableMentalCommandAction(toTrain, true);
        EmoMentalCommand.EnableMentalCommandActionsList();
        EmoMentalCommand.StartTrainingMentalCommand(toTrain);
    }
예제 #10
0
    /// <summary>
    /// Checks if block is above game area
    /// </summary>
    void CheckGameOver()
    {
        foreach (Transform child in transform)
        {
            Vector2 v = Grid.ToGrid(child.position);
            if (v.y >= snapPos)
            {
                //Log Game over
                LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_GAME_OVER);

                MainController.score = 0;

                foreach (Transform c in transform.parent)
                {
                    Destroy(c.gameObject);
                }

                //Restart Game
                FindObjectOfType <MainSpawn>().CreateFirst();
                FindObjectOfType <MainSpawn>().CreateNext();


                return;
            }
        }
    }
예제 #11
0
    /// <summary>
    /// Sets the participant ID. Called by Participant_ID_InputField
    /// </summary>
    /// <param name="val">ID value</param>
    public void SetParticipantID(string val)
    {
        int id;

        Int32.TryParse(val, out id);
        LoggerCSV.GetInstance().participantID = id;
    }
예제 #12
0
 /// <summary>
 /// Check if halfway or end has been reached
 /// </summary>
 void CheckTime()
 {
     halfAllottedTime -= Time.deltaTime;
     if (halfAllottedTime < 0)
     {
         paused       = true;
         checkingTime = false;
         if (!midWayReached)
         {
             LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_PAUSE_START);
             midWayReached    = true;
             halfAllottedTime = allotedTime / 2;
             UI_Pause("midway");
         }
         else
         {
             LoggerCSV logger = LoggerCSV.GetInstance();
             if (logger.gameMode == LoggerCSV.BCI_MODE)
             {
                 LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_END_BCI);
             }
             else
             {
                 logger.AddEvent(LoggerCSV.EVENT_END_NORMAL);
             }
             UI_Pause("finished");
             logger.inSession = false;
             logger.SaveCSV();
             logger.ResetCSV();
         }
     }
 }
예제 #13
0
    /// <summary>
    /// Clear mental command accepted by Accept_Clear_Button,
    /// Clears all data if neutral is cleared
    /// </summary>
    /// <param name="type">Command to be trained ("Neutral","Left","Right")</param>
    public void ClearTraining()
    {
        LoggerCSV logger     = LoggerCSV.GetInstance();
        string    statusText = "Neutral";

        EdkDll.IEE_MentalCommandAction_t action = EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL;
        switch (trainType)
        {
        case "clear left":
            statusText = "Left";
            action     = EdkDll.IEE_MentalCommandAction_t.MC_LEFT;
            trainType  = "clear left";
            logger.AddEvent(LoggerCSV.EVENT_TRAINING_CLEAR_L);
            break;

        case "clear right":
            statusText = "Right";
            action     = EdkDll.IEE_MentalCommandAction_t.MC_RIGHT;
            trainType  = "clear right";
            logger.AddEvent(LoggerCSV.EVENT_TRAINING_CLEAR_R);
            break;

        default:
            logger.AddEvent(LoggerCSV.EVENT_TRAINING_CLEAR_N);
            UI.UpdateStatusText("Current Aciton: None");
            trainType = "clear neutral";
            Debug.Log(action);
            EraseAction(action);
            //Clear left and right if enabled
            //Left
            if (EmoMentalCommand.MentalCommandActionsEnabled[5])
            {
                Debug.Log("left active - clear");
                EraseAction(EdkDll.IEE_MentalCommandAction_t.MC_LEFT);
            }
            //Right
            if (EmoMentalCommand.MentalCommandActionsEnabled[6])
            {
                Debug.Log("right active - clear");
                EraseAction(EdkDll.IEE_MentalCommandAction_t.MC_LEFT);
            }
            DeactivateRL();
            //Update UI and Training cube
            UI.UpdateStatusText("Cleared " + statusText + " Training Data");
            UI.UpdateUI(trainType);
            cube.SetAciton(cube.ACTION_RESET);
            return;
        }

        EraseAction(action);
        //Deactivate cleared action
        EmoMentalCommand.EnableMentalCommandAction(action, false);
        EmoMentalCommand.EnableMentalCommandActionsList();
        //Update UI and Training cube
        UI.UpdateUI(trainType);
        UI.ActivateButtons(true);
        cube.SetAciton(cube.ACTION_RESET);
        UI.UpdateStatusText("Cleared " + statusText + " Training Data");
    }
예제 #14
0
파일: Grid.cs 프로젝트: esposen/BrainBlocks
 public static void DestroyRow(int y)
 {
     MainController.score++;
     LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_SCORE, MainController.score.ToString());
     for (int x = 0; x < w; x++)
     {
         Destroy(grid[x, y].gameObject);
         grid[x, y] = null;
     }
 }
예제 #15
0
 void Start()
 {
     if (LoggerCSV.GetInstance().gameMode != LoggerCSV.BCI_MODE)
     {
         Destroy(gameObject);
     }
     initHeadset();
     engine = EmoEngine.Instance;
     bindEvents();
 }
예제 #16
0
    //------------------------------UI OnClick Functions------------------------------//


    /// <summary>
    /// Finishs the game. Called by Done_Button
    /// </summary>
    public void FinishGame()
    {
        if (LoggerCSV.GetInstance().gameMode == LoggerCSV.BCI_MODE)
        {
            GameObject master = GameObject.Find("Persistent_Master");
            Destroy(GameObject.Find("Contact_Quality"));
            master.GetComponent <EmotivControl>().End();
            Destroy(master.GetComponent <EmotivControl>());
            Destroy(master.GetComponent <EmoFacialExpression>());
        }
        SceneManager.LoadScene(0);
    }
예제 #17
0
//------------------------------Unity Functions------------------------------//

    /// <summary>
    /// Start this instance.
    /// </summary>
    private void Start()
    {
        LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_BLOCK_CREATE);
        if (LoggerCSV.GetInstance().gameMode == LoggerCSV.BCI_MODE)
        {
            emotivLag = 0f;
            engine    = EmoEngine.Instance;
            BindEvents();
        }
        orientation = true;
        ghost       = GameObject.Find(tag + "_ghost");
    }
예제 #18
0
 /// <summary>
 /// Starts/Ends pause periods
 /// </summary>
 public void TogglePause()
 {
     paused = !paused;
     if (!paused)
     {
         LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_PAUSE_END);
     }
     else
     {
         LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_PAUSE_START);
     }
 }
예제 #19
0
//------------------------------Unity Functions------------------------------//
    /// <summary>
    /// Start this instance.
    /// </summary>
    private void Start()
    {
        if (LoggerCSV.GetInstance().gameMode == LoggerCSV.BCI_MODE)
        {
            emotivLag = 0f;
            engine    = EmoEngine.Instance;
            BindEvents();
        }
        completed   = false;
        orientation = true;
        ghost       = GameObject.Find(tag + "_ghost");
    }
예제 #20
0
    private float timeOutTime = 1800f; //30 min given to pass this stage

    /// <summary>
    /// Checks if alotted time for training has expired
    /// </summary>
    private void Update()
    {
        if (started && !paused)
        {
            runningTimer += Time.deltaTime;
            if (runningTimer > timeOutTime)
            {
                LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_TIMEOUT);
                Debug.Log(timeOutPanel.ToString());
                timeOutPanel.gameObject.SetActive(true);
                paused = true;
            }
        }
    }
예제 #21
0
    //------------------------------Familiarization Scene Control Functions------------------------------//

    /// <summary>
    /// Checks if alotted time for trail has expired
    /// </summary>
    private void Update()
    {
        if (started && !paused)
        {
            runningTimer += Time.deltaTime;
            //End trial
            if (runningTimer > timePerTrial)
            {
                LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_TIMEOUT);
                timeOutPanel.SetActive(true);
                paused = true;
                //Admin must be used at this point
            }
        }
    }
예제 #22
0
    //------------------------------UI OnClick Functions------------------------------//
    /// <summary>
    /// Customs the start function called by Start_Trials_Buttom.
    /// </summary>
    public void CustomStart()
    {
        LoggerCSV logger = LoggerCSV.GetInstance();

        logger.AddEvent(LoggerCSV.EVENT_FAMI_START);
        leftFirst = logger.counterBalanceID == 1 ||
                    logger.counterBalanceID == 3;
        spawnLeft  = leftFirst;
        trialStage = 0;
        paused     = false;
        ToggleUI(paused, "none");
        runningTimer = 0f;
        started      = true;
        CreateNext();
    }
예제 #23
0
    /// <summary>
    /// Creates the next trial prompt
    /// </summary>
    public void CreateNext()
    {
        //Check if familiarization stage is finished
        if (CheckStage())
        {
            return;
        }
        //Destroy objects from previous trial
        Destroy(group);
        Destroy(target);

        //Create Player Object
        int i = Random.Range(0, options.Length);

        group = Instantiate(options[i], transform.position, Quaternion.identity);

        //Choose random position and rotation of prompt
        //Loop ensures target is not directly below group
        while (true)
        {
            Vector2 targetPos;
            if (spawnLeft)
            {
                targetPos = new Vector2(Random.Range(0, 4), 0);
            }
            else
            {
                targetPos = new Vector2(Random.Range(5, 9), 0);
            }

            Quaternion targetRot = new Quaternion(0, 0, Random.Range(0, rotationOptions.Length), 0);
            //Create trial object
            target = Instantiate(options[i], targetPos, targetRot);
            //Check if directly below
            //Average needed because different rotations create different x vals
            if (PositionAverage(target.transform) != PositionAverage(group.transform))
            {
                spawnLeft = !spawnLeft;
                break;
            }
            Destroy(target);
        }
        SnapTarget();         //For when the random rotation/postioning put it out of bounds

        LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_FAMI_PROMT,
                                         PositionAverage(target.transform).ToString());
        group.AddComponent <FamiliarizationSet>();
    }
예제 #24
0
    //------------------------------UI OnClick Functions------------------------------//

    /// <summary>
    /// Custom Start function called by Start_Training_Button
    /// </summary>
    public void CustomStart()
    {
        LoggerCSV logger = LoggerCSV.GetInstance();

        logger.AddEvent(LoggerCSV.EVENT_TRAINSTAGE_START);

        UI        = GetComponent <TrainingUI>();
        cube      = GameObject.Find("Block").GetComponent <TrainingCube>();
        leftFirst = logger.counterBalanceID == 1 ||
                    logger.counterBalanceID == 2;

        engine = EmoEngine.Instance;
        DeactivateRL();
        UI.InitUI();
        BindEvents();
    }
예제 #25
0
    void Update()
    {
        timeLag += Time.deltaTime; //moniters amount of time since last cube pick up/drop

        if (usingEpoc)
        {
            emotivControl();
        }
        buttonControll();

        checkCube();

        if (Input.GetKeyDown(KeyCode.Y))
        {
            LoggerCSV.GetInstance().SaveCSV();
        }
    }
예제 #26
0
    /// <summary>
    /// Listens for and applies move right action
    /// </summary>
    void CheckFallDown()
    {
        // Fall
        if (CustomInput("down"))
        {
            //Log Drop time in CSV file
            LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_BLOCK_DROP);


            // Modify position
            transform.position += new Vector3(0, -1, 0);

            // See if valid
            while (LegalGridPos())
            {
                // It's valid. Update grid.
                UpdateGrid();
                transform.position += new Vector3(0, -1, 0);
            }
            // It's not valid. revert.
            transform.position += new Vector3(0, 1, 0);

            // Clear filled horizontal lines
            Grid.DeleteFullRows();

            // Spawn next Group
            FindObjectOfType <MainSpawn>().CreateNext();

            //Check Game Over
            CheckGameOver();

            //Unbind Emotiv Events
            if (LoggerCSV.GetInstance().gameMode == LoggerCSV.BCI_MODE)
            {
                UnbindEvent();
            }

            // Disable script
            enabled = false;
        }
    }
예제 #27
0
//------------------------------User Input Listener Functions------------------------------//



    /// <summary>
    /// Listens for and applies rotate action
    /// </summary>
    void CheckRotate()
    {
        // Rotate
        if (CustomInput("rotate"))
        {
            transform.Rotate(0, 0, -90);
            // See if valid
            if (LegalGridPos())
            {
                // It's valid. Update grid.
                UpdateGrid();
            }
            else
            {
                // It's not valid. revert.
                transform.Rotate(0, 0, 90);
            }

            LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_BLOCK_ROTATE);
        }
    }
예제 #28
0
 /// <summary>
 /// Checks if user is done with familiarization trials.
 /// </summary>
 /// <returns><c>true</c>, if max stage is reached, <c>false</c> otherwise.</returns>
 bool CheckStage()
 {
     if (trialStage != 0)
     {
         LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_FAMI_PASS);
     }
     if (trialStage == maxStage)
     {
         LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_FAMI_END);
         //Stop checking time
         started = false;
         ToggleUI(true, "finished");
         return(true);
     }
     else
     {
         runningTimer   = 0f;
         trialText.text = "Trial " + (++trialStage) + " of " + maxStage;
         return(false);
     }
 }
예제 #29
0
    /// <summary>
    /// Listens for and applies move right action
    /// </summary>
    void CheckMoveRight()
    {
        // Move Right
        if (CustomInput("right"))
        {
            // Modify position
            transform.position += new Vector3(1, 0, 0);

            // See if valid
            if (LegalGridPos())
            {
                // It's valid. Update grid.
                UpdateGrid();
            }
            else
            {
                // It's not valid. revert.
                transform.position += new Vector3(-1, 0, 0);
            }
            LoggerCSV.GetInstance().AddEvent(LoggerCSV.EVENT_BLOCK_RIGHT,
                                             FamiliarizationController.PositionAverage(transform).ToString());
        }
    }
예제 #30
0
//------------------------------Input helper Functions------------------------------//

    /// <summary>
    /// Custom Input function that works across control modes
    /// </summary>
    /// <returns><c>true</c>, if input was occuring, <c>false</c> otherwise.</returns>
    /// <param name="type">Input to check</param>
    private bool CustomInput(string type)
    {
        if (LoggerCSV.GetInstance().gameMode == LoggerCSV.BCI_MODE)
        {
            if (type == "down")
            {
                return(Input.GetKeyDown(KeyCode.DownArrow));
            }
            else if (type == "up")
            {
                return(Input.GetKeyDown(KeyCode.UpArrow));
            }

            switch (type)
            {
            case "rotate":
                if (EmoFacialExpression.isBlink && emotivLag > blinkProcessInterval)
                {
                    emotivLag = 0f;
                    return(true);
                }
                break;

            case "left":
                if (mentalAction == 2 && emotivLag > actionProcessInterval)
                {
                    emotivLag = 0f;
                    return(true);
                }
                break;

            case "right":
                if (mentalAction == 1 && emotivLag > actionProcessInterval)
                {
                    emotivLag = 0f;
                    return(true);
                }
                break;

            default:
                Debug.Log("CustomInput() used incorrectly with: " + type);
                break;
            }
            return(false);
        }
        else
        {
            switch (type)
            {
            case "rotate":
                return(Input.GetKeyDown(KeyCode.Space));

            case "left":
                return(Input.GetKeyDown(KeyCode.LeftArrow));

            case "right":
                return(Input.GetKeyDown(KeyCode.RightArrow));

            case "down":
                return(Input.GetKeyDown(KeyCode.DownArrow));

            case "up":
                return(Input.GetKeyDown(KeyCode.UpArrow));

            default:
                Debug.Log("CustomInput() used incorrectly with: " + type);
                return(false);
            }
        }
    }