private void Serialization()
        {
            for (int cnt = 0; cnt < m_datas.Length; cnt++)
            {
                TestIOCsvConfigData m_tempData = new TestIOCsvConfigData();

                if (!int.TryParse(m_datas[cnt][0], out m_tempData.Id))
                {
                    m_tempData.Id = 0;
                }

                m_tempData.Name = m_datas[cnt][1];

                if (!int.TryParse(m_datas[cnt][2], out m_tempData.Age))
                {
                    m_tempData.Age = 0;
                }


                if (!float.TryParse(m_datas[cnt][3], out m_tempData.Score))
                {
                    m_tempData.Score = 0.0f;
                }

                m_tempData.Designation = CSVConverter.ConvertToArray <string>(m_datas[cnt][4]);
                if (!dicData.ContainsKey(m_datas[cnt][0]))
                {
                    dicData.Add(m_datas[cnt][0], m_tempData);
                    listData.Add(m_tempData);
                }
            }
        }
        public void Load()
        {
            configDatas = new TestIOCsvConfigDatas();
            dicData.Clear();
            listData.Clear();

            StreamReader streamReader = null;

            if (File.Exists(DataPath()))
            {
                streamReader = File.OpenText(DataPath());
            }
            else
            {
                Debug.LogError(GetType() + "/Load() load config eroor!  path:" + DataPath());
                return;
            }

            string str = streamReader.ReadToEnd();

            streamReader.Close();
            streamReader.Dispose();

            string textData = StringEncrypt.DecryptDES(str);

            m_datas = CSVConverter.SerializeCSVData(textData);
            Serialization();
        }
Beispiel #3
0
        /// <summary>
        /// 获取CSV的序列化数据
        /// </summary>
        /// <param name="textAsset">text数据</param>
        /// <returns></returns>
        private static string GetCsvSerialize(TextAsset textAsset)
        {
            string[] csvParameter = CSVConverter.SerializeCSVParameter(textAsset);

            int keyCount = csvParameter.Length;

            string csvSerialize = string.Empty;

            for (int cnt = 0; cnt < keyCount; cnt++)
            {
                string[] attributes = csvParameter[cnt].Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);

                if (attributes[0] == "string")
                {
                    csvSerialize += string.Format("m_tempData.{0} = m_datas[cnt][{1}];", attributes[1], cnt);
                }
                else if (attributes[0] == "bool")
                {
                    csvSerialize += GetCsvSerialize(attributes, cnt, "0");
                }
                else if (attributes[0] == "int")
                {
                    csvSerialize += GetCsvSerialize(attributes, cnt, "0");
                }
                else if (attributes[0] == "float")
                {
                    csvSerialize += GetCsvSerialize(attributes, cnt, "0.0f");
                }
                else if (attributes[0] == "string[]")
                {
                    csvSerialize += string.Format("m_tempData.{0} = CSVConverter.ConvertToArray<string>(m_datas[cnt][{1}]);",
                                                  attributes[1], cnt);
                }
                else if (attributes[0] == "bool[]")
                {
                    csvSerialize += string.Format("m_tempData.{0} = CSVConverter.ConvertToArray<bool>(m_datas[cnt][{1}]);",
                                                  attributes[1], cnt);
                }
                else if (attributes[0] == "int[]")
                {
                    csvSerialize += string.Format("m_tempData.{0} = CSVConverter.ConvertToArray<int>(m_datas[cnt][{1}]);",
                                                  attributes[1], cnt);
                }
                else if (attributes[0] == "float[]")
                {
                    csvSerialize += string.Format("m_tempData.{0} = CSVConverter.ConvertToArray<float>(m_datas[cnt][{1}]);",
                                                  attributes[1], cnt);
                }

                if (cnt != keyCount - 1)
                {
                    csvSerialize += "\n";
                    csvSerialize += "\t\t";
                }
            }

            return(csvSerialize);
        }
 private void Serialization()
 {
     for (int cnt = 0; cnt < m_datas.Length; cnt++)
     {
         LanguagConfigData m_tempData = new LanguagConfigData();
         m_tempData.Id    = m_datas[cnt][0];
         m_tempData.En    = m_datas[cnt][1];
         m_tempData.Cn    = m_datas[cnt][2];
         m_tempData.Scene = CSVConverter.ConvertToArray <string>(m_datas[cnt][3]);
         if (!dicData.ContainsKey(m_datas[cnt][0]))
         {
             dicData.Add(m_datas[cnt][0], m_tempData);
             listData.Add(m_tempData);
         }
     }
 }
Beispiel #5
0
        public void Load()
        {
            dicData.Clear();
            listData.Clear();

            TextAsset textAsset = Resources.Load <TextAsset>(DataPath());
            string    str       = textAsset.text;

            if (string.IsNullOrEmpty(str))
            {
                Debug.LogError(GetType() + "/Load()/ load config error! path:" + DataPath());
            }

            string textData = StringEncrypt.DecryptDES(str);

            m_datas = CSVConverter.SerializeCSVData(textData);
            Serialization();
        }
Beispiel #6
0
        /// <summary>
        /// 获取自动生成类的参数
        /// </summary>
        /// <param name="textAsset">text数据</param>
        /// <returns></returns>
        private static string GetClassParameters(TextAsset textAsset)
        {
            string[] csvParameter = CSVConverter.SerializeCSVParameter(textAsset);
            int      keyCount     = csvParameter.Length;

            string classParameters = string.Empty;

            for (int cnt = 0; cnt < keyCount; cnt++)
            {
                string[] attributes = csvParameter[cnt].Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);
                classParameters += string.Format("public {0} {1};", attributes[0], attributes[1]);

                if (cnt != keyCount - 1)
                {
                    classParameters += "\n";
                    classParameters += "\t\t";
                }
            }

            return(classParameters);
        }