【數據處理】使用xlua讀取XlsxToLua生成的配置文件

//LuaDataInfo
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using XLua;

public class TableDataHeroPojo
{
    public int HeroId { get; set; }
    public string Name { get; set; }
    public int Rare { get; set; }
    public int Type { get; set; }
    public int DefaultStar { get; set; }
    public bool IsOpen { get; set; }
    //public LitJson.JsonData Attributes { get; set; }
}

public class LuaDataInfo : MonoBehaviour 
{
    string lua_hero = "DataConfig/Hero";
    void Start()
    {
        LuaEnv luaEnv = new LuaEnv();
        //luaEnv.AddLoader(LoadLuaByName);

        luaEnv.AddLoader(new LuaLoader((ref string filepath) =>
        {
            filepath = string.Format(GameConfig.LuaLoaderPath, Application.streamingAssetsPath, filepath);
            if (File.Exists(filepath))
            {
                return File.ReadAllBytes(filepath);
            }
            else
            {
                return null;
            }
        }));
        string path = string.Format(GameConfig.LuaPath, lua_hero);
        luaEnv.DoString(path);

        LuaTable tab = luaEnv.Global.GetInPath<LuaTable>("Hero");
        LuaTable hero1 = tab.Get<int, LuaTable>(1);
        string Name = hero1.Get<string>("name");
        int heroId = hero1.Get<int>("heroId");
        LuaTable attr = hero1.Get<LuaTable>("attributes");
        string desc = attr.Get<string>("petPhrase");
        Debug.LogError(" heroId = " + heroId + " ,name = " + Name + " ,pet phrase = " + desc);

    }

    public byte[] LoadLuaByName(ref string filepath)
    {
        string tempPath = string.Format(GameConfig.LuaDataConfigPath,filepath);
        if (File.Exists(tempPath))
        {
            return File.ReadAllBytes(tempPath);
        }
        else
        {
            return null;
        }
    }
}


-- heroId                           int                              英雄ID
-- name                             lang                             英雄名稱(僅客戶端用)
-- rare                             int                              稀有度(11-13)
-- type                             int                              英雄職業(1:法師,2:戰士,3:牧師,4:勇士)
-- defaultStar                      int                              英雄初始星數
-- isOpen                           bool                             當前是否在遊戲中開放(即可在英雄圖鑑看到,可以被抽卡抽到)
-- attributes                       json                             戰鬥屬性

Hero =
{
	[1] = {
		heroId = 1,
		name = "英雄法師",
		rare = 11,
		type = 1,
		defaultStar = 1,
		isOpen = true,
		attributes = {
			attack = {
				physical = 20,
				magic = 100,
				canCrit = true,
				hitRate = 0.9,
				ult = {
					[1] = {
						name = "CoupDeGrace",
						params = {
							[1] = "circle",
							[2] = 1,
							[3] = 0,
							[4] = true,
						},
						cd = 5,
					},
				},
			},
			defence = {
				physical = 10,
				magic = 60,
			},
			hp = 200,
			modelSize = {
				[1] = 4,
				[2] = 5,
				[3] = 10.5,
			},
			petPhrase = "I will kill you!",
		},
	},
	[2] = {
		heroId = 2,
		name = "英雄戰士",
		rare = 11,
		type = 2,
		defaultStar = 1,
		isOpen = true,
		attributes = nil,
	},
	[3] = {
		heroId = 3,
		name = "英雄牧師",
		rare = 11,
		type = 3,
		defaultStar = 1,
		isOpen = false,
		attributes = nil,
	},
	[4] = {
		heroId = 4,
		name = "英雄勇士",
		rare = 11,
		type = 4,
		defaultStar = 1,
		isOpen = false,
		attributes = {
			attack = {
				physical = 140,
				magic = 0,
				canCrit = true,
				hitRate = 0.9,
				ult = {
					[1] = {
						name = "CoupDeGrace",
						params = {
							[1] = "sector",
							[2] = 150,
							[3] = 0,
							[4] = true,
						},
						cd = 5,
					},
				},
			},
			defence = {
				physical = 40,
				magic = 0,
			},
			hp = 150,
			modelSize = {
				[1] = 3.5,
				[2] = 4,
				[3] = 8,
			},
			petPhrase = "Death to all who oppose me!",
		},
	},
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章