Exemplo n.º 1
0
    public bool ReadConfig(string strConfigPath, out List <AnimConfigItem> configs)
    {
        configs = new List <AnimConfigItem>();
        try
        {
            using (FileStream fs = new FileStream(strConfigPath, FileMode.Open))
            {
                TextReader reader = new StreamReader(fs);
                while (true)
                {
                    string strConfigContent = reader.ReadLine();
                    if (strConfigContent == null)
                    {
                        break;
                    }
                    int comments = strConfigContent.IndexOf("//");
                    if (comments != -1)
                    {
                        strConfigContent = strConfigContent.Substring(0, comments);
                    }
                    strConfigContent = strConfigContent.Trim();
                    if (strConfigContent.Length == 0)
                    {
                        continue;
                    }

                    string[] strConfigItems = strConfigContent.Split(',');
                    if (strConfigItems.Length < 4)
                    {
                        Debug.LogError("Invalid animConfig format: " + strConfigContent);
                        break;
                    }

                    foreach (string strConfigItem in strConfigItems)
                    {
                        strConfigItem.Trim();
                    }

                    AnimConfigItem animConfigItem = new AnimConfigItem();
                    animConfigItem.name       = strConfigItems[0];
                    animConfigItem.name       = animConfigItem.name.Trim();
                    animConfigItem.startFrame = int.Parse(strConfigItems[1]);
                    animConfigItem.endFrame   = int.Parse(strConfigItems[2]);
                    animConfigItem.wrapMode   = AnimConfigItem.Parse(strConfigItems[3]);

                    for (int idx = 4; idx < strConfigItems.GetLength(0); idx += 2)
                    {
                        AnimConfigItem.AnimEvent key = new AnimConfigItem.AnimEvent();
                        _ParseFunction(key, strConfigItems[idx], strConfigItems[idx + 1].Trim());
                        animConfigItem.animEvents.Add(key);
                    }

                    configs.Add(animConfigItem);
                }
            }
            return(true);
        }
        catch (IOException exp)
        {
            Debug.LogError("读取动作文件配置失败: " + exp.Message);
        }
        return(false);
    }