游戏配置表的导入使用

游戏配置表是游戏策划的标配,如下图:

那么程序怎么把这张配置表导入使用?

1.首先,利用命令行把Excel格式的文件转化成Json格式:

powershell 复制代码
json-excel\json-excel json Tables\ Data\

@copy Data\CharacterDefine.txt ..\Client\Data\
pause

其中把第一行的Tables\改成自己存放Excel文件的文件夹,Data\改成存放Json文件的文件夹即可,第二行是复制Json文件的命令。上面的代码存成.cmd文件双击使用即可

生成的Json文件如下

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文件定义内容:

csharp 复制代码
  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 List<int> Params { get; set; }
  }

3.C#代码读取Json文件:

csharp 复制代码
using System.Collections.Generic;
using System.IO;
using Common;
using Common.Data;
using Newtonsoft.Json;

namespace GameServer.Managers
{
    public class DataManager : Singleton<DataManager>
    {
        internal string DataPath;
        public Dictionary<int, 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.DeserializeObject<Dictionary<int, ItemDefine>>(json);
        }
    }
}

在DataManager单例初始化后,调用Load函数读取json文件,就能使用配置表了

4.使用案例

csharp 复制代码
DataManager.Instance.Items[ItemID].Name
相关推荐
noipp1 天前
推荐题目:洛谷 P6231 [JSOI2013] 公交系统
c语言·数据结构·c++·算法·游戏·洛谷·luogu
金銀銅鐵1 天前
[Python] 用 turtle 来绘制国际象棋棋盘(不含棋子)
python·游戏
Python私教1 天前
Godot怎么下载和安装?零基础完成第一次启动
人工智能·游戏·godot
FairGuard手游加固2 天前
2026年7月份国产游戏审批信息
游戏
星空露珠2 天前
28种颜色对应名称,
开发语言·数据库·算法·游戏·lua
中国搜索直付通2 天前
棋牌游戏支付与防沉迷:二级商户如何构建“免疫系统”
游戏
2601_962924762 天前
遗忘之海手游战术家怎么玩 遗忘之海手游战术家玩法攻略
游戏
雅客李2 天前
2026年第三季度云手机实测 游戏多开挂机托管三维度数据公开
游戏·智能手机
xcLeigh2 天前
Unity基础:创建你的第一个游戏物体——Cube、Sphere与基本3D物体
游戏·3d·unity·教程
_Tenk_2 天前
自研开源小工具 SwitchDeck:一键切换分辨率/刷新率/音频输出(附 WinForms 高 DPI 踩坑实录)
游戏·分辨率·cs2·看电影·一键切换·音响耳机音频·州瓦go