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 -*- ' ...
随机推荐
- Android开发日记(二)
HashMap<String, Object> map;定义一个HashMap用来传递字符 TextView textView_JobTitle=(TextView)findViewByI ...
- vim显示行号、语法高亮、自动缩进、添加下划线的设置
ubuntu默认是没有安装vim的,所以设置以前请先安装vim:sudo apt-get install vim. 然后 打开vim的配置文件:sudo vim /etc/vim/vimrc 或者 s ...
- dp之多维背包hdu2159
二维背包问题,我是觉得这个题目数据比较水,虽然它最后说了怪可以无限个,但是它却只能最多杀s个,也就是所有品种的怪最多为s个,那么就是二维完全背包的问题了.......同时,它没有说一定要杀s只怪,所以 ...
- Python内置字典;dict ,set
dict and set dict: 键-值 /重复添加 set : 键 / key不能重复 对于不变对象来说,调用对象自身的任意方法,也不会改变该对象自身的内容.相反,这些方法会创建新的对象并返 ...
- 【WampServer笔记】常用文件及其配置
用的集成工具是 www.wampserver.com WampServer = Windows操作系统 + Apache服务器 + MySQL数据库 + Php服务器脚本 WampServer工具(集 ...
- 浅谈WebService的调用<转>
0.前言 前段时间,公司和电信有个合作,产品对接电信的某个平台,使用了WebService接口的调用,实现了业务受理以及单点登录.终于使用到了WebService,楼主还是比较兴奋的,目前功能已经上线 ...
- ubuntu下配置java环境
配置JDK环境 下载 登录oracle的网站去下载JDK7 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads ...
- 设计中最常用的CSS选择器
准确而简洁的运用CSS选择器会达到非常好的效果.我们不必通篇给每一个元素定义类(class)或ID,通过合适的组织,可以用最简单的方法实现同样的效果.在实际工作中,最常用的选择器有以下五类: 一.标签 ...
- 几种常见的DIV边框样式
<html> <head> <title>边框样式</title> </head> <body> <p style=bor ...
- Oracle中的job的定时任务
Oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务. 一.查询系统中的job,可以查询视图 --相关视图 select * from dba_jobs; selec ...