コード例 #1
0
ファイル: SetManager.cs プロジェクト: Makiah/IntelliQuizlet
    public void LoadQAPairs(string path)
    {
        try
        {
            string line;
            // Create a new StreamReader, tell it which file to read and what encoding the file
            // was saved as
            StreamReader theReader = new StreamReader(path, Encoding.Default);
            // Immediately clean up the reader after this block of code is done.
            // You generally use the "using" statement for potentially memory-intensive objects
            // instead of relying on garbage collection.
            // (Do not confuse this with the using directive for namespace at the
            // beginning of a class!)
            string titleText = "";
            using (theReader)
            {
                //For some reason  a new string variable must be created.
                titleText = theReader.ReadLine();                 //There must be a line no matter what.

                // While there's lines left in the text file, do this:
                do
                {
                    try
                    {
                        line = theReader.ReadLine();
                    }
                    catch (System.Exception e)
                    {
                        line = null;
                    }

                    if (line != null)
                    {
                        // Do whatever you need to do with the text line, it's a string now
                        // In this example, I split it into arguments based on comma
                        // deliniators, then send that array to DoStuff()
                        if (line.Length > 1 && line.IndexOf("~") != -1)
                        {
                            string[] entries = line.Split('~');
                            string   question = entries[0], answer = entries[1];
                            if (!(question.Equals("") && answer.Equals("")))
                            {
                                QAPair.Create(question, answer);
                            }
                        }
                    }
                } while (line != null);
                // Done reading, close the reader and return true to broadcast success
                theReader.Close();
            }

            title.text = titleText;
        }
        // If anything broke in the try block, we throw an exception with information
        // on what didn't work
        catch (System.Exception e)
        {
            Debug.LogError("Fatal error in Reading File!");
        }
    }
コード例 #2
0
 void CreateNewTermIfSceneAppropriate()
 {
     if (SceneManager.GetActiveScene().buildIndex == 1)
     {
         QAPair     newTerm    = QAPair.Create("", "");
         InputField inputfield = newTerm.transform.GetChild(0).GetComponent <InputField> ();
         inputfield.OnPointerClick(new PointerEventData(system));                //if it's an input field, also set the text caret
         system.SetSelectedGameObject(newTerm.GetComponentInChildren <Selectable> ().gameObject, new BaseEventData(system));
     }
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab) && QuizToggle.instance.InQuizMode == false)
        {
            GameObject current = system.currentSelectedGameObject;

            if (current != null)
            {
                InputField currentInputField = current.GetComponent <InputField> ();
                if (currentInputField != null)
                {
                    InputField newInputField = null;
                    if (currentInputField.gameObject.name.Equals("Question"))
                    {
                        newInputField = currentInputField.gameObject.transform.parent.GetChild(1).GetComponent <InputField> ();
                    }
                    else if (currentInputField.name.Equals("Answer"))
                    {
                        int qaPairChildIndex      = currentInputField.transform.parent.GetSiblingIndex();
                        int totalNumberOfChildren = currentInputField.transform.parent.parent.childCount - 1;
                        if (qaPairChildIndex < totalNumberOfChildren - 1)
                        {
                            newInputField = currentInputField.gameObject.transform.parent.parent.GetChild(qaPairChildIndex + 1).Find("Question").GetComponent <InputField> ();
                        }
                        else
                        {
                            newInputField = QAPair.Create("", "").transform.Find("Question").GetComponent <InputField> ();
                        }
                    }

                    if (newInputField != null)
                    {
                        system.SetSelectedGameObject(newInputField.gameObject, new BaseEventData(system));
                        newInputField.OnPointerClick(new PointerEventData(system));

                        //Find the tap in the input field that was last selected.
                        int    indexOfTab = currentInputField.text.IndexOf("\t");
                        string newText    = "";
                        if (indexOfTab > 0)                         //Check to make sure that is not -1, and greater than 0 in one go.
                        {
                            newText = currentInputField.text.Substring(0, indexOfTab);
                            if (indexOfTab < currentInputField.text.Length - 1)
                            {
                                newText = newText + currentInputField.text.Substring(indexOfTab + 1);
                            }
                        }

                        currentInputField.text = newText;
                    }
                }
            }
        }
    }
コード例 #4
0
ファイル: SetManager.cs プロジェクト: Makiah/IntelliQuizlet
 public void AddEmptyQAPair()
 {
     QAPair.Create("", "");
 }