Assetpostprocessor



How to work with Excel

Assetpostprocessor

This post shows and helps you how to set up and use Unity-QuickSheet with excel.

Before starting, check your spreadsheet page again. It should start without an empty row which means the first row should not be an empty one.

Step 1) Create Excel Setting File

Description This is called after importing of any number of assets is complete (when the Assets progress bar has reached the end). This call may occur after a manual reimport, or when you move an asset or a folder of assets to a new location in the Project window. Public class MeshPostProcess: AssetPostprocessor void OnPostprocessModel (GameObject gameObject) var meshFilter = gameObject.GetComponent ; var importedMesh = meshFilter.sharedMesh; List verticesList = new List (importedMesh.vertexCount); importedMesh.GetVertices(verticesList); // Inject copy of vertex array in to second UV channel.

First you need thing to do is creating an excel setting file. Simply right click on the Project view and select ‘Create > Spreadsheet Tools > Excel’. It creates a new file which shows various setting to create script files and get data from the specified excel file.

Select Excel menu item then it creates setting file. It may be shown like the following:

Let’s start to do settinig.

File Setting

File setting is setting for what excel file and its sheet page to import.

First you should specify what excel file to import.

  1. Select an excel file to import with File Open Dialog.

An excel file can have one or more sheet pages so you need to decide what sheet you select and retrieve data from.

  1. Select a sheet page you want to import.

  2. Press Import button imports the specified excel file and shows all column headers.

Type Setting

Importing the specified sheet page shows all column headers of the page. That are neccessary to let you set the type of the each cells.

Assetpostprocessor Fbx

Set the proper type of the cells.

Currently the following types are supoorted:

  • string
  • int
  • long
  • float
  • double
  • enum
  • bool

Path Setting

Path setting are concerned with specifying paths where the generated script files are put.

Note: All paths should be relative without ‘Assets/’.`

  1. Template indicates a path where template files which are neccessary to generate script files. In most case you don’t need to change it.
  2. Runtime indicates a path where generated script files which are used on runtime will be put.
  3. Editor inidicates a path where generated script files which are used on editor mode will be put.

Step 2) Generating Script Files

If you’ve done all necessary setting, it’s time to generate some script files which are needed for reading data in from the sheet page of the excel file and to store that within ScriptableObject which is being as an asset file in the Project View.

Press Generate button.

After generating some script files, Unity Editor starts to compile those. Wait till Unity ends doing compile then check the specified Editor and Runtime paths all necessary script files are correctly generated.

In Editor folder should have contain two files:

  • your-sheetpage-nameAssetPostProcessor.cs
  • your-sheetpage-nameEditor.cs

In Runtime foller should have contain tow files:

  • your-sheetpag-name.cs
  • your-sheetpage-nameData.cs

See the your-sheetpage-nameData.cs file. The class members of the file represent each cells of the sheet page.

Step 3) Importing Spreadsheet Data

Creating asset file and importing data from the spreadsheet file into that created asset file is done just by simply doing reimport any xls or xlsx file within Project view.

Assetpostprocessor

Reimporting xls or xlsx file will automatically create an asset file which has same file name as the sheet page name(not excel file name) and automatically import data from the sheet page of the excel file into the created asset file.

It’s done. Hope you enjoy that!

Assetpostprocessor Unity

TroubleShoting

‘Can’t read content types part !’ error on Mac

On a Mac machine, opening .xlsx file cause an error ‘Can’t read content types part !’.

Unity Assetpostprocessor

Assetpostprocessor.onpostprocessallassets

Save it as ‘.xls’ then open again. It solves the problem.

Excel Deserialize Exception exception error

There can be an exception error on Unity console such as ‘Excel Deserialize Exception: Object reference not set to an instance of an objectRow[5], Cell[6] Is that cell empty?’ if a cell of a spreadsheet is empty.

Check the cell with the given row and cell index of the error. Then see the cell is defined as string type and not being empty. If the cell is empty fill a proper data.