当前位置:网站首页>Configmanager of unity framework [JSON configuration file reading and writing]
Configmanager of unity framework [JSON configuration file reading and writing]
2022-07-24 18:53:00 【Zero one and black and white】
Unity Framework ConfigManager【Json Profile read / write 】
Read configuration information
int id = 0;
ConfigManager.cheatConfig.GetCheats("TriggerJackPot" , id);
Configuration file management class :ConfigManager.cs
public static class ConfigManager
{
public static CheatConfig cheatConfig{
get; pricate set;}
public static void Initialize(){
UpdateConfig();
LoadAllConfig();
}
/// <summary>
/// Update profile
/// <summary>
private static void UpdateConfig(){
JsonHelper.SaveJson(new CheatConfig());
}
/// <summary>
/// Load all configuration files
/// <summary>
private static void UpdateConfig(){
cheatConfig = JsonHelper.ReadJson<CheatConfig>();
}
}
Read and write configuration files :JsonHelper.cs
public class CheatConfig
{
private static string PATH = Application.streamingAssetsPath + "/Config/";
/// <summary>
/// preservation Json
/// <summary>
public static void SaveJson<T>(T value) where T : class
{
string filename = string.Format{
"{0}{1}.json", PATH, typeof(T).Name};
if(!File.Exists(filename))
Directory.CreateDirectory(PATH);
else
File.Delete(filename);
using(StreamWriter sw = File.CreateText(filename))
{
sw.Write(JsonConvert.SerializeObject(value));
}
}
/// <summary>
/// Read Json
/// <summary>
public static T ReadJson<T>(T value) where T : class
{
string filename = string.Format{
"{0}{1}.json", PATH, typeof(T).Name};
if(!File.Exists(filename))
{
Debug.logError("Json file missing ");
return null;
}
string text = File.ReadAllText(filename);
T obj = JsonConvert.DeserializeObject<T>(text);
return obj;
}
}
The class corresponding to the configuration file :CheatConfig.cs
public class CheatConfig
{
public Dictionary<string, string[][]> Cheat = new Dictionary<string, string[][]>{
{
"TiggerFreeGame", new String[][]{
new String[]{
"N", "Scatter", "T"},
new String[]{
"A", "PIC02", "PIC03"},
new String[]{
"PIC05", "Scatter", "A"},
new String[]{
"Q", "J", "PIC04"},
new String[]{
"K", "Scatter", "N"},
},
},
{
"BonusCoinFullGame", new String[][]{
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"},
new String[]{
"Coin"}
}
},
};
/// <summary>
/// Read configuration information
/// <summary>
/// <param name="name"> name </param>
/// <param name="id"> Lines </param>
/// <returns> Returns all data in a row </returns>
public string[] GetCheats(string name, int id){
if(Cheats.ContainKey(name)){
return Cheats[name][id];
}
else{
Debug.logErrorFormat(" non-existent {0} Cheat sheet ");
return default;
}
}
}
JSON The configuration file :CheatConfig.json
{
"Cheats":{
"TriggerJackPot":[
["N", "Scatter", "T"],
["A", "Wild", "PIC03"],
["PIC05", "Scatter", "A"],
["Q", "Wild", "PIC04"],
["K", "Scatter", "N"]
],
"BonusCoinFullGame":[
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"],
["Coin"]
]
}
}
边栏推荐
- 暑期牛客多校1: I Chiitoitsu(期望dp,求逆元)
- redis 数据类型
- OPENGL学习(五)Modern OpenGL 三角形绘制
- Easily learn pytoch transfer learning to realize surface defect inspection
- Zip compression and decompression
- L4l7 load balancing
- Ionic4 learning notes 1
- [wechat applet development] custom tabbar case (custom message 99 + little hearts)
- OPENGL学习(四)GLUT三维图像绘制
- matplotlib
猜你喜欢

Ionic4 learning notes 9 -- an east project 01

Sequences, time series and prediction in tessorflow quizs on coursera (II)

FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 1)

Today's sleep quality record 79 points

32-bit stack overflow advanced

轻松学Pytorch-迁移学习实现表面缺陷检查

2022 Hangdian multi school second session 1009 shuangq (Mathematics)

Type-C PD protocol chip while charging and listening

Sqoop

深度学习中Dropout原理解析
随机推荐
2022 Summer Games of Hangzhou electric power multiple schools 1012aalice and Bob (game theory)
Add column by column selection for JTable
轻松学Pytorch-迁移学习实现表面缺陷检查
On dynamic application of binary array
Typora user manual
Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
Crazy God redis notes 11
Nacos简介和控制台服务安装
Introduction to VIM
Type-C边充边听PD协议芯片
OpenGL learning (V) modern OpenGL triangle rendering
Vsftpd2.3.4-端口渗透 6200 irc_3281_backdoor
Ionic4 learning notes 1
Sqoop
Mysql数据库,子查询,union,limit篇
ETL development tool kettle download installation environment construction and use tutorial
Ionic4 learning notes 5-- custom public module
Ionic4 learning notes 3
Convolution neural network receptive field calculation Guide
redis 数据类型