Unity_ini配置文件应用(用于读取或写入程序设置)
来源:互联网 发布:xp无法添加网络打印机 编辑:程序博客网 时间:2024/05/21 10:41
public static class IniSetting{ private static string mINIFileName = Application.dataPath + "/../config.ini"; public enum SectionName { config,//浏览 config2,//共享内存 } public static bool GetBool(string Key, SectionName section = SectionName.config, bool defaultValue = false) { bool value = defaultValue; string sectionName = section.ToString(); Action<INIParser> action = (ini) => { if (!ini.IsKeyExists(sectionName, Key)) ini.WriteValue(sectionName, Key, defaultValue); value = ini.ReadValue(sectionName, Key, defaultValue); }; OpenAndReadINI(mINIFileName, action); Debug.LogWarning(Key + " " + value); return value; } public static string GetString(string Key, SectionName section = SectionName.config, string defaultValue = "") { string value = defaultValue; string sectionName = section.ToString(); Action<INIParser> action = (ini) => { if (!ini.IsKeyExists(sectionName, Key)) ini.WriteValue(sectionName, Key, defaultValue); value = ini.ReadValue(sectionName, Key, defaultValue); }; OpenAndReadINI(mINIFileName, action); return value; } public static float GetFloat(string Key, SectionName section = SectionName.config, float defaultValue = 0) { float value = defaultValue; string sectionName = section.ToString(); Action<INIParser> action = (ini) => { if (!ini.IsKeyExists(sectionName, Key)) ini.WriteValue(sectionName, Key, defaultValue); value = (float)ini.ReadValue(sectionName, Key, defaultValue); }; OpenAndReadINI(mINIFileName, action); Debug.LogWarning(Key + " " + value); return value; } public static void WriteString(string Key, SectionName section = SectionName.config, string defaultValue = "") { string sectionName = section.ToString(); Action<INIParser> action = (ini) => { ini.WriteValue(sectionName, Key, defaultValue); }; OpenAndReadINI(mINIFileName, action); } public static void WriteBool(string Key, SectionName section = SectionName.config, bool defaultValue = false) { string sectionName = section.ToString(); Action<INIParser> action = (ini) => { ini.WriteValue(sectionName, Key, defaultValue); }; OpenAndReadINI(mINIFileName, action); } public static void WriteFloat(string Key, SectionName section = SectionName.config, float defaultValue = 0) { string sectionName = section.ToString(); Action<INIParser> action = (ini) => { ini.WriteValue(sectionName, Key, defaultValue); }; OpenAndReadINI(mINIFileName, action); } public static int GetInt(string Key, SectionName section = SectionName.config, int defaultValue = 0) { int value = defaultValue; string sectionName = section.ToString(); Action<INIParser> action = (ini) => { if (!ini.IsKeyExists(sectionName, Key)) ini.WriteValue(sectionName, Key, defaultValue); value = ini.ReadValue(sectionName, Key, defaultValue); }; OpenAndReadINI(mINIFileName, action); Debug.LogWarning(Key + " " + value); return value; } static void OpenAndReadINI(string path, Action<INIParser> actionRead) { try { if (!File.Exists(path)) { File.Create(path).Close(); Debug.LogWarning("Create Success:" + path); } //else { INIParser iniParser = new INIParser(); iniParser.Open(path); actionRead(iniParser); iniParser.Close(); } } catch (Exception e) { Debug.LogError("INIFile Not Found Or Create:\r\n" + path + "\r\n" + e); } }}
阅读全文
0 0
- Unity_ini配置文件应用(用于读取或写入程序设置)
- C++读取、写入配置文件
- 读取和写入配置文件
- 读取配置文件和写入配置文件
- vc2008: 控制台程序将数据写入MySql(数据库信息从配置文件读取)
- properties 读取和写入配置文件
- C#读取和写入配置文件
- Properties配置文件读取/写入例子
- VC读取和写入配置文件
- 配置文件读取和写入类
- Java读取/写入Yaml配置文件
- VC配置文件读取和写入
- C#读取与写入配置文件
- 一个用于读取应用程序配置文件(*.ini)的类
- c++读取或写入文本文件
- C++读写TXT (string类型存储读取或写入)
- C# XML配置文件读写类(用于程序配置保存)
- 在Jsp程序读取或向DB写入数据乱码解决办法
- C++数值类型与string的相互转换
- 关于颜色缓存 GL_FRONT、GL_BACK、GL_BAK_LEFT、GL_FRONT_LEFT......
- OpenGL从1.0开始--曲线图形
- 学习笔记--实现ArrayList
- linux 安装nginx
- Unity_ini配置文件应用(用于读取或写入程序设置)
- 正则表达式
- Android PopupWindow用法(五) showAtLocation
- idea15更改编辑器模版,生成时间到分钟
- PopupWindow 的实现
- 关于ref和out的学习和思考
- 《深入理解Java虚拟机》学习笔记(6)--程序编译与代码优化
- 八数码问题(bfs,hash判重)
- springBoot启动器列表