Пример #1
0
 public string getString(GAME_STRING param)
 {
     if (mStringList.TryGetValue(param, out StringParameter strinParam))
     {
         return(strinParam.mValue);
     }
     return(EMPTY);
 }
Пример #2
0
 public void setString(GAME_STRING param, string value, string comment = null)
 {
     if (!mStringList.TryGetValue(param, out StringParameter stringParam))
     {
         stringParam             = new StringParameter();
         stringParam.mValue      = value;
         stringParam.mComment    = comment;
         stringParam.mType       = param;
         stringParam.mTypeString = param.ToString();
         mStringList.Add(param, stringParam);
     }
     else
     {
         stringParam.mValue = value;
         if (!isEmpty(comment))
         {
             stringParam.mComment = comment;
         }
         mStringList[param] = stringParam;
     }
 }
Пример #3
0
 public void setString(GAME_STRING param, string value, string comment = null)
 {
     if (!mStringList.ContainsKey(param))
     {
         StringParameter strParam = new StringParameter();
         strParam.mValue      = value;
         strParam.mComment    = comment;
         strParam.mType       = param;
         strParam.mTypeString = param.ToString();
         mStringList.Add(param, strParam);
     }
     else
     {
         StringParameter temp = mStringList[param];
         temp.mValue = value;
         if (!isEmpty(comment))
         {
             temp.mComment = comment;
         }
         mStringList[param] = temp;
     }
 }
Пример #4
0
    // fileName为StreamAssets/Config目录下的相对路径
    protected void readFile(string fileName, bool floatParam)
    {
        // 资源目录为本地目录,直接读取本地文件,否则使用http同步下载文件
        string text;

        if (ResourceManager.mLocalRootPath)
        {
            text = openTxtFile(fileName, false);
        }
        else
        {
            text = bytesToString(HttpUtility.downloadFile(fileName), Encoding.UTF8);
        }
        string[] lineList = split(text, true, "\r\n");
        Dictionary <string, ConfigInfo> valueList = new Dictionary <string, ConfigInfo>();
        string comment = null;
        // 前4行需要被丢弃
        int dropLine = 4;

        for (int i = 0; i < lineList.Length; ++i)
        {
            if (i < dropLine)
            {
                continue;
            }
            string line = lineList[i];
            // 去除所有空白字符
            line = Regex.Replace(line, @"\s", EMPTY);
            // 如果该行是空的,或者是注释,则不进行处理
            if (!isEmpty(line))
            {
                if (line.Substring(0, 2) == "//")
                {
                    comment = line.Substring(2, line.Length - 2);
                }
                else
                {
                    string[] value = split(line, false, "=");
                    if (value.Length != 2)
                    {
                        logError("配置文件错误 : line : " + line);
                        return;
                    }
                    ConfigInfo info = new ConfigInfo();
                    info.mComment = comment;
                    info.mName    = value[0];
                    info.mValue   = value[1];
                    if (!valueList.ContainsKey(info.mName))
                    {
                        valueList.Add(info.mName, info);
                    }
                }
            }
        }

        foreach (var item in valueList)
        {
            if (floatParam)
            {
                GAME_FLOAT def = floatNameToType(item.Key);
                if (def != GAME_FLOAT.NONE)
                {
                    setFloat(def, stringToFloat(item.Value.mValue), item.Value.mComment);
                }
            }
            else
            {
                GAME_STRING def = stringNameToType(item.Key);
                if (def != GAME_STRING.NONE)
                {
                    setString(def, item.Value.mValue, item.Value.mComment);
                }
            }
        }
    }
Пример #5
0
 protected bool hasParameter(GAME_STRING param)
 {
     return(mStringList.ContainsKey(param));
 }
Пример #6
0
 protected string stringTypeToName(GAME_STRING type)
 {
     mStringDefineToName.TryGetValue(type, out string str);
     return(str);
 }
Пример #7
0
 protected void addString(GAME_STRING type)
 {
     mStringNameToDefine.Add(type.ToString(), type);
     mStringDefineToName.Add(type, type.ToString());
 }
Пример #8
0
 public string getString(GAME_STRING param)
 {
     return(mStringList.ContainsKey(param) ? mStringList[param].mValue : EMPTY_STRING);
 }
Пример #9
0
 protected string stringTypeToName(GAME_STRING type)
 {
     return(mStringDefineToName.ContainsKey(type) ? mStringDefineToName[type] : null);
 }