Unity3D/Plugins

[펌] Unity Excel Importer

blueasa 2019. 1. 3. 19:25

[파일] 

unity-excel-importer-master.zip


Unity Excel Importer

Automatically import from xls, xlsx to custom ScriptableObject in Unity Editor

Import Setup

1. Create Excel and add to Unity

Create an Excel file, make the first row the name of the column, and enter the data from the second row. And add it to Unity’s Project view.

create_excel import_excel_to_unity

2. Create Entity Class Script

Create a new script and define a class with Excel column names and public fields of the desired type. Also give the class ‘System.Serializable’ attribute.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class MstItemEntity
{
	public int id;
	public string name;
	public int price; 
}

3. Create Excel Asset Script

After selecting Excel, execute ExcelAssetScript from the Create menu and create a ScriptableObject script for Excel.

create_excel_asset

As for the generated script, the Excel file name and the sheet name are extracted and the part is commented out as below.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExcelAsset]
public class MstItems : ScriptableObject
{
	//public List<EntityType> Entities; // Replace 'EntityType' to an actual type that is serializable.
}

4. Replace EntityType in created Excel Asset

Uncomment fields and replace the generic type of List with the Entity class defined above.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExcelAsset]
public class MstItems : ScriptableObject
{
	public List<MstItemEntity> Entities;
}

4. Reimport or re-save Excel

When you import or re-save Excel, a ScriptableObject with the same name as Excel is created in the same directory and the contents of Excel are imported.

reimport_excel imported_entities

After this setting, updating Excel automatically updates ScriptableObject as well.

Advanced

Comment Row

If you enter ‘#’ in the first cell of the row, you can treat it as a comment and skip.

Change Asset Path

You can change the ScriptableObject generation position by specifying AssetPath as the ExcelAssetAttribute as shown below.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExcelAsset(AssetPath = "Resources/MasterData")]
public class MstItems : ScriptableObject
{
	public List<MstItemEntity> Entities;
}

Use Enum

You can use enum by entering the element name as string in cell. It is also useful to set Data Validation pull down as an element of enum in Excel.

Lisence

This library is under the MIT License. This software includes the work that is distributed in the Apache License 2.0.



[출처] https://unitylist.com/p/28t/Unity-excel-importer

반응형