Beispiel #1
0
        private static void GetCSVIndexData(string csvLine, ref CSVIndexData data)
        {
            var strArr = csvLine.Split(CSV.k_Spliter);

            for (int i = 0; i < strArr.Length; ++i)
            {
                var cur = strArr[i].Trim();
                if (cur.Equals(k_CSVHead_Value, System.StringComparison.Ordinal))
                {
                    data.ValueIndex = i;
                }
                else if (cur.Equals(k_CSVHead_Name, System.StringComparison.Ordinal))
                {
                    data.NameIndex = i;
                }
                else if (cur.Equals(k_CSVHead_Type, System.StringComparison.Ordinal))
                {
                    data.TypeIndex = i;
                }
                else
                {
                    UnityEngine.Debug.LogError($"Not support: {cur}");
                }
            }
        }
Beispiel #2
0
        private bool GetDataCountFromCSV(string csvStr, ref CSVIndexData indexData, out int outCount)
        {
            indexData.Reset();

            int dataCount = 0;

            using (System.IO.StringReader strReader = new System.IO.StringReader(csvStr))
            {
                var line = strReader.ReadLine();
                GetCSVIndexData(line, ref indexData);
                line = strReader.ReadLine();
                while (!string.IsNullOrEmpty(line))
                {
                    ++dataCount;
                    line = strReader.ReadLine();
                }
            }

            outCount = dataCount;
            return(true);
        }
Beispiel #3
0
        private NativeArray <Vector4> CreateDataFromCSV(string csvStr, Allocator allocator)
        {
            int          dataCount = 0;
            CSVIndexData indexData = new CSVIndexData();

            if (!GetDataCountFromCSV(csvStr, ref indexData, out dataCount))
            {
                return(new NativeArray <Vector4>());
            }
            if (dataCount <= 0)
            {
                return(new NativeArray <Vector4>());
            }
            if (indexData.ValueIndex == -1)
            {
                return(new NativeArray <Vector4>());
            }
            var data = new NativeArray <Vector4>(dataCount, allocator, NativeArrayOptions.ClearMemory);

            using (System.IO.StringReader strReader = new System.IO.StringReader(csvStr))
            {
                dataCount = 0;
                strReader.ReadLine();
                var line = strReader.ReadLine();
                while (!string.IsNullOrEmpty(line) && (dataCount < data.Length))
                {
                    var valStr = CSV.GetCSVString(line, indexData.ValueIndex);
                    if (!string.IsNullOrEmpty(valStr))
                    {
                        data[dataCount] = GetValueFromCSV(valStr);
                    }
                    ++dataCount;
                    line = strReader.ReadLine();
                }
            }
            return(data);
        }