[Programming tools] Unity table export tool

0. Preface

This is a tool for exporting a table with unity. In fact, I have written an article to express it before. This time it is refactored.

  1. Refactor attribute processing to facilitate attribute expansion
  2. Handle the export of sheets with the same name, which is convenient for multiple people to collaborate
  3. untiy menu and resource editing processing, easy to use in Unity

Let’s post gitee this time, the previous version and related articles can be found in the column, the address is as follows. The following is also a brief introduction to the project, which can also be seen in the readme file of gitee.

gitee地址:https://gitee.com/buuai/unity-table-exporter
csdn专栏:https://blog.csdn.net/blue_carrot_/category_12180642.html

1. Function

  1. Quickly export Unity Execl tables, support multiple attributes such as bool, int, float, double, string, vector2, and corresponding arrays such as bool[]
  2. Attribute expansion is convenient, and the program is highly configurable
  3. Support multi-language quick export
  4. It is convenient for multiple people to collaborate, and supports multiple files to be exported as the same group of data
  5. Most suitable for UGF, other frameworks need to make templates and other modifications

2. Configuration menu

After importing, there will be an extra menu MyTool

  • [MenuItem("MyTool/Table Export")]
    Export data
  • [MenuItem(“MyTool/Table Export Asset/Create Config Asset”)]
    创建 Config.Asset
  • [MenuItem(“MyTool/Table Export Asset/Create Template Asset”)]
    创建 Template.Asset
  • [MenuItem(“MyTool/Table Export Asset/Selection Config Asset”)]
    找到 Config.Asset
  • [MenuItem(“MyTool/Table Export Asset/Selection Template Asset”)]
    找到 Template.Asset

The location of the configuration file Config.Asset.Template.Asset is written in ExportorEditor. If the configuration location needs to be changed, it needs to be changed in ExportorEditor. Most of the content is configurable, such as the name and content of the exported file, including the line where the data attributes are all configurable.
insert image description here
Template configuration
insert image description here
To see the content corresponding to the specific configuration, you can click on the corresponding script and look at the comments, all of which have relatively complete comments. as follows.
insert image description here

3. Table file format

The configuration format of the table is as follows, you can see the Execl file in the Demo

table correspondence table content
1. Setting items different outputKey
2. Attribute name Id NextId MapType Name
3. Attribute type int int int string
4. Attribute annotation serial number next serial number map type name
5. Data row 1 1 2 1001 shooting guide
n. data line 2 3 1002 block guide
  • Setting items
    can be empty or other, there is no limit
    If it is different, all attribute values ​​​​of this attribute must not be repeated, otherwise an error will be reported
    If it is outputKey, this attribute will be exported as a key and exported to multilingual xml
  • Attribute types
    can handle bool, int, float, double, string, and corresponding arrays such as bool[]
    When the attribute value is exported, a check will be performed according to the attribute type. If an error occurs, an error will be reported.
    When the attribute value is not filled, bool The default is false, int\float\double defaults to false, string is "", and array defaults to a 0-length array.

Support multiple files to configure the same class, only need to be a sheet with the same name, but the attribute items need to be consistent (the columns can be inconsistent),

4. Attribute expansion

If you need new attributes, please refer to the extension of Vector2

  1. First of all, we need a property class to represent this property, which needs to inherit the Property class, and the name needs to be the property name + Property, with the first letter capitalized. For example, when exporting Vector2, it will obtain the Exportor.Vector2Property class through reflection to create this class.
  2. Secondly, we need a Parse function to convert the string to this property, and this function is usually written in a static class, just write the called function in Property
  3. Finally, we need an array Parse function to convert strings to this attribute array, which is similar to the above. The details are as follows.
  4. (In fact, after the first step, the export work has been done, and 2, 3 actually determine the data import method)
// 属性类
// Vector2Property.cs
internal class Vector2Property : Property
{
    
    
    protected override bool OnFormatCheck(string content)
    {
    
    
        string[] temp = content.Split(",");
        bool flag = false;
        float tempFloat;
        if (temp.Length == 2 &&
            float.TryParse(temp[0], out tempFloat) &&
            float.TryParse(temp[1], out tempFloat))
        {
    
    
            flag = true;
        }
        return flag;
    }

    public override string OnEmptyReplace()
    {
    
    
        return "0,0";
    }

    public override string GetParseFunc()
    {
    
    
        return "DataTableExtension.ParseVector2";
    }

    public override string GetArrParseFunc()
    {
    
    
        return "DataTableExtension.ParseVector2Arr";
    }
}
// Parse 函数
// DataTableExtension.ParseVector2
public static Vector2 ParseVector2(string text)
{
    
    
    string[] temp = text.Split(",");
    float x, y;
    if (temp.Length == 2 &&
        float.TryParse(temp[0], out x) &&
        float.TryParse(temp[1], out y))
    {
    
    
        return new Vector2(x, y);
    }
    else
    {
    
    
        return Vector2.zero;
    }
}

// 数组 Parse 函数
// DataTableExtension.ParseVector2Arr
public static Vector2[] ParseVector2Arr(string text)
{
    
    
    string[] texts = ParseStringArr(text);
    int length = texts.Length;
    Vector2[] arr = new Vector2[length];
    for (int i = 0; i < length; i++)
    {
    
    
        arr[i] = ParseVector2(texts[i]);
    }
    return arr;
}

Guess you like

Origin blog.csdn.net/Blue_carrot_/article/details/130592741