コード例 #1
0
    /// <summary>
    /// Loads the session file assigned to the given game.
    /// </summary>
    public static bool LoadSessionData(TextAsset sessionFile, ref SessionData sData)
    {
        XmlDocument doc = new XmlDocument();
        XmlNode     settingsElem;
        XmlNode     trialsElem;

        try
        {
            doc.LoadXml(sessionFile.text);
            settingsElem = doc.SelectSingleNode("/" + ELEM_SESSION + "/" + ELEM_SETTINGS);
            trialsElem   = doc.SelectSingleNode("/" + ELEM_SESSION + "/" + ELEM_TRIALS);

            sData.fileName = sessionFile.name;
            ParseSessionSettings(settingsElem, ref sData);
            ParseSessionTrials(trialsElem, ref sData);

            if (sData.shuffleTrials)
            {
                SessionUtil.Shuffle(sData.trials);
            }

            return(true);
        }
        catch (Exception e)
        {
            GUILog.Error("Failed to load Session file: {0}\n{1}", sessionFile.name, e.Message);
            return(false);
        }
    }
コード例 #2
0
    /// <summary>
    /// Parses all the session file settings.
    /// </summary>
    private static void ParseSessionSettings(XmlNode settingsElement, ref SessionData sData)
    {
        if (settingsElement == null)
        {
            GUILog.Error("Session {0}, settings element not found.", sData.fileName);
            return;
        }
        foreach (XmlNode n in settingsElement.ChildNodes)
        {
            switch (n.Name)
            {
            case ELEM_GENERAL:
                sData.ParseElement(n as XmlElement);
                break;

            case ELEM_REACT:
                sData.gameData = new ReactData(n as XmlElement);
                break;

            case ELEM_HIGH_STRIKER:
                sData.gameData = new HighStrikerData(n as XmlElement);
                break;

            default:
                break;
            }
        }
    }
コード例 #3
0
    /// <summary>
    /// Creates a log file of the given session data.
    /// </summary>
    public static void WriteSessionLog(ref SessionData sData)
    {
        XDocument doc         = new XDocument();
        XElement  sessionElem = new XElement(ELEM_SESSION);

        // Session Elem children.
        XElement resultsElem  = new XElement(ELEM_RESULTS);
        XElement settingsElem = new XElement(ELEM_SETTINGS);
        XElement trialsElem   = new XElement(ELEM_TRIALS);

        // Populate the elements with data.
        WriteResultsElement(sData, ref resultsElem);
        WriteSettingsElement(sData, ref settingsElem);
        WriteTrialsElement(sData, ref trialsElem);

        // Add all the Elements to the document in the proper order.
        doc.Add(sessionElem);
        sessionElem.Add(resultsElem, settingsElem, trialsElem);

        // Save the document.
        string fileName = GetOutputFilepath(sData);

        GUILog.Log("Using output file {0} for module {1}", fileName, sData.GameName);
        try
        {
            doc.Save(fileName);
            sData.outputWritten = true;
        }
        catch (Exception e)
        {
            GUILog.Error("XMLUtil::WriteSessionLog:: Failed to Save output document {0} \n{1}", fileName, e.Message.ToString());
        }
    }
コード例 #4
0
 private void SetResolution(PointerEventData obj)
 {
     UpdateSetting(obj);
     if (Debug.isDebugBuild)
     {
         GUILog.Clear();
         GUILog.Show(string.Format("{0} 分辨率设置为:{1}", DateTime.Now.ToString("HH:mm:ss"), Global.Ins.resolutionSize));
     }
 }
コード例 #5
0
ファイル: XMLUtil.cs プロジェクト: uday721/UnityExercise
 /// <summary>
 /// Parses a bool attribute.
 /// And assigns it to the referenced variable.
 /// Does nothing if the attribute fails to parse.
 /// </summary>
 public static bool ParseAttribute(XmlNode n, string att, ref bool val, bool optional = false)
 {
     if (n.Attributes[att] != null && bool.TryParse(n.Attributes[att].Value, out val))
     {
         return(true);
     }
     if (!optional)
     {
         GUILog.Error("Could not parse attribute {1} under node {0}", n.Name, att);
     }
     return(false);
 }
コード例 #6
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TippingPointTrialResult r = new TippingPointTrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            // No response.
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("Fail! No response!");
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                //Check if it was also the wrong key.
                if (IsCorrectKey((TippingPointTrial)t))
                {
                    r.keyCorrect = true;
                }
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                //Check if correct key was pressed
                if (IsCorrectKey((TippingPointTrial)t))
                {
                    // Responded correctly.
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    r.success    = true;
                    r.keyCorrect = true;
                    r.accuracy   = GetAccuracy(t, time);
                    GUILog.Log("Success! responseTime = {0}", time);
                }
                else
                {
                    //With wrong key.
                    DisplayFeedback(RESPONSE_KEY, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Wrong Key Pressed! key pressed = " + keyPressed, time);
                }
            }
            else
            {
                // Responded too slow.
                DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Slow response! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
コード例 #7
0
 /// <summary>
 /// Checks that all the folders we define here are accessible, and if not
 /// creates them. If something goes wrong returns False.
 /// </summary>
 public static bool InitializeFolders()
 {
     foreach (string path in FoldersList)
     {
         if (!CheckAndCreateDir(path))
         {
             GUILog.Error("Unable to create folder {0}", path);
             return(false);
         }
     }
     GUILog.Log("Folders initialized for {0}", DashboardPath);
     return(true);
 }
コード例 #8
0
    /// <summary>
    /// Displays the Stimulus for a specified duration.
    /// During that duration the player needs to respond as quickly as possible.
    /// </summary>
    protected virtual IEnumerator DisplayStimulus(Trial t)
    {
        GameObject stim = stimulus;

        stim.SetActive(false);

        yield return(new WaitForSeconds(t.delay));

        StartInput();

        ReactTrialRed RTR = t as ReactTrialRed;

        // Set color of the stimulus as given in the trial
        if (RTR.isRed)
        {
            stim.GetComponent <Image>().color = Color.red;
            currentColorIsRed = true;
        }

        if (!RTR.isRed)
        {
            stim.GetComponent <Image>().color = Color.white;
            currentColorIsRed = false;
        }

        // Set position of the stimulus as given in the trial.
        if (RTR.isRandomPos)
        {
            StimRandomPos.x = GetRandomX(RTR.minX, RTR.maxX);
            StimRandomPos.y = GetRandomY(RTR.minY, RTR.maxY);

            stim.GetComponent <RectTransform>().anchoredPosition = StimRandomPos;
            GUILog.Log("Current stimulus position: " + stim.GetComponent <RectTransform>().position.ToString());
        }
        else
        {
            StimRandomPos.x = RTR.fixedX;
            StimRandomPos.y = RTR.fixedY;
            stim.GetComponent <RectTransform>().anchoredPosition = StimRandomPos;
            GUILog.Log("Current stimulus position: " + stim.GetComponent <RectTransform>().position.ToString());
        }


        stim.SetActive(true);
        yield return(new WaitForSeconds(((ReactTrialRed)t).duration));

        stim.SetActive(false);
        EndInput();

        yield break;
    }
コード例 #9
0
 /// <summary>
 /// Called when the game session has started.
 /// </summary>
 public virtual GameBase StartSession(TextAsset sessionFile)
 {
     // Create and load a SessionData object to give to the active game.
     sessionData = new SessionData();
     if (XMLUtil.LoadSessionData(sessionFile, ref sessionData))
     {
         GUILog.Log("Game {0} starting Session {1}", this.gameObject.name, sessionFile.name);
         OnStart();
     }
     else
     {
         GUILog.Error("Game {0} failed to load session file {1}", this.gameObject.name, sessionFile.name);
     }
     return(this);
 }
コード例 #10
0
    void OnApplicationQuit()
    {
        if (activeGame == null)
        {
            return;
        }
        SessionData sData = activeGame.SessionData;

        // Write the log file for any sessions that haven't been completed but have started.
        if (!sData.outputWritten && sData.SessionStarted)
        {
            XMLUtil.WriteSessionLog(ref sData);
        }
        GUILog.SaveLog();
    }
コード例 #11
0
ファイル: XMLUtil.cs プロジェクト: uday721/UnityExercise
 /// <summary>
 /// Parses a GameType enum attribute.
 /// And assigns it to the referenced variable.
 /// Does nothing if the attribute fails to parse.
 /// </summary>
 public static bool ParseAttribute(XmlNode n, string att, ref GameType val, bool optional = false)
 {
     try
     {
         val = (GameType)Enum.Parse(typeof(GameType), n.Attributes[att].Value, true);
         return(true);
     }
     catch
     {
         if (!optional)
         {
             GUILog.Error("Could not parse attribute {1} under node {0}", n.Name, att);
         }
         return(false);
     }
 }
コード例 #12
0
    /// <summary>
    /// Checks to see if the given path directory exists, and if not tries to create. If all goes
    /// well returns true. If something goes wrong, false is returned.
    /// </summary>
    public static bool CheckAndCreateDir(string dirPath)
    {
        DirectoryInfo dir = new DirectoryInfo(dirPath);

        if (!dir.Exists)
        {
            try
            {
                Directory.CreateDirectory(dir.FullName);
            }
            catch (Exception e)
            {
                GUILog.Error("Couldn't create directory {0}, Exception: {1}", dir.FullName, e.Message.ToString());
                return(false);
            }
        }
        return(true);
    }
コード例 #13
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0 && !t.isRed)
        {
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("FAIL! No Response");
        }
        else if (time == 0 && t.isRed)
        {
            r.success = true;
            DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
            GUILog.Log("Correct! responseTime = {0}", time);
        }
        else
        {
            if (IsGuessResponse(time))
            {
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time) && !t.isRed)
            {
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! responseTime = {0}", time);
            }
            else if (IsValidResponse(time) && t.isRed)
            {
                DisplayFeedback(RESPONSE_INCORRECT, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Incorrect response! responseTime = {0}", time);
            }
            else
            {
                DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Slow response! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
コード例 #14
0
ファイル: XMLUtil.cs プロジェクト: uday721/UnityExercise
    /// <summary>
    /// Parses all the Trials attributes and Trial elements.
    /// </summary>
    private static void ParseSessionTrials(XmlNode trialsNode, ref SessionData sData)
    {
        if (trialsNode == null)
        {
            GUILog.Error("Session {0}, Trials element not found.", sData.fileName);
            return;
        }

        sData.trials = new List <Trial>();
        foreach (XmlNode n in trialsNode.ChildNodes)
        {
            switch (n.Name)
            {
            case ELEM_TRIAL:
                ParseTrial(n as XmlElement, ref sData);
                break;
            }
        }
        GUILog.Log("Found {0} Trials defined in {1}", sData.trials.Count, sData.fileName);
    }
コード例 #15
0
ファイル: React2.cs プロジェクト: kyung01/UnityExercise
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        if (!t.isRed)
        {
            //Stimulus is not red. The new implementation is not required.
            base.AddResult(t, time);
            return;
        }
        //Stimulus is red. New implementation is required.
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        r.isRed        = true;
        if (time == 0)
        {
            // No response.
            DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
            r.success  = true;
            r.accuracy = 1;
            GUILog.Log("Success! No response!");
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else
            {
                // Responded too slow.
                DisplayFeedback(RESPONSE_WRONG, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Response detected! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
コード例 #16
0
ファイル: React.cs プロジェクト: eja4296/UnityExercise
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            // No response.
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("Fail! No response!");
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                // Responded correctly.
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! responseTime = {0}", time);
            }
            else
            {
                // Responded too slow.
                DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Slow response! responseTime = {0}", time);
            }
        }
        sessionData.results.Add(r);
    }
コード例 #17
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            // If no response, check if stimulus has valid color or not (Valid color = white, not valid color = red).
            if (IsValidStimulusColor(t))
            {
                GUILog.Log("Fail! No response!");
                DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            }
            else
            {
                GUILog.Log("Success! Ignored the red square!");
                DisplayFeedback(RESPONSE_RED_IGNORED, RESPONSE_COLOR_GOOD);
                r.success = true;
            }
        }
        else
        {
            if (IsGuessResponse(time) && IsValidStimulusColor(t))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                if (IsValidStimulusColor(t))
                {
                    // Responded correctly.
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    r.success  = true;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Success! responseTime = {0}", time);
                }
                else
                {
                    DisplayFeedback(RESPONSE_RED, RESPONSE_COLOR_BAD);
                    r.success  = false;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Fail! Responded to wrong color");
                }
            }
            else
            {
                // Responded too slow.
                if (IsValidStimulusColor(t))
                {
                    DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Slow response! responseTime = {0}", time);
                }
                else
                {
                    DisplayFeedback(RESPONSE_RED, RESPONSE_COLOR_BAD);
                    r.success  = false;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Fail! Responded to wrong color");
                }
            }
        }

        // Preparing and writing data in result
        if (currentColorIsRed)
        {
            r.isRed = true;
        }
        else
        {
            r.isRed = false;
        }
        r.positionX = (int)StimRandomPos.x;
        r.positionY = (int)StimRandomPos.y;
        sessionData.results.Add(r);
    }
コード例 #18
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        // stim isRed and times out
        // Result: Correct response
        if (time == 0 && t.isRed)
        {
            DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
            GUILog.Log("Success! Didn't click red! responseTime = {0}", time);
            sessionData.results.Add(r);
            return;
        }
        // If not red and times out
        // Result: Fail. No response
        if (time == 0 && !t.isRed)
        {
            // No response.
            DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
            GUILog.Log("Fail! No response!");
        }
        else
        {
            // Player Guesses
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }

            // Player responds in time and it is not red
            else if (IsValidResponse(time) && !t.isRed)
            {
                // Responded correctly.
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! responseTime = {0}", time);
            }

            // player responds and it is red
            else if (IsValidResponse(time) && t.isRed)
            {
                // Responded correctly but wrong color
                DisplayFeedback(RESPONSE_INCORRECT, RESPONSE_COLOR_BAD);
                r.success  = false;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Fail! responseTime = {0}", time);
            }

            // No responce
            else
            {
                // Catch in case it is red and gets to here
                if (t.isRed)
                {
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    GUILog.Log("Success! Didn't click red! responseTime = {0}", time);
                }
                // No response and fail
                else
                {
                    DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Slow response! responseTime = {0}", time);
                }
            }
        }
        sessionData.results.Add(r);
    }
コード例 #19
0
    /// <summary>
    /// Adds a result to the SessionData for the given trial.
    /// </summary>
    protected override void AddResult(Trial t, float time)
    {
        TrialResult r = new TrialResult(t);

        r.responseTime = time;
        if (time == 0)
        {
            if (((AzzaranoTrial)t).red == "false" && ball == false)
            {
                // No response.
                DisplayFeedback(RESPONSE_TIMEOUT, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! No response!");
            }
            else if (((AzzaranoTrial)t).red == "false" && ball == true)
            {
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! Didn't respond to BALL.");
                score += 1;
            }
            else
            {
                // Responded correctly.
                DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                r.success  = true;
                r.accuracy = GetAccuracy(t, time);
                GUILog.Log("Success! Didn't respond to RED.");
                score += 1;
            }
        }
        else
        {
            if (IsGuessResponse(time))
            {
                // Responded before the guess limit, aka guessed.
                DisplayFeedback(RESPONSE_GUESS, RESPONSE_COLOR_BAD);
                GUILog.Log("Fail! Guess response! responseTime = {0}", time);
            }
            else if (IsValidResponse(time))
            {
                if (((AzzaranoTrial)t).red == "false" && ball == false)
                {
                    // Responded correctly.
                    DisplayFeedback(RESPONSE_CORRECT, RESPONSE_COLOR_GOOD);
                    r.success  = true;
                    r.accuracy = GetAccuracy(t, time);
                    GUILog.Log("Success! responseTime = {0}", time);
                    score += 1;
                }
                else if (((AzzaranoTrial)t).red == "false" && ball == true)
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITBALL, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to BALL");
                }
                else
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITRED, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to RED");
                }
            }
            else
            {
                if (((AzzaranoTrial)t).red == "false" && ball == false)
                {
                    // Responded too slow.
                    DisplayFeedback(RESPONSE_SLOW, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Slow response! responseTime = {0}", time);
                }
                else if (((AzzaranoTrial)t).red == "false" && ball == true)
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITBALL, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to BALL");
                }
                else
                {
                    // Responded incorrectly.
                    DisplayFeedback(RESPONSE_HITRED, RESPONSE_COLOR_BAD);
                    GUILog.Log("Fail! Not supposed to respond to RED");
                }
            }
        }
        sessionData.results.Add(r);
    }
コード例 #20
0
 // Use this for initialization
 void Start()
 {
     instance = this;
 }