Unity编译器 《策划表编表工具》 Excel转Json自动生成解析c#代码

Unity编译器 《策划表编表工具》 Excel转Json自动生成解析c#代码。
摘要由CSDN通过智能技术生成

Unity编译器 《策划表编表工具》 Excel转Json自动生成解析c#代码

1.表格数据结构解释
表格数据解释
2.Excel文件路径
在这里插入图片描述
3.C#代码与Json自动生成路径
在这里插入图片描述
点击下载依赖Dll程序集
4.下载好的依赖程序集放到Plugins中

5.Unity中整体结构
在这里插入图片描述

6.Tools 工具代码

using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using Excel;
using LitJson;

public class Tools : EditorWindow
{
   
    /// <summary>
    /// Execlw文件夹路径
    /// </summary>
    public static string ExeclPath = Application.dataPath.Replace("Assets", "Excel");

    /// <summary>
    /// json路径
    /// </summary>
    public static string jsonPath = Application.dataPath + "/Resources/TxT/";

    /// <summary>
    /// 创建的解析脚本CSharp路径
    /// </summary>
    public static string CSharpPath = Application.dataPath + "/Script/Auto/TableAuto/";

    /// <summary>
    /// table表管理类路径
    /// </summary>
    public static string CSharptablePath = Application.dataPath + "/Script/Table/";

    /// <summary>
    ///  Execl To Json入口
    /// </summary>
    [MenuItem("Tools / Execl To Json and C#")]
    public static void StartExelToJson()
    {
   
        if (Directory.Exists(ExeclPath))
        {
   
            //文件路径
            DirectoryInfo directoryInfo = new DirectoryInfo(ExeclPath);
            //拿到所有的Exel路径
            FileInfo[] FilesAll = directoryInfo.GetFiles("*.xlsx");
            //循环序列化ExeclPath文件夹下所有表
            for (int i = 0; i < FilesAll.Length; i++)
            {
   
                string ExcelTempPath = FilesAll[i].ToString();
                Debug.Log(" Excel绝对路径: " + ExcelTempPath);
                //构造Excel工具类
                ExcelUtility excel = new ExcelUtility(ExcelTempPath);
                excel.ConvertToJson(jsonPath, Encoding.GetEncoding("utf-8"), CSharpPath);
                //刷新本地资源
                AssetDatabase.Refresh();
            }

            //创建TableManager脚本
            if (!Directory.Exists(CSharptablePath))
            {
   
                // 如果路径不存在,则创建文件夹
                Directory.CreateDirectory(CSharptablePath);
                Console.WriteLine("文件夹已创建!");
            }

            CreatTableManager(FilesAll);
            //刷新本地资源
            AssetDatabase.Refresh();
        }
        else
        {
   
            Debug.LogError("未找到路径: " + ExeclPath);
        }

        #region 创建Table管理类

        /// <summary>
        /// 创建Table管理类
        /// </summary>
        void CreatTableManager(FileInfo[] FilesAll)
        {
   
            StringBuilder scriptStr = new StringBuilder();
            scriptStr.AppendLine("using System.Collections.Generic;");
            scriptStr.AppendLine("using UnityEngine;");
            scriptStr.AppendLine("public class TableManager");
            scriptStr.AppendLine("{");
            scriptStr.AppendLine("    private static TableManager _instance;");
            scriptStr.AppendLine("    public static TableManager Instance");
            scriptStr.AppendLine("    {");
            scriptStr.AppendLine("        get");
            scriptStr.AppendLine("        {");
            scriptStr.AppendLine("            if (_instance == null)");
            scriptStr.AppendLine("            {");
            scriptStr.AppendLine("                _instance = new TableManager();");
            scriptStr.AppendLine("            }");
            scriptStr.AppendLine("            return _instance;");
            scriptStr.AppendLine("        }");
            scriptStr.AppendLine("    }");
            foreach (var info in FilesAll)
            {
   
                string tampName= Path.GetFileNameWithoutExtension(info.Name);
                scriptStr.AppendLine($"    public {
     tampName}InfoTable {
     tampName}Info;");
            }

            scriptStr.AppendLine("    public void LoadTables()&#
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值