Example #1
0
        public void ParseString(string content)
        {
            content = content.Trim();
            heads   = new Dictionary <string, HeadInfo>();
            using (var oReader = new StringReader(content))
            {
                var headLine    = oReader.ReadLine();
                var typeLine    = oReader.ReadLine();
                var metaLine    = oReader.ReadLine();
                var headStrings = headLine.Split(separators);
                var typeStrings = typeLine.Split(separators);
                var metaStrings = metaLine.Split(separators);
                //CDebug.Log(headStrings.Length + " " + metaStrings.Length);
                for (int i = 0; i < headStrings.Length; i++)
                {
                    HeadInfo head = new HeadInfo()
                    {
                        name  = headStrings[i],
                        type  = typeStrings[i],
                        meta  = metaStrings[i],
                        index = i,
                    };

                    heads.Add(head.name, head);

                    //CDebug.Log("head " + i + " " + headStrings[i]);
                }
                var rowLine = "";
                while (rowLine != null)
                {
                    rowLine = oReader.ReadLine();
                    if (rowLine == null)
                    {
                        break;
                    }
                    var rowStrings = rowLine.Split(separators);
                    var primaryKey = rowStrings[0];
                    //CDebug.LogError(rowLine);
                    if (rows.ContainsKey(primaryKey))
                    {
                        CDebug.LogError("rows.ContainsKey true " + primaryKey + "   !" + fileName);
                    }
                    else
                    {
                        rows.Add(primaryKey, new TableRow(rowStrings, heads));
                    }
                }
            }
        }
Example #2
0
        public object Get(string name)
        {
            //CDebug.LogError("name " + name);
            HeadInfo head = null;

            heads.TryGetValue(name, out head);
            if (head != null)
            {
                switch (head.type)
                {
                case "int":
                    //CDebug.LogError(head.index);
                    //CDebug.LogError(values[head.index]);
                    return(int.Parse(values[head.index]));

                case "string":
                    return(values[head.index].ToString());

                case "double":
                    return(double.Parse(values[head.index]));

                case "Vector3":
                    return(RowConvert.StringToVector3(values[head.index]));

                case "Vector4":
                    return(RowConvert.StringToVector4(values[head.index]));

                case "Vector3[]":
                    return(RowConvert.StringToVector3Array(values[head.index]));

                case "int[]":
                    return(RowConvert.StringToIntArray(values[head.index]));

                case "bool":
                    return(RowConvert.StringToBool(values[head.index]));

                case "long":
                    return(long.Parse(values[head.index]));

                case "float":
                    return(float.Parse(values[head.index]));

                default:
                    break;
                }
            }

            return(null);
        }