Home

Awesome

Excel To ScriptableObject

中文README

Description

It's used to transform data in xlsx (which defines field name and field type) directly into Unity ScriptableObject asset. It's aimed at convenience in xlsx sheet output and fast retrieving sheet data at runtime.

Nested data type in one xlsx file between sheets is supported.

NO EXTRA API AT ALL. All you need to use will be in the generated codes。

How It Works

  1. A C-Sharp code will be generated in specific folder, the same file name with xlsx. All the data types in its sheets will be included, with the class names as sheets' names in xlsx file. The C-Sharp code is used for serializing and retrieving datas.

  2. After compiling generated code, All the datas in sheets will be saved in a Unity asset in specific folder with the same file name with xlsx.

  3. Before writing datas in asset file, datas in each sheets will be sorted, in order to make binary search available.

Rules

Work with It

Guiding in Progress

  1. Modify and check global configuration. Open "GreatClock->Excel2ScriptableObject->Open Window" in menu bar to open management window to do this.

  2. Create a xlsx file and fill the field types, field names and datas in sheets that you need.

  3. Modify sheets and datas in xlsx anytime you need.

  4. Go back to Unity,Open "GreatClock->Excel2ScriptableObject->Open Window" in menu bar to open management window.

  5. When adding new xlsx file, click "Add New Excel Setting" or bottom-right "+" button to create new item. Then click "Select" to choose xlsx file to add. Specify which folders that generated C-Sharp code and asset file stores. Modify its name space, and other features.

  6. Click "Process Excel" or "Process All" to generate or update C-Sharp code and write datas to serialized unity asset file for specific xlsx file(s) managed in management window.

  7. Load data asset file just as loading other assets such as prefab, AudioClip, AnimationClip etc. You can drag data asset file to serialized field in MonoBehaviour, or load it by Resources.Load / AssetBundle.

  8. Get the instance with the data type of the same name with xlsx file from loaded asset.

  9. Call specific Get Method with id or key to retrieve data item(s) of specific sheet.

  10. Debug.Log data item, or read the values of the instance by reading its properties.

  11. If multi-language, 'lang' type, is used in xlsx file, a public variable 'System.Func<string, string> Translate' will be existed in generated C-Sharp file. By implementing this method and set your method to 'Translate' variable, you may transform the corresponding string into any string you need.

  12. If rich string, 'rich' type, is used in xlsx file, a public variable 'Enrich' will be existed in generated C-Sharp code. It is similar to multi-language feature.

Supported Base Data Types

Boolean

Identifier : bool

Value Example :

32bit Integer

Identifier : int, int32

Value Example :

32bit Integer Array

Identifier : ints, int[], [int], int32s, int32[], [int32]

Value Example :

64bit Integer

Identifier : long, int64

Value Example :

64bit Integer Array

Identifier : longs, long[], [long], int64s, int64[], [int64]

Value Example :

Float

Identifier : float

Value Example :

Float Array

Identifier : floats, float[], [float]

Value Example :

Vector2

Identifier : vector2

Value Example :

Vector3

Identifier : vector3

Value Example :

Vector4

Identifier : vector4

Value Example :

Rectangle

Identifier : rect, rectangle

Value Example :

Color

Identifier : color

Value Example :

String

Identifier : string

Value Example :

String Array

Identifier : strings, string[], [string]

Value Example :

Multi-Language Key

Identifier : lang, language

Value Example :

Multi-Language Key Array

Identifier : langs, lang[], [lang], languages, language[], [language]

Value Example :

Rich String Key

Identifier : rich

Value Example :

Rich String Key Array

Identifier : richs, riches, rich[], [rich]

Value Example :

NOTE :

Other Features

FAQs

Q: How to deal with the compile error because of duplicated Excel.dll, ICSharpCode.SharpZipLib.dll or System.Data.dll when this plugin-tool is imported.

A: All the three dynamic link libraries are common libraries. If duplicated dll importing occurred, keep only one of the same dlls in your project will make it work. All the three dlls used by this plugin-tool are only used in Unity Editor. Take care of dll import settings when necessary.


Q: How to deal with compile errors after clicking "Process Excel" ?

A: To make sure the data asset file is accurate, "Process Excel" should execute again after compile errors are resolved. Any of the following conditions may bring a compile error:


Q: When using multi-language or rich-text, their values are not reset after calling Reset() method of data asset containing the data item.

A: The real values of multi-language or rich-text field are set only when the data item is retrieved. This is designed to avoid mass data process when there are massive data items. It's recommended NOT to keep the data item for long time. Retrieving data item again after Reset() is called is also a good choice.


Q: My Data types are nested, and the field type referencing another type is not mark as an array. But why the field is an array in generated C-Sharp code?

A: When data types are nested, either the field type is marked as array or the referenced data type is key-to-multi-values will make the field referencing another type be an array.