示例#1
0
    public static CSVValue GetCSVValue(string fileName, string key1, string key2, string name)
    {
        CSVTableContainer container = GetTableContainer(fileName);

        if (container == null)
        {
            return(null);
        }
        else
        {
            return(container.GetValue(key1, key2, name));
        }
    }
示例#2
0
    static void OnLoadCSVFile(string strs, string fileName)
    {
        string[] contents = strs.Replace("\r\n", "\r").Split('\r');

        //line 1, for word value type defined
        string[] wordTypeStr = contents[0].Split(',');
        //line 2, for word key defined
        string[] wordKeyNameStr = contents[1].Split(',');

        if (wordTypeStr.Length != wordKeyNameStr.Length)
        {
            Debuger.LogError("CSVTableLoader", "Load {0} csv file failed, because of word type length not equal to word key length", fileName);
            return;
        }

        //search the key word
        int keyWordHierarchyLevel = 0;

        foreach (string str in wordTypeStr)
        {
            if (str[0] == 'K' || str[0] == 'k')
            {
                keyWordHierarchyLevel = keyWordHierarchyLevel + 1;
            }
        }

        //hierarchy level should not be bigger than 2
        if (keyWordHierarchyLevel == 0 || keyWordHierarchyLevel > 2)
        {
            Debuger.LogError("CSVTableLoader", "Load {0} csv file failed, because of the incorrect key word count", fileName);
            return;
        }


        CSVTableContainer csvContainer = new CSVTableContainer(keyWordHierarchyLevel);

        //entry content
        for (int i = 2; i < contents.Length; i++)
        {
            if (string.IsNullOrEmpty(contents[i]))
            {
                continue;
            }

            Dictionary <string, CSVValue> rowDict = new Dictionary <string, CSVValue>();

            string[] rowContent = contents[i].Split(',');
            for (int j = 0; j < rowContent.Length; j++)
            {
                // column name as key                     //content string  //value type string
                rowDict[wordKeyNameStr[j]] = new CSVValue(rowContent[j], wordTypeStr[j]);
            }

            //store the entry to root dict
            if (keyWordHierarchyLevel == 1)
            {
                csvContainer.SetRow(rowContent[0], rowDict);
            }
            else if (keyWordHierarchyLevel == 2)
            {
                csvContainer.SetRow(rowContent[0], rowContent[1], rowDict);
            }
        }

        _CSVTableCache[fileName] = csvContainer;
    }