当前位置:网站首页>Et5.0 configuring Excel
Et5.0 configuring Excel
2022-06-13 00:50:00 【Small fish game development】
List of articles
Usage mode :
Write a watch
open Excel In the catalog UnitConfig.xlsx
A1: According to whether there is AppType.ClientH Distinguish whether the client or server loads the configuration
C3: Start reading data here
Reading and writing rules :
The first 3 That's ok : This line does not read the contents of the comment line , # The first column is not read , s This field is server specific at the beginning
The first 4 That's ok : The content of this line is used as the name of the field , Do not empty
The first 5 That's ok : The content of this line is the type of field , Do not empty
The first 6 Line and below : Configuration data
nesting
When you need to nest in a list , I think you should reexamine your logic
If you really don't want to think about it , Be sure to nest ! Then you can open another watch , This table is nested data , Then fill in the data of the nested table ID!
Need nested tables :
Nested tables :
About this way to visit , You can get the complete data , It's also extension friendly :
var testConfig = Game.Scene.GetComponent<ConfigComponent>().Get(typeof(TestConfig),1001) as TestConfig;
var test2 = Game.Scene.GetComponent<ConfigComponent>().Get(typeof(Test2Config), testConfig.a);
Access configuration data
// Read TestConfig Type all data
var array = Game.Scene.GetComponent<ConfigComponent>().GetAll(typeof(TestConfig));
foreach (TestConfig config in array)
{
Log.Debug($"{
config.a}");
}
matters needing attention :
id Fields are indispensable , Can't remove id Field 
Click export client configuration or server configuration to report an error , This is because you are opening in exclusive mode Excel As a result of , Close the Excel Just fine 
There is blank data in the readable field , Field data cannot be blank , Something must be written
Of course, you think it's troublesome and not in line with your habits , You can also modify the source code to read blank data and directly give a default value
But I don't approve of it . You can directly query the value by writing it directly on the table , Better for reading .
And when others read it, they won't wonder why it's blank 
Deleted , Not completely deleted , Press down delete Deleted yellow column , But in fact, when reading, you will still read , You need to delete cells to read normally 

Generate results :
Click export client configuration or export server configuration 
If there is no error, the system will ET\Unity\Assets\Res\Config The folder generates the corresponding configuration data
And in
Assets/Model/Module/Demo/Config
Assets/Hotfix/Module/Demo/Config
Server/Model/Module/Demo/Config
Generate configuration classes under the directory 

Module source code :
Editor Extension
Catalog :ET\Unity\Assets\Editor\ExcelExporterEditor\ExcelExporterEditor.cs
Modify the class generation directory , The following path can be modified according to its own location :
private void OnGUI()
{
try
{
const string clientPath = "./Assets/Res/Config";
if (GUILayout.Button(" Export client configuration "))
{
this.isClient = true;
ExportAll(clientPath);
ExportAllClass(@"./Assets/Model/Module/Demo/Config", "namespace ETModel\n{\n");
ExportAllClass(@"./Assets/Hotfix/Module/Demo/Config", "using ETModel;\n\nnamespace ETHotfix\n{\n");
Log.Info($" Export client configuration complete !");
}
if (GUILayout.Button(" Export server configuration "))
{
this.isClient = false;
ExportAll(ServerConfigPath);
ExportAllClass(@"../Server/Model/Module/Demo/Config", "namespace ETModel\n{\n");
Log.Info($" The export server configuration is completed !");
}
}
catch (Exception e)
{
Log.Error(e);
}
}
The field types supported by the extension configuration table , You need to support more types. Just add them here :
private static string Convert(string type, string value)
{
switch (type)
{
case "int[]":
case "int32[]":
case "long[]":
return $"[{
value}]";
case "string[]":
return $"[{
value}]";
case "int":
case "int32":
case "int64":
case "long":
case "float":
case "double":
return value;
case "string":
return $"\"{
value}\"";
default:
throw new Exception($" This type is not supported : {
type}");
}
}
Configuration is loaded
Configuration components : ConfigComponent.cs
Traverse all configuration types ,BeginInit Add to cache after initialization
public void Load()
{
this.allConfig.Clear();
List<Type> types = Game.EventSystem.GetTypes();
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof (ConfigAttribute), false);
if (attrs.Length == 0)
{
continue;
}
ConfigAttribute configAttribute = attrs[0] as ConfigAttribute;
// Only the specified configuration is loaded
if (!configAttribute.Type.Is(AppType.ClientH))
{
continue;
}
object obj = Activator.CreateInstance(type);
ACategory iCategory = obj as ACategory;
if (iCategory == null)
{
throw new Exception($"class: {
type.Name} not inherit from ACategory");
}
iCategory.BeginInit();
iCategory.EndInit();
this.allConfig[iCategory.ConfigType] = iCategory;
}
}
Configuration initialization
Configure each row as a class data , Deserialization json Save to dictionary
public override void BeginInit()
{
this.dict = new Dictionary<long, IConfig>();
string configStr = ConfigHelper.GetText(typeof (T).Name);
foreach (string str in configStr.Split(new[] {
"\n" }, StringSplitOptions.None))
{
try
{
string str2 = str.Trim();
if (str2 == "")
{
continue;
}
T t = ConfigHelper.ToObject<T>(str2);
this.dict.Add(t.Id, t);
}
catch (Exception e)
{
throw new Exception($"parser json fail: {
str}", e);
}
}
}
边栏推荐
- Card constructions -- two points
- The grass is bearing seeds
- Triangle wave and triangle wave convolution
- Cve-2021-24078 vulnerability analysis
- MySQL lpad() and rpad() concatenate string functions with specified length
- MCU serial port interrupt and message receiving and sending processing -- judge and control the received information
- Composite key relationships using Sqlalchemy - relationships on composite keys using Sqlalchemy
- Zhouchuankai, Bank of Tianjin: from 0 to 1, my experience in implementing distributed databases
- 人神共愤,唐山“群殴女性事件”细节...
- Antdpro - protable realizes the linkage effect of two selection boxes
猜你喜欢

市值破万亿,连续三个月销量破10万,比亚迪会成为最强国产品牌?

Aunt learning code sequel: ability to sling a large number of programmers

How many steps are appropriate for each cycle of deep learning?

Canvas airplane game

Stack overflow learning summary

With a market value of more than trillion yuan and a sales volume of more than 100000 yuan for three consecutive months, will BYD become the strongest domestic brand?
![[JS component] create a custom horizontal and vertical scroll bar following the steam style](/img/c0/9ad8c6abf3dbb210f3d8a46d55b110.jpg)
[JS component] create a custom horizontal and vertical scroll bar following the steam style

Canvas game lower level 100

Kotlin collaboration, the life cycle of a job

什么是 dummy change?
随机推荐
MCU serial port interrupt and message receiving and sending processing -- judge and control the received information
【SCA-CNN 解读】空间与通道注意力:Spatial and Channel-wise Attention
[virtual machine] notes on virtual machine environment problems
Leetcode weekly -- April to May
Kali system -- dnsrecon for DNS collection and analysis
The seventh finals of the Blue Bridge Cup
Illustrator tutorial, how to add dashes and arrows in illustrator?
Android Weather
硬(磁)盘(二)
How many steps are appropriate for each cycle of deep learning?
How to solve the duplication problem when MySQL inserts data in batches?
STM32 USB Basics
蓝桥杯单片机第七届决赛
People and gods are angry. Details of Tangshan "mass beating of women incident"
A simple deadlock example
What is meebits? A brief explanation
Canvas game 2048 free map size
Binary tree - right view
从ADK的WinPE自己手动构建自己的PE
.net core 抛异常对性能影响的求证之路