Unity 超级实用的读表工具Luban

1.将Luban文件夹放到和Assets同级别目录下

2.将LubanLib放到Assets文件夹下

3.附代码 Editor 编辑一键读表一键打开目录

4. 介绍一下主要的几个表

5路径在luban文件夹下 表顺序依次为1.2.3

6.首先介绍一下_Beans 里边可以加一些值类型 比如 int  float 枚举 等 string vector3也可以

_tables表为 对要加载表也就是info表的记录和规范命名 以便后边生成代码类  以及info表数据的路径看下图

7.这样表就做完了然后点击导表工具会在StreamingAssets下生成json文件

8.创建一个Datamanager类代码如下

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using cfg;
using cfg.Bing;
using QFramework;
using SimpleJSON;
using UniRx;
using UnityEngine;
using UnityEngine.Networking;

namespace HF
{
    public class DataManager : Singleton<DataManager>
    {
        private Tables _tables;

        private DataManager()
        {
        }

        public void AsyncInit()
        {
            Observable.FromCoroutine(LoadData);
        }
        public void SyncInit()
        {
            _tables = new Tables(Loader);
        }
        #region cfg_InfoCData
        public List<cfg_InfoCData> GetAllInfocDatum()
        {
            return _tables.TbInfo_CData.DataMap.Values.ToList();
        }

        public cfg_InfoCData GetInfocData(int id)
        {
            if (_tables.TbInfo_CData.DataMap.TryGetValue(id, out cfg_InfoCData equipData))
            {
                return equipData;
            }
            else
            {
                Debug.LogError("TbInfo_CData id : " + id + "is not exist");
                return _tables.TbInfo_CData.DataMap.First().Value;
            }
        }
        #endregion
 
        #region cfg_InfoSData
        public List<cfg_InfoSData> GetAllInfosDatum()
        {
            return _tables.TbInfo_SData.DataMap.Values.ToList();
        }

        public cfg_InfoSData GetInfosData(int id)
        {
            if (_tables.TbInfo_SData.DataMap.TryGetValue(id, out cfg_InfoSData equipData))
            {
                return equipData;
            }
            else
            {
                Debug.LogError("TbInfo_SData id : " + id + "is not exist");
                return _tables.TbInfo_SData.DataMap.First().Value;
            }
        }
        #endregion
        private JSONNode Loader(string fileName)
        {
            Debug.Log(fileName);
            return JSON.Parse(File.ReadAllText(Application.streamingAssetsPath+"/json/" + fileName + ".json"));
        }


        public IEnumerator LoadData()
        {
            Dictionary<string, JSONNode> jsonNodes = new Dictionary<string, JSONNode>();
            foreach (var t in Tables.NameArray)
            {
                var uri = new System.Uri(Path.Combine(Application.streamingAssetsPath,
                    "json/" + t + ".json"));
                UnityWebRequest www = UnityWebRequest.Get(uri);
                yield return www.SendWebRequest();
                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    string json = www.downloadHandler.text;
                    jsonNodes.Add(t, JSON.Parse(json));
                }

                yield return null;
            }

            _tables = new Tables(jsonNodes);
        }
        
      

    }
}z
9.这样就可以利用这个数据单例类读取表中的数据了 _beans表中的记录类名就是DataManager中的 数据类

如果没有 Luban 和LubanLib 的可以留言评论! 

  • 33
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
unity luban是一个最佳游戏配置解决方案,它支持多种数据格式,包括excel、csv、xls、xlsx、json、bson、xml、yaml、lua和unity scriptableobject,并能够将这些格式转换为json、bson、xml、lua、yaml、protobuf(pb)、msgpack、flatbuffers、erlang和自定义模板。 在Unity中,luban还提供了逆向运动学解决方案,适用于Humanoid、Generic和Legacy动画类型,并经过了在多个平台上的测试,包括Standalone、WebGL、iOS、Android和所有VR平台(包括Oculus Quest)。它还包含源代码,并适用于各个组件。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Unity导表工具Luban插件的数据加载原理与优化](https://blog.csdn.net/wankcn/article/details/127883528)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Unity学习笔记——Luban工具的使用](https://blog.csdn.net/qq_55042292/article/details/125665772)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [UnityIK人体骨骼反向动力学系统插件 Final IK 2.2](https://download.csdn.net/download/mayzhengxi/88262273)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值