Exemple #1
0
    public void LoadAddressList()
    {
        Debug.Log("LoadAddressList");
        //更新文件列表
        fileList.Clear();
        XmlDocument xmlDoc = new XmlDocument();
        var         path   = Application.persistentDataPath + Conf.xmlFileName;

        xmlDoc.Load(path);
        if (xmlDoc != null)
        {
            var rootNode        = xmlDoc.SelectSingleNode("root");
            var fileAddressNode = rootNode.SelectSingleNode("fileAddress");
            var nodes           = fileAddressNode.ChildNodes;
            foreach (var node in nodes)
            {
                XmlNode n = (XmlNode)node;
                fileList.Add(n.InnerText);
            }
            ShowChoseDialog();
            var newVerStr = rootNode.SelectSingleNode("appVersion");
            if (newVerStr != null && newVerStr.InnerText != Application.version)
            {
                var appUrl = rootNode.SelectSingleNode("downloadApp");
                if (appUrl != null)
                {
                    StartCoroutine(gotoDownloadNewVersion(appUrl.InnerText));
                }
            }
        }
        else
        {
            UIToast.ShowTips("读取配置文件失败!", 2.0f);
        }
    }
Exemple #2
0
    public void LoadVocLibAndStartGame(int sceneIndex)
    {
        string vocFileName = PlayerPrefs.GetString(Conf.missionVocFileKey);
        string filePath    = Application.persistentDataPath + @"/" + vocFileName + ".txt";

        if (File.Exists(filePath))
        {
            string xmlFilePath = Application.persistentDataPath + @"/" +
                                 vocFileName + ".xml";
            if (File.Exists(xmlFilePath))
            {
                //如果已经解析过词库,直接加载xml
                Debug.Log("加载xml词库,开始游戏");
                SceneManager.LoadScene(sceneIndex);
            }
            else
            {
                //如果词库未解析,则解析词库
                Debug.Log("文件不存在:" + xmlFilePath);
                StartCoroutine(RegexMatch(vocFileName, delegate()
                {
                    LoadVocLibAndStartGame(sceneIndex);
                }));
            }
        }
        else
        {
            UIToast.ShowTips("词库不存在,请先设置词库", 2.0f);
        }
    }
Exemple #3
0
    private IEnumerator DownloadProgress(string path, Button[] bts)
    {
        string progress = string.Empty;

        while (!net.isDone)
        {
            progress = net.progress * 100.0 + "%";
            //.Log("进度:" + progress);
            yield return(1);
        }
        if (net.error != null)
        {
            UIToast.ShowTips("下载出错:" + net.error, 2.0f);
        }
        else
        {
            progress = "100%";
            if (null != net.text)
            {
                File.WriteAllText(path, net.text, System.Text.Encoding.UTF8);
                UIToast.ShowTips("下载完成:" + path, 2.0f);
                bts[0].interactable = false;
                bts[1].interactable = true;
                bts[2].interactable = true;
            }
        }
        yield return(1);
    }
Exemple #4
0
    public void LoadXmlFile()
    {
        //如果没有网络 判断本地是否存在配置文件 如果有则去读本地文件
        var confFile = Application.persistentDataPath + Conf.xmlFileName;

        if (File.Exists(confFile))
        {
            string confContent = File.ReadAllText(confFile);
            //校验本地配置文件是否有效
            if (confContent.Length < 10)
            {
                Debug.Log("删除无效配置文件");
                File.Delete(confFile);
            }
        }
        if (File.Exists(confFile))
        {
            LoadAddressList();
        }
        else
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                UIToast.ShowTips("无法连接网络,请检查网络", 2.0f);
            }
            else
            {
                //如果有网络更新xml
                UpdateAndShowVocLibList();
            }
        }
    }
Exemple #5
0
    IEnumerator UpdateXmlFile(string address)
    {
        UIToast.ShowTips("正在更新词库列表...", 2.0f);
        net = new WWW(address);
        yield return(net);

        //下载xml完成后将文件写入
        while (!net.isDone)
        {
            yield return(0);
        }
        //如果本地已存在xml 则检测xml版本
        if (File.Exists(Application.persistentDataPath + Conf.xmlFileName))
        {
            if (isNewVersion(net.text))
            {
                //有新版本
                File.WriteAllText(Application.persistentDataPath + Conf.xmlFileName, net.text);
            }
        }
        else
        {
            File.WriteAllText(Application.persistentDataPath + Conf.xmlFileName, net.text);
        }

        LoadAddressList();
    }
Exemple #6
0
    private IEnumerator gotoDownloadNewVersion(string url)
    {
        UIToast.ShowTips("发现新版本", 3f);
        yield return(new WaitForSeconds(3f));

        Application.OpenURL(url);
    }
Exemple #7
0
    IEnumerator RegexMatch(string file, UnityEngine.Events.UnityAction callBack)
    {
        string filePath = Application.persistentDataPath + "/" + file + ".txt";

        filePath = Regex.Replace(filePath, "/", @"\");
        var www = new WWW("file://" + filePath);

        yield return(www);

        string            nText   = www.text;
        string            pattern = @"[a-zA-Z]+.*[\u4e00-\u9fa5]+|[\u4e00-\u9fa5]+.*[a-zA-Z]+";
        var               mat     = Regex.Match(nText, pattern);
        int               count   = 0;
        List <Vocabulary> vocList = new List <Vocabulary>();

        while (mat.Success)
        {
            count++;
            string str = Regex.Replace(mat.Value, @"(\[.*\])+|[\uFE30-\uFFA0]+", " ");
            str = Regex.Replace(str, @"[ \n\s*\r]+", " ");

            //匹配词性 如abj.
            var    c  = Regex.Match(str, @"[a-z]+\.");
            string en = string.Empty;
            if (c.Success)
            {
                if (c.Value.Contains("sb") || c.Value.Contains("sth"))
                {
                    en  = str.Substring(0, c.Index + c.Length);
                    str = str.Substring(c.Index + c.Length);
                }
                else
                {
                    en  = str.Substring(0, c.Index - 1);
                    str = str.Substring(c.Index);
                }
                vocList.Add(new Vocabulary(en, str));
            }
            else
            {
                var enMat = Regex.Match(str, @"[a-zA-Z]+([ -][a-zA-Z]+)*");
                str = Regex.Replace(str, @"[a-zA-Z]+([ -][a-zA-Z]+)*", "");

                vocList.Add(new Vocabulary(enMat.Value, str));
            }
            mat = mat.NextMatch();
        }
        if (vocList.Count > 0)
        {
            //SaveVocList(SortVocList(vocList), file + ".xml");
            SaveVocList(vocList, file + ".xml");
            callBack.Invoke();
        }
        else
        {
            UIToast.ShowTips("词库解析失败,请检查词库格式是否正确", 2.0f);
        }
    }
Exemple #8
0
    public void OnClickButton(GameObject item, string fileName, int id)
    {
        Button[] bts = new Button[3];
        bts[0] = item.transform.Find("Buttons/Download").GetComponent <Button>();
        bts[1] = item.transform.Find("Buttons/Refresh").GetComponent <Button>();
        bts[2] = item.transform.Find("Buttons/Delete").GetComponent <Button>();
        //Debug.Log("FileList Size:" + fileList.Count);
        switch (id)
        {
        case 0:
        {
            //如果file存在 则设置为默认词库
            if (!File.Exists(Application.persistentDataPath + @"/" + fileName))
            {
                UIToast.ShowTips("请先下载词库", 2.0f);
            }
            else
            {
                PlayerPrefs.SetString(Conf.missionVocFileKey, fileName.Substring(0, fileName.Length - 4));
                PlayerPrefs.Save();
                UIToast.ShowTips("设置默认词库:" + fileName, 2.0f);
                headerTitle.text = "任务词库" + System.Environment.NewLine + PlayerPrefs.GetString(Conf.missionVocFileKey);
            }
        }
        break;

        case 1:
            //下载按钮响应
        {
            StartCoroutine(DownloadFile(item.name,
                                        Application.persistentDataPath + @"/" + fileName,
                                        bts));
        }
        break;

        case 2:
            //更新按钮响应
        {
            StartCoroutine(DownloadFile(item.name, Application.persistentDataPath + @"/" + fileName, bts));
        }
        break;

        case 3:
            //删除按钮响应
        {
            DeleteVocabularyLib(fileName, bts);
        }
        break;

        default:
            break;
        }
    }
Exemple #9
0
 private IEnumerator DownloadFile(string address, string path, Button[] bts)
 {
     if (Application.internetReachability != NetworkReachability.NotReachable)
     {
         net = new WWW(address);
         yield return(StartCoroutine(DownloadProgress(path, bts)));
     }
     else
     {
         UIToast.ShowTips("无网络连接...", 2.0f);
         yield return(0);
     }
 }
Exemple #10
0
    public void OnButtonClick(int tag)
    {
        switch (tag)
        {
        //选择词库
        case 1:
        {
            Debug.Log("点击选择词库");
            //读取词库列表,显示在选择词库对话框
            loader.LoadXmlFile();
        }
        break;

        //游戏说明
        case 2:
        {
            Debug.Log("游戏说明");
            var textObj = loader.aboutDialog.transform.Find("Window/Scroll View/Viewport/Content/UserDefine");
            if (textObj)
            {
                var text = textObj.GetComponent <Text>();
                text.text = "Version:" + Application.version + System.Environment.NewLine +
                            System.Environment.NewLine +
                            "自定义词库存放目录:" +
                            System.Environment.NewLine + Application.persistentDataPath;
            }
            loader.aboutDialog.SetActive(true);
        }
        break;

        case 3:
        {
            loader.LoadVocLibAndStartGame(1);
        }
        break;

        case 4:
        {
            //DataLoader.Instance(this).LoadVocLibAndStartGame(2);
            UIToast.ShowTips("呼呼~ 此功能正在开发中...", 2.0f);
        }
        break;

        case 5:
            //退出
            Application.Quit();
            break;
        }
    }
Exemple #11
0
    public void DeleteVocabularyLib(string fileName, Button[] bts)
    {
        string path = Application.persistentDataPath + @"/" + fileName;

        if (File.Exists(path))
        {
            File.Delete(path);
            var vocLibName = fileName.Substring(0, fileName.Length - 4);
            path = Application.persistentDataPath + @"/" + vocLibName + ".xml";
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            path = Application.persistentDataPath + @"/" + vocLibName + "_Level.xml";
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            bts[0].interactable = true;
            bts[1].interactable = false;
            bts[2].interactable = false;
            UIToast.ShowTips("删除文件:" + fileName, 2.0f);
        }
    }