akina wordpress,上海优化网站公司,wordpress cos 配置,文登做网站游戏配置表是游戏策划的标配#xff0c;如下图#xff1a;
那么程序怎么把这张配置表导入使用#xff1f;
1.首先#xff0c;利用命令行把Excel格式的文件转化成Json格式#xff1a;
json-excel\json-excel json Tables\ Data\copy Data\CharacterDefine.txt ..\Clien…游戏配置表是游戏策划的标配如下图
那么程序怎么把这张配置表导入使用
1.首先利用命令行把Excel格式的文件转化成Json格式
json-excel\json-excel json Tables\ Data\copy Data\CharacterDefine.txt ..\Client\Data\
pause其中把第一行的Tables\改成自己存放Excel文件的文件夹Data\改成存放Json文件的文件夹即可第二行是复制Json文件的命令。上面的代码存成.cmd文件双击使用即可 生成的Json文件如下
{1: {ID: 1,Name: 小型治疗药水,Description: 使用立即回复500生命值战斗回复,Type: NORMAL,Category: 药水,Level: 1,CanUse: true,UseCD: 1.0,Price: 200,SellPrice: 100,StackLimit: 99,Icon: UI/Items/hongp,Function: RecoverHP,Param: 500},2: {ID: 2,Name: 小型法力药水,Description: 使用立即回复500法力值战斗回复,Type: NORMAL,Category: 药水,Level: 1,CanUse: true,UseCD: 1.0,Price: 200,SellPrice: 100,StackLimit: 99,Icon: UI/Items/lanp,Function: RecoverMP,Param: 500},2.用Define文件定义内容 public class ItemDefine{public int ID { get; set; }public string Name { get; set; }public string Description { get; set; }public ItemType Type { get; set; }public string Category { get; set; }public int Level { get; set; }public CharacterClass LimitClass { get; set; }public bool CanUse { get; set; }public int Price { get; set; }public int SellPrice { get; set; }public int StackLimit { get; set; } // 堆叠限制public string Icon { get; set; }public ItemFunction Function { get; set; }public int Param { get; set; }public Listint Params { get; set; }}
3.C#代码读取Json文件
using System.Collections.Generic;
using System.IO;
using Common;
using Common.Data;
using Newtonsoft.Json;namespace GameServer.Managers
{public class DataManager : SingletonDataManager{internal string DataPath;public Dictionaryint, ItemDefine Items null;public DataManager(){this.DataPath Data/;Log.Info(DataManager DataManager());}internal void Load(){json File.ReadAllText(this.DataPath ItemDefine.txt);this.Items JsonConvert.DeserializeObjectDictionaryint, ItemDefine(json);}}
}在DataManager单例初始化后调用Load函数读取json文件就能使用配置表了 4.使用案例
DataManager.Instance.Items[ItemID].Name