一、记录

只是记录,现在在项目中删除掉了。先保留下来,以飨来着!!当然有包括自己。

二、读取配置的代码

简单粗暴

[ExecuteInEditMode]
public class Config : MonoBehaviour
{
private static ConfigFile pConf = null;
public static ConfigFile ConfReference
{
get
{
if (pConf == null)
{
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "JsonConfig/Config.slqj");
if (string.IsNullOrEmpty(filePath))
{
return null;
} if (File.Exists(filePath))
{
string text = File.ReadAllText(filePath);
#if UNITY_EDITOR
Debug.Log(text);
#else
Debug.logger.logEnabled = false;
#endif
pConf = JsonUtility.FromJson<ConfigFile>(text);
}
}
return pConf;
}
}
} [Serializable]
public class ConfigFile
{
// server
public string ServerIP;
// gun
public int SecondGunAmmoNum;
public int ThirdGunAmmoNum;
//player
public float MoveSpeedMultiplier; // 移动速度倍率
public float CamMinDamping;
public int PlayerLifeNum; // 玩家生命数
public int PlayerHP; // 玩家重生血值
// HardwareConf
public float DeadAreaThrold;
public int FilterStep; // 滤波步长
public int joyStickIndex = 0; // 开枪按键
public float renderScale; // 渲染缩放
public bool IsUseOptics; // 是否使用光学定位
public bool IsUseDebug; // 是否显示FPS 输入位置 玩家位置
public int BlueEnemyCount;//蓝方敌人数量
public int RedEnemyCount;//红方敌人数量
public int GameReadyTime;//游戏准备倒计时
public bool IsNetWorkVersion; // 是否为联网版本
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

三、保存Json文件

代码:

 void Save2File()
{
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "JsonConfig/pConfig.json"); string text = "";
FileInfo file = new FileInfo(filePath); if (file.Exists)
{
text = JsonUtility.ToJson(NetWorkManager.config);
StreamWriter w = new StreamWriter(filePath);
w.Write(text);
w.Close();
} }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

——–THE—————END———————

Unity读取 JSon配置文件的更多相关文章

  1. [.NET Core] 简单读取 json 配置文件

    简单读取 json 配置文件 背景 目前发现网上的 .NET Core 读取配置文件有点麻烦,自己想搞个简单点的. .NET Core 已经不使用之前的诸如 app.config 和 web.conf ...

  2. C# 读取Json配置文件

    今天需要用到读取Json配置文件的helper   结果竟然没找到合适的    微软自己有一个 不过不支持.Net fw 4.0 于是自己在NewTonSoft.Json的基础上  加了点小小的封装  ...

  3. fastjson读取json配置文件

    fastjson读取json配置文件: ClassLoader loader=FileUtil.class.getClassLoader(); InputStream stream=loader.ge ...

  4. 【NET Core】.NET Core中读取json配置文件

    在.NET Framework框架下应用配置内容一般都是写在Web.config或者App.config文件中,读取这两个配置文件只需要引用System.Configuration程序集,分别用 Sy ...

  5. unity读取json文件

    首先填表 [escel转json]注意,粘贴表之后,需要把最后的空行删掉 http://www.bejson.com/json/col2json/ [json格式化] http://www.bejso ...

  6. .Net Core控制台应用加载读取Json配置文件

    ⒈添加依赖 Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.FileExtensions Microsoft ...

  7. .NET Core控制台利用【Options】读取Json配置文件

    创建一个 .NET Core控制台程序 添加依赖 Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.FileE ...

  8. ASP.NET CORE入门之读取Json配置文件

    首先新建一.net core控制台项目,命名为jsonReader 然后选中引用,选择NuGet包管理器,点击浏览引入mircosoft.aspnetcore.all并安装 选中解决方案,填加,新建项 ...

  9. python写的读取json配置文件

    配置文件默认为conf.json 使用函数set完成追回配置项. 使用load或取配置项. 代码如下: #!/usr/bin/env python3 # -*- coding: utf-8 -*- ' ...

随机推荐

  1. How To Install and Configure Elasticsearch on Ubuntu 14.04

    Reference: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsear ...

  2. git工作流教程

    简介:在用git进行开发时,需要规范化,这时用git工作流来规范化,软件开发过程 https://github.com/oldratlee/translations/blob/master/git-w ...

  3. DatagridView内容自动换行和换行符换行

    内容自动换行: 在 DataGridView 新增 Row 时,設定 DataGridView 的 DefaultCellStyle 屬性WrapMode=true: 换行符换行: 在 DataGri ...

  4. Hive中order by,sort by,distribute by,cluster by的区别

    一:order by order by会对输入做全局排序,因此只有一个Reducer(多个Reducer无法保证全局有序),然而只有一个Reducer,会导致当输入规模较大时,消耗较长的计算时间.关于 ...

  5. pip安装的python扩展模块自定义目录

    根据系统不同: Windows是python目录下Lib\site-packages\: Linux是/usr/local/lib/python/dist-packages/.

  6. 常用的经典jquery代码[转]

    0. 如何创建嵌套的过滤器: //允许你减少集合中的匹配元素的过滤器, //只剩下那些与给定的选择器匹配的部分.在这种情况下, //查询删除了任何没(:not)有(:has) //包含class为“s ...

  7. [转载]如何解决failed to push some refs to git

    Administrator@PC-20150110FGWU /K/cocos2d/yc (master) $ git push -u origin master To git@github.com:y ...

  8. MFC中的UpdateData()

    UpdateData()是MFC的窗口函数,用来刷新数据的,参数只有一个,默认为TRUE 简单的说: UpdateData(TRUE) == 将控件的值赋值给成员变量, UpdateData(FALS ...

  9. \avformat.h(40) : fatal error C1083: 无法打开包括文件:“libavcodec/avcodec.h”: No such file or directory

    在ffmpeg库下面的头文件包含时用"../"表示当前项目下的头文件就ok了

  10. linux -- chown修改文件拥有者和所在组

    chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...