Unity读取 JSon配置文件
一、记录
只是记录,现在在项目中删除掉了。先保留下来,以飨来着!!当然有包括自己。
二、读取配置的代码
简单粗暴
[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配置文件的更多相关文章
- [.NET Core] 简单读取 json 配置文件
简单读取 json 配置文件 背景 目前发现网上的 .NET Core 读取配置文件有点麻烦,自己想搞个简单点的. .NET Core 已经不使用之前的诸如 app.config 和 web.conf ...
- C# 读取Json配置文件
今天需要用到读取Json配置文件的helper 结果竟然没找到合适的 微软自己有一个 不过不支持.Net fw 4.0 于是自己在NewTonSoft.Json的基础上 加了点小小的封装 ...
- fastjson读取json配置文件
fastjson读取json配置文件: ClassLoader loader=FileUtil.class.getClassLoader(); InputStream stream=loader.ge ...
- 【NET Core】.NET Core中读取json配置文件
在.NET Framework框架下应用配置内容一般都是写在Web.config或者App.config文件中,读取这两个配置文件只需要引用System.Configuration程序集,分别用 Sy ...
- unity读取json文件
首先填表 [escel转json]注意,粘贴表之后,需要把最后的空行删掉 http://www.bejson.com/json/col2json/ [json格式化] http://www.bejso ...
- .Net Core控制台应用加载读取Json配置文件
⒈添加依赖 Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.FileExtensions Microsoft ...
- .NET Core控制台利用【Options】读取Json配置文件
创建一个 .NET Core控制台程序 添加依赖 Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.FileE ...
- ASP.NET CORE入门之读取Json配置文件
首先新建一.net core控制台项目,命名为jsonReader 然后选中引用,选择NuGet包管理器,点击浏览引入mircosoft.aspnetcore.all并安装 选中解决方案,填加,新建项 ...
- python写的读取json配置文件
配置文件默认为conf.json 使用函数set完成追回配置项. 使用load或取配置项. 代码如下: #!/usr/bin/env python3 # -*- coding: utf-8 -*- ' ...
随机推荐
- Sqli-LABS通关笔录-8[延时注入]
通过该关卡我学习到了 1.if语句的三目运算符(其实说白了也就是php里的三位运算符) 2.sleep函数 3.substring函数(其实和substr一样) 4.limit的灵活运用 5. Sta ...
- [4G]常用AT指令
The GPRS communication module is controlled by terminal (e.g. H50) firmware. The actions are mapped ...
- kubernetes service访问原理
k8s集群中有三类IP: 1:宿主机的物理网卡IP,比如192.168.255.* 2:cni创建的网卡的IP,比如172.16.*.* 3:虚拟的IP(即ClusterIP ,无法ping通,通过代 ...
- 恶补java基础 位运算符
以前不知道在哪看过别人写博客里的一句话 “越学的深入觉得自己会的东西越少”.最近研究了一下java的基础算法 hash表 被一些位运算符搞的头都大了 决心花一些时间研究一下以前一直觉得没用的东西! ...
- linux内核支持U-disk和U转串
配置内核 make menuconfig,选中device驱动 Device Drivers ---->USB support--->USB Serial Converter suppor ...
- history统计命令最多的20条
1.1.1 统计使用命令最多的20条 [root@ob1 ~]# history|awk '{ml[$2]++}END{for (i in ml) print i,ml[i]}'|sort -nrk ...
- 《FPGA全程进阶----实战演练》第二章之系统搭建
1 系统方案 对于设计一款硬件平台,首先要确定整体框架,确定各个模块所需要的芯片以及电压分配情况.图2.6是笔者曾经设计的硬件平台系统. 图2.6系统框图 对于选定一个系统方案之后,接下来做的要先去查 ...
- e662. 取的图像的色彩模型
// This method returns the color model of an image public static ColorModel getColorModel(Image imag ...
- HDU 1020:Encoding
pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- R语言中两个数组(或向量)的外积怎样计算
所谓数组(或向量)a和b的外积,指的是a的每个元素和b的每个元素搭配在一起相乘得到的新元素.当然运算规则也可自己定义.外积运算符为 %o%(注意:百分号中间的字母是小写的字母o).比如: > a ...