コード例 #1
0
    /// <summary>
    /// 开始时加载题库列表
    /// </summary>
    void Start()
    {
        if (selectClassId != string.Empty)
        {
            if (GlobalVariable.practiceState == PracticeState.classes)
            {
                initClassInfo();
                GlobalVariable.bankName = "classId_" + selectClassId + "_QAXML";
                Debug.Log(GlobalVariable.bankName);
            }
            else if (GlobalVariable.practiceState == PracticeState.errors)
            {
                GlobalVariable.bankName = "classId_" + selectClassId + "_Error_QAXML";
                Debug.Log(GlobalVariable.bankName);
            }
            this.transform.GetComponent <StartPanel>().changeBankName();
        }
        else
        {
            //正常加载QA系统 , 初始化题库旋转列表
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc = Vesal_DirFiles.loadXml(currentQaPath, GlobalVariable.bankName + ".xml");

            if (xmlDoc == null)
            {
                Debug.Log("BankScriControl missing Xml");
                return;
            }
            string      xPath = "//banks";
            XmlNodeList node  = xmlDoc.SelectSingleNode(xPath).ChildNodes;

            foreach (XmlElement nodeElement in node)
            {
                InstantiateList(nodeElement["bankName"].InnerText,
                                nodeElement["tips"].InnerText,
                                nodeElement["fileName"].InnerText);
            }
            //获得班级题库
            // StartCoroutine(getClassInfo());
        }
    }
コード例 #2
0
ファイル: StartPanel.cs プロジェクト: RelinkaKing/UnityPC
    /// <summary>
    /// 选择题库
    /// </summary>
    public bool initLibs()
    {
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc = Vesal_DirFiles.loadXml(BankScriControl.currentQaPath, GlobalVariable.bankName + ".xml");
        if (GlobalVariable.bankName.StartsWith("classId"))
        {
            inputFieldParent.SetActive(false);
        }
        else
        {
            inputFieldParent.SetActive(true);
        }

        if (xmlDoc == null)
        {
            Debug.Log("startPanel missing Xml");
            return(false);
        }
        string      xPath = "//library";
        XmlNodeList node  = xmlDoc.SelectNodes(xPath);
        string      tmpLibName;

        Toggle t;

        GameObject g;
        bool       flag = true;

        foreach (XmlElement nodeElement in node)
        {
            tmpLibName = nodeElement.GetAttribute("name");
            int n = xmlDoc.SelectNodes("//library[@name='" + tmpLibName + "']/Question").Count;
            if (n == 0)
            {
                continue;
            }
            g = GameObject.Instantiate(originObject, parentTransForm);
            g.SetActive(true);
            g.GetComponent <RectTransform>().anchoredPosition = new Vector2(g.GetComponent <RectTransform>().anchoredPosition.x, originObject.GetComponent <RectTransform>().anchoredPosition.y);
            g.GetComponentInChildren <Text>().text            = tmpLibName;
            if (GlobalVariable.practiceState == PracticeState.classes)
            {
                XmlElement xm = (XmlElement)xmlDoc.SelectSingleNode("//library[@name='" + tmpLibName + "']");
                if (xm.HasAttribute("startTime") && xm.HasAttribute("closeTime"))
                {
                    g.transform.Find("Time").GetComponent <Text>().text = (xm.GetAttribute("startTime") + " ~ " + xm.GetAttribute("closeTime")).Replace(".0", "");
                }
                else
                {
                    g.transform.Find("Time").GetComponent <Text>().text = "";
                }
            }
            t       = g.GetComponent <Toggle>();
            t.group = tg;
            //取消难度切换
            //g.name = nodeElement.GetAttribute("minGrade") + "_" + nodeElement.GetAttribute("maxGrade");
            if (flag)
            {
                t.isOn = true;
                //changeMaxGrade(g.name);
                if (GlobalVariable.practiceState == PracticeState.classes)
                {
                    ScenceData.testPaperTimeInfo = g.transform.Find("Time").GetComponent <Text>().text;
                }
                flag = false;
            }
            else
            {
                t.isOn = false;
            }
            UIEventListener btnListener = t.gameObject.AddComponent <UIEventListener>();
            btnListener.OnClickEvent += delegate(GameObject gb)
            {
                this.OnToggleClick(gb);
            };
        }
        //占位元素,防止列表被下方挡住
        GameObject tmpGo;

        for (int i = 0; i < 2; i++)
        {
            tmpGo = GameObject.Instantiate(placeholderObject, parentTransForm);
            tmpGo.SetActive(true);
        }


        Toggle[] tmp = tg.GetComponentsInChildren <Toggle>();
        for (int i = 0; i < tmp.Length; i++)
        {
            t = tmp[i];
            if (t.isOn)
            {
                checkToggle            = t.gameObject;
                GlobalVariable.libName = t.GetComponentInChildren <Text>().text;
            }
        }
        return(true);
    }
コード例 #3
0
ファイル: StartPanel.cs プロジェクト: RelinkaKing/UnityPC
    /// <summary>
    /// 创建答题列表
    /// </summary>
    /// <param name="n">列表题数</param>
    /// <param name="errorQts">上次答错题集合</param>
    public void randomQuestion(int n)
    {
        bool          tmpFlag    = true;
        List <string> loadedSign = new List <string>();
        XmlDocument   xmlDoc     = new XmlDocument();

        xmlDoc = Vesal_DirFiles.loadXml(BankScriControl.currentQaPath, GlobalVariable.bankName + ".xml");
        //#if UNITY_EDITOR
        //        n = 1000;
        //        tmpFlag = false;
        //        if (editXmlDoc == null)
        //        {
        //            editXmlDoc = xmlDoc;
        //        }
        //#endif
        Debug.Log("------" + GlobalVariable.bankName);
        Debug.Log("------" + GlobalVariable.libName);
        Question.LibId = ((XmlElement)xmlDoc.SelectSingleNode("//library[@name='" + GlobalVariable.libName + "']")).GetAttribute("id");
        Debug.Log(Question.LibId);
        //试卷答全部题
        if (GlobalVariable.bankName.StartsWith("classId"))
        {
            n = xmlDoc.SelectNodes("//library[@name='" + GlobalVariable.libName + "']/Question").Count;
            Debug.Log("=========总题数" + n);
            GlobalVariable.questionCount = n;
        }



        List <string>   idLists  = QaDao.instance.getTopErrorQaId(Mathf.FloorToInt(n * GlobalVariable.errorReappear), GlobalVariable.bankName, GlobalVariable.libName);
        List <Question> errorQts = new List <Question>();
        string          tmpStr;
        string          xPath;
        XmlElement      xe;
        Question        tmpQues;

        Debug.Log(idLists.Count);
        if (tmpFlag)
        {
            for (int m = 0; m < idLists.Count; m++)
            {
                tmpStr = idLists[m];
                xPath  = "//library[@name='" + GlobalVariable.libName + "']/Question[grade <=" + CurrentMaxGrade + " and @qid = \"" + tmpStr + "\"]";
                xe     = (XmlElement)xmlDoc.SelectSingleNode(xPath);
                Debug.Log(tmpStr);
                if (xe != null)
                {
                    tmpQues = new Question(xe);
                    //                    if (tmpQues.modelName != "null") {
                    //                        ScenceData.loadModel(tmpQues.abName, tmpQues.modelName, tmpQues.questionType == Question.QuestionType.thumbtack?true:false);
                    //                    }
                    //                    if (tmpQues.questionType == Question.QuestionType.thumbtack) {
                    ////                        initThumbtack(ref tmpQues, ref loadedSign);
                    //                    }
                    errorQts.Add(tmpQues);
                }
            }
        }
        Debug.Log(loadedSign.Count);
        // hasModels = false;
        //int max = int.Parse(maxDropDown.transform.Find("maxLabel").GetComponent<Text>().text);
        xPath = "//library[@name='" + GlobalVariable.libName + "']/Question[grade <=" + CurrentMaxGrade + "]";
        //and grade >= "+currentMinGrade+"]";
        //Question[grade<4 and grade>2]
        ////Question[contains("23",grade)]
        if (xmlDoc == null)
        {
            return;
        }
        //SelectSingleNode(xPath).ChildNodes;
        XmlNodeList node = xmlDoc.SelectNodes(xPath);

        if (n > node.Count)
        {
            n = node.Count;
        }
        Debug.Log(n);
        ScenceData.questions = new Question[n];
        int i = 0;

        //添加错题并记录错题里问题排重
        List <string> ques = new List <string>();

        if (tmpFlag)
        {
            if (errorQts.Count != 0)
            {
                while (i < errorQts.Count)
                {
                    ScenceData.questions[i] = errorQts[i];
                    //if (ScenceData.questions[i].modelName != null && ScenceData.questions[i].modelName != "null")
                    //{
                    //    hasModels = true;
                    //}
                    ques.Add(errorQts[i].qid);
                    i++;
                }
            }
        }

        if (i != n)
        {
            int tmpIndex = 0;

            Question[] tmpQs;
            if (errorQts != null && errorQts.Count != 0)
            {
                Debug.Log(node.Count + "--" + errorQts.Count);
                tmpQs = new Question[node.Count - errorQts.Count];
            }
            else
            {
                tmpQs = new Question[node.Count];
            }
            Debug.Log(tmpQs.Length);
            foreach (XmlElement nodeList in node)
            {
                if (nodeList["q"] != null && !ques.Contains(nodeList.GetAttribute("qid")))
                {
                    tmpQs[tmpIndex] = new Question(nodeList);
                    tmpIndex++;
                }
            }
            if (tmpFlag)
            {
                if (tmpQs.Length > 2)
                {
                    //打乱数组中元素顺序
                    int y; Question tmp;
                    for (int m = 0; m < tmpQs.Length; m++)
                    {
                        do
                        {
                            y = UnityEngine.Random.Range(0, tmpQs.Length);
                        } while (y == m);
                        tmp      = tmpQs[m];
                        tmpQs[m] = tmpQs[y];
                        tmpQs[y] = tmp;
                    }
                }
            }
            tmpIndex = 0;

            while (i <= n - 1)
            {
                //Debug.Log(i+"_"+tmpIndex+ "--tmpQs-"+ tmpQs.Length);
                ScenceData.questions[i] = tmpQs[tmpIndex];
                tmpIndex++;
                if (ScenceData.questions[i] == null)
                {
                    break;
                }
                //                if (ScenceData.questions[i].modelName != null && ScenceData.questions[i].modelName != "null")
                //                {
                //                    //hasModels = true;
                //                    //ScenceData.loadModel(ScenceData.questions[i].abName, ScenceData.questions[i].modelName, ScenceData.questions[i].questionType == Question.QuestionType.thumbtack ? true : false);
                //                    if (ScenceData.questions[i].questionType == Question.QuestionType.thumbtack) {

                ////                        initThumbtack(ref ScenceData.questions[i],ref loadedSign);
                //                    }
                //                }
                i++;
            }
        }
        //初始化本波次错题记录
        ScenceData.errorQts = new List <Question>();
        Debug.Log("end RandomQuestion");
    }