EasyExcel 5.0.0 is released: https://assetstore.unity.com/packages/slug/99352
1 Introduction
In game development, we often use xlsx files to edit a lot of game constants, such as missions, equipment configurations, Tools are needed to convert the xlsx data into data that is usable at runtime.
EasyExcel is a plugin that helps you easily use xlsx data in Unity games. It is easy to use, rich in features, flexible in setup, and does not rely on third-party libraries when running.
It parses xlsx files in the Unity editor and generates code and data for the game runtime.
It generates one ScriptableObject code and one data file for each sheet in the excel file.
When the game runs, EasyExcel loads the generated data file, providing an API to query the data.
Once installed, its menu will appear in the Unity Editor menu bar:
When you click Generate scripts, a ScriptableObject type code file is generated for each sheet in the xlsx file.
When you click Generate data, you generate a ScriptableObject data file for each sheet in the xlsx file.
Features:
• Quick code and data generation with one click
• Support for all Unity versions, cross-platform
• Visual Scripting support
• Support types int, long, float, string, bool, List, Dictionary
• Support engine types Vector2, Vector3, Rect...
• Support for custom types
• Flexible Settings
• Rich examples
2 Files
(1)Xlsx files
Use Hero.xlsx as an example, as shown below.
The first three lines of the first Hero page are specially marked,
The first line is the variable name (##name tag),
The second line is the variable type (##type tag),
The third line is the comment (## tag),
The fourth row and the following are the data.
Therefore, the Hero page conforms to the convention and is imported to generate code (hero.cs and HeroTable.cs) and data (hero.asset).
The first three lines of the other two sheets, Sheet2 and Sheet3, were unmarked, so they were ignored.
Note: The data page name does not have to be the same as the file name and can contain multiple data pages.
(2)The generated code file
Because only the Hero page in hero.xlsx has data, only hero.cs and HeroTable.cs are generated.
The Hero class represents a row of data in the Hero page.
The HeroTable is a collection of Hero data that contains all the data imported from the Hero page.
(3)The generated data file
The hero. asset file is generated, which is a ScriptableObject file of type HeroTable and contains all the Hero data.
(4)The generated class DataTables
A data management class, DataTables.cs, is also generated each time the code is generated.
It is responsible for loading data and querying data.
DataTables contain both synchronous and asynchronous Load methods
DataTables generate static methods for each type of data, such as:
DataTables.GetHero(1001)
DataTables.GetHeroList()
Note that it is important to initialize the load data before calling these static methods.
3 Runtime API
Initialize load data
Create a DataTables instance and call Load to complete the initialization.
Get Data
In the Hero example, obtain the hero configuration with id 1001
Get the all hero configuration
4 Settings
Settings UI
Click EasyExcel/Settings to open the screen.
Here you can set input and output paths, class name rules, and Unity's Visual Scripting.
How to Enable Visual Scripting
Check Visual Scripting in the interface
Click Generate Scripts to regenerate the code
In the ProjectSettings/VisualScripting, join the TypeOptions the generated type
Click Regenerate Nodes
In the Example/Scene/VisualScripting can view the sample:
5 Examples
PredefinedTypes.xlsx
_PredefinedTypes.xlsx is a fixed file that you can use to add custom types.
Notice you can't delete it.
BasicTypes.xlsx
The BasicTypes page of BasicTypes.xlsx demonstrates the base types supported:
int, long, float, string, bool, List, Dictionary.
For List, Dictionary, you can write (sep=;) after the type. To specify the element separator,
Use such as (sep=;) , (sep=#), (sep=,). If omitted (sep=;) , Easy Excel uses the default delimiter '; '.
CustomTypes.xlsx
The CustomTypes page in CustomTypes.xlsx shows how to use CustomTypes that need to be defined first in _PredefinedTypes.xlsx.
UnityEngineTypes.xlsx
The UnityEngineTypes.xlsx page shows how to use Unity's built-in types, which need to be defined in _PredefinedTypes.xlsx first.
Hero、Quest、Item
The Hero page in hero.xlsx demonstrates how to configure Hero character data,
Check out the scene file EasyExcel\Example\Scenes\HeroList.unity
InitializeEasyExcel.cs script shows how to initialize and load data.
HeroListExample.cs Get the list of heroes and display it.
The runtime screenshot is as follows:
The Quest page in quest.xlsx shows how to configure the task data, and the Item page in item.xlsx shows how to configure the items. Where Quest references the Item table, look in the scene file EasyExcel\Example\Scenes\QuestList.unity.
Visual Scripting
Scene file EasyExcel Example Scenes visualScript.unity
See How to enable the Visual Scripting.
6 Support
QQ:1534921818
Mail:1534921818@qq.com
暂无关于此日志的评论。