Excel導表工具(開源)
功能
- 支援int、float、bool、string基礎類型
- 支援數組
- 支援kv
- 支援枚舉
- 支援unity類型vector3,vector2,color
- 自動生成csharp類
- 單個excel中多個sheet,依次導出
使用
- 設置config.txt文件,按需求配置;
#為注釋行必須;結尾
#excel存放路徑;
excelPath:./Excel/;
#數據保存路徑;
dataPath:./DataTable/;
#c#類保存路徑;
classPath:./CSharp/;
#輸出類型;
exportType:Json;
isExportServer:False
- 雙擊運行DataTable.exe,等待執行完畢;
配表
-
第一行注釋
-
第二行欄位類型
-
第三行變數名(屬性名)
-
第一列留空
-
數組:類型+[] e.g: int[]
-
kv使用
類型:dic<string,int>
變數名:變數名+:+key值
e.g:
dic<string,float> dic<string,float> dic<string,float> Attribute:atk Attribute:def Attribute:spd -
枚舉:自動生成的枚舉類型從1開始,Enum類型為:Enum+變數名欄位;
Json序列化
使用json庫需要對Vector3等Unity欄位魔改;
Litjson庫魔改:將自定義類型註冊進json庫;
namespace LitJson.Extensions
{
public static class JsonExtensions
{
public static void WriteProperty(this JsonWriter w, string name, long value)
{
w.WritePropertyName(name);
w.Write(value);
}
public static void WriteProperty(this JsonWriter w, string name, string value)
{
w.WritePropertyName(name);
w.Write(value);
}
public static void WriteProperty(this JsonWriter w, string name, bool value)
{
w.WritePropertyName(name);
w.Write(value);
}
public static void WriteProperty(this JsonWriter w, string name, double value)
{
w.WritePropertyName(name);
w.Write(value);
}
}
}
using UnityEngine;
using System;
using System.Collections;
using LitJson.Extensions;
namespace LitJson
{
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoad]
#endif
/// <summary>
/// Unity內建類型拓展
/// </summary>
public static class UnityTypeBindings
{
static bool registerd;
static UnityTypeBindings()
{
Register();
}
public static void Register()
{
if (registerd) return;
registerd = true;
// 註冊Type類型的Exporter
JsonMapper.RegisterExporter<Type>((v, w) => { w.Write(v.FullName); });
JsonMapper.RegisterImporter<string, Type>((s) => { return Type.GetType(s); });
// 註冊Vector2類型的Exporter
Action<Vector2, JsonWriter> writeVector2 = (v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteObjectEnd();
};
JsonMapper.RegisterExporter<Vector2>((v, w) => { writeVector2(v, w); });
// 註冊Vector3類型的Exporter
Action<Vector3, JsonWriter> writeVector3 = (v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("z", v.z);
w.WriteObjectEnd();
};
JsonMapper.RegisterExporter<Vector3>((v, w) => { writeVector3(v, w); });
// 註冊Vector4類型的Exporter
JsonMapper.RegisterExporter<Vector4>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("z", v.z);
w.WriteProperty("w", v.w);
w.WriteObjectEnd();
});
// 註冊Quaternion類型的Exporter
JsonMapper.RegisterExporter<Quaternion>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("z", v.z);
w.WriteProperty("w", v.w);
w.WriteObjectEnd();
});
// 註冊Color類型的Exporter
JsonMapper.RegisterExporter<Color>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("r", v.r);
w.WriteProperty("g", v.g);
w.WriteProperty("b", v.b);
w.WriteProperty("a", v.a);
w.WriteObjectEnd();
});
// 註冊Color32類型的Exporter
JsonMapper.RegisterExporter<Color32>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("r", v.r);
w.WriteProperty("g", v.g);
w.WriteProperty("b", v.b);
w.WriteProperty("a", v.a);
w.WriteObjectEnd();
});
// 註冊Bounds類型的Exporter
JsonMapper.RegisterExporter<Bounds>((v, w) =>
{
w.WriteObjectStart();
w.WritePropertyName("center");
writeVector3(v.center, w);
w.WritePropertyName("size");
writeVector3(v.size, w);
w.WriteObjectEnd();
});
// 註冊Rect類型的Exporter
JsonMapper.RegisterExporter<Rect>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("width", v.width);
w.WriteProperty("height", v.height);
w.WriteObjectEnd();
});
// 註冊RectOffset類型的Exporter
JsonMapper.RegisterExporter<RectOffset>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("top", v.top);
w.WriteProperty("left", v.left);
w.WriteProperty("bottom", v.bottom);
w.WriteProperty("right", v.right);
w.WriteObjectEnd();
});
}
}
}
後續計劃加入protobuf和bytes導出;
計劃可導出.go文件;
相比其他導表工具,優勢就是簡單使用,不用看長長的文檔;
有bug或修改建議歡迎交流;
開源地址://github.com/Rebort1012/DataTable.git
個人部落格:perilla.work