加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

【数据处理】使用xlua读取XlsxToLua生成的配置文件

发布时间:2020-12-14 04:53:27 所属栏目:大数据 来源:网络整理
导读://LuaDataInfousing 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
//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 = "英雄战士",type = 2,attributes = nil,[3] = {
		heroId = 3,name = "英雄牧师",type = 3,isOpen = false,[4] = {
		heroId = 4,name = "英雄勇士",type = 4,attributes = {
			attack = {
				physical = 140,magic = 0,params = {
							[1] = "sector",[2] = 150,defence = {
				physical = 40,hp = 150,modelSize = {
				[1] = 3.5,[2] = 4,[3] = 8,petPhrase = "Death to all who oppose me!",}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读