//----------------------------------------------------------------------------------------------------
    // PrepareNextTrial: continue next trial/challenge
    //----------------------------------------------------------------------------------------------------
    void PrepareNextTrial()
    {
        m_intSelectedStimulusIdx = -1;

        // update CTrialList with current response
        CTrialList.Instance.UpdateReponseList (m_curResponse);

        // check end of level
        if (CTrialList.Instance.IsEndOfLevel(m_bIsAdminMode) || trialsCounter == 0)
        {
            EndTherapySession();
            return;
        }

        // fetch the next trial
        m_curResponse.Reset ();
        m_curTrial = CTrialList.Instance.GetNextTrial ();
        trialsCounter--;

        ShowAllStimuli (false);

        // show stimuli's images and play target audio
        Invoke("ShowNextTrial", 1f);
    }
Example #2
0
    //----------------------------------------------------------------------------------------------------
    // ConvertCsvToXml
    //----------------------------------------------------------------------------------------------------
    public void ConvertCsvToXml()
    {
        //string strWholeFile = System.IO.File.ReadAllText ();

        TextAsset textAsset = Resources.Load("Doc/level12-V4-csv") as TextAsset;
        string strWholeFile = textAsset.text;
            
        // split into lines
        strWholeFile = strWholeFile.Replace ('\n', '\r');
        string [] lines = strWholeFile.Split (new char[] {'\r'}, StringSplitOptions.RemoveEmptyEntries);

        // see how many rows & columns there are
        int intNumRows = lines.Length;
        int intNumCols = lines [0].Split (',').Length;

        List<CTrial> lsTrial = new List<CTrial>();

        int i = 0;
        while (i < intNumRows)
        {
            if ((i % 7) == 0)
            {
                CTrial trial = new CTrial();

                for (int j = 0; j < 7; j++)
                {
                    CStimulus stim = new CStimulus();
                    string[] line_r = lines[i].Split(',');
                    if (line_r[0] == "Target")
                        line_r[0] = "target";
                    stim.m_strType = line_r[0];
                    stim.m_strName = line_r[1];
                    stim.m_strImage = line_r[2];
                    trial.m_lsStimulus.Add(stim);
                    if (j == 0)
                    {
                        // remove .wav
                        string[] strWav = line_r[3].Split('.');
                        trial.m_strTargetAudio = strWav[0];
                    }
                    i++;
                }
                trial.m_intTargetIdx = 0;
                lsTrial.Add(trial);
                /*for (int j = 0; j < intNumCols; j++)
                {
                    stim.m_strType = line_r[j];
                }*/
            }
        }	// end while

        // save lsTrial to xml
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<?xml version='1.0' encoding='utf-8'?>" +
                    "<root>" +
                    "</root>");

        // Save the document to a file. White space is preserved (no white space).
        string strFile = Application.persistentDataPath + "/level12-V4-xml.xml";

        for (i = 0; i < lsTrial.Count; i++)
        {
            XmlElement xmlNode = doc.CreateElement("node");
            XmlAttribute attr = doc.CreateAttribute("idx");
            attr.Value = i.ToString();
            xmlNode.SetAttributeNode(attr);

            // add stimuli
            for (var j = 0; j < lsTrial[i].m_lsStimulus.Count; j++)
            {
                XmlElement xmlStimulus = doc.CreateElement("stimulus");
                XmlAttribute attr1 = doc.CreateAttribute("idx");
                attr1.Value = j.ToString();
                xmlStimulus.SetAttributeNode(attr1);

                XmlElement xmlChild = doc.CreateElement("name");
                xmlChild.InnerText = lsTrial[i].m_lsStimulus[j].m_strName;
                xmlStimulus.AppendChild(xmlChild);

                xmlChild = doc.CreateElement("image");
                xmlChild.InnerText = lsTrial[i].m_lsStimulus[j].m_strImage;
                xmlStimulus.AppendChild(xmlChild);

                xmlChild = doc.CreateElement("type");
                xmlChild.InnerText = lsTrial[i].m_lsStimulus[j].m_strType;
                xmlStimulus.AppendChild(xmlChild);

                xmlNode.AppendChild(xmlStimulus);
            }

            XmlElement xmlChild2 = doc.CreateElement("targetAudio");
            xmlChild2.InnerText = lsTrial[i].m_strTargetAudio;
            xmlNode.AppendChild(xmlChild2);

            xmlChild2 = doc.CreateElement("targetIdx");
            xmlChild2.InnerText = lsTrial[i].m_intTargetIdx.ToString();
            xmlNode.AppendChild(xmlChild2);

            doc.DocumentElement.AppendChild(xmlNode);
        }

        //doc.PreserveWhitespace = true;
        doc.Save(strFile);
    }
    //----------------------------------------------------------------------------------------------------
    // PrepareNextTrial: continue next trial/challenge
    //----------------------------------------------------------------------------------------------------
    void PrepareNextTrial()
    {
        m_pointingHand.SetActive(false);

        m_intCurIdx++;

        if (m_intCurIdx >= m_lsTrial.Count)
        {
            EndTherapySession();
            return;
        }

        // fetch the next trial
        m_curResponse.Reset ();
        m_curTrial = m_lsTrial [m_intCurIdx];  //CTrialList.Instance.GetNextTrial ();

        trialsCounter--;

        ShowAllStimuli (false);

        // show stimuli's images and play target audio
        Invoke("ShowNextTrial", 1f);
    }