Пример #1
0
        public void LoadPackages()
        {
            if (isPackagesLoaded)
            {
                return;
            }
            bool internalTesting = false;

#if INTERNAL_TESTING
            internalTesting = true;
#endif
            if (internalTesting || Application.isEditor)
            {
                foreach (var pkgItem in DataConst.TESTING_PACKAGES)
                {
                    Package pkg       = new Package();
                    var     pkgCSVStr = CryptoUtils.Decript(Resources.Load <TextAsset>(pkgItem.packagePath).text);
                    var     pkgDict   = CSVUtils.Parse(pkgCSVStr)[0];
                    pkg.FromDict(pkgDict, pkgItem.questionPath);
                    AddPackage(pkg);
                }
            }

            foreach (var pkgItem in DataConst.BUILTIN_PACKAGES)
            {
                Package pkg       = new Package();
                var     pkgCSVStr = CryptoUtils.Decript(Resources.Load <TextAsset>(pkgItem.packagePath).text);
                var     pkgDict   = CSVUtils.Parse(pkgCSVStr)[0];
                pkg.FromDict(pkgDict, pkgItem.questionPath);
                AddPackage(pkg);
            }

#if UNITY_STANDALONE
            // DLC
            // TODO check file broken
            // string appInstallDir = Utils.GetAppInstallDir();

            // if (Directory.Exists(appInstallDir)) {
            //   Debug.Log("Load DLC at " + appInstallDir);
            //   foreach(var path in Directory.GetDirectories(appInstallDir)) {
            //     if (File.Exists(Path.Combine(path, "Package.csv"))) {
            //       Debug.Log("Loading DLC");
            //       Package pkg = new Package();
            //       string pkgCSVStr = CryptoUtils.Decript(File.ReadAllText(Path.Combine(path, "Package.csv")));
            //       var pkgDict = CSVUtils.Parse(pkgCSVStr)[0];
            //       pkg.FromDict(pkgDict, Path.Combine(path, "Question.csv"), Package.Type.CSV, Package.Source.DLC);
            //       Debug.Log("  ID: " + pkg.id);
            //       AddPackage(pkg);
            //       Debug.Log("Loaded");
            //     }
            //   }
            // }
#endif

            isPackagesLoaded = true;
            OnPackagesLoaded.Invoke();
        }
Пример #2
0
        public List <Question> Parse(Package package, object data)
        {
            var csvStr           = data.ToString();
            var questionDictList = CSVUtils.Parse(csvStr);
            var questionList     = new List <Question>();

            foreach (var row in questionDictList)
            {
                Question question = new Question();
                question.id      = row["id"].ToString();
                question.title   = row["title"].ToString();
                question.explain = row["explain"].ToString();
                question.result  = (Question.Result)Enum.Parse(typeof(Question.Result), row["result"].ToString(), true);
                question.optionA = row["A"].ToString();
                question.optionB = row["B"].ToString();
                question.optionC = row["C"].ToString();
                question.optionD = row["D"].ToString();
                questionList.Add(question);
            }
            return(questionList);
        }