游戏配置表的导入使用

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

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

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
相关推荐
2501_929157681 小时前
「IOS苹果游戏」600个
游戏·ios
AA陈超1 小时前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-13 属性菜单 - 边框值
c++·游戏·ue5·游戏引擎·虚幻
2501_929157682 小时前
【安卓+PC+IOS】psp全中文游戏+高清纹理包+金手指
android·游戏·ios
bmcyzs6 小时前
【展厅多媒体】展厅小知识:VR体感游戏推动展厅数字化转型
经验分享·科技·游戏·人机交互·软件构建·vr·设计规范
代码改变世界1008619 小时前
像素策略游戏:资源战争
css·游戏·css3
半夏知半秋1 天前
游戏登录方案中常见的设计模式整理
服务器·开发语言·笔记·学习·游戏·设计模式·lua
佩京科技VR1 天前
垃圾分类抠像拍照系统-垃圾分类AR互动游戏-体感漫画拍照一体机
游戏·ar·抠像拍照·体感抠像
WaWaJie_Ngen1 天前
【OpenGL】模板测试(StencilTest)
c++·算法·游戏·游戏引擎·游戏程序·图形渲染
风亦辰7391 天前
从 Hello World 到游戏世界——pygame 快速入门
python·游戏·pygame
2501_918126911 天前
用c语言写一个nes游戏模拟器
游戏