Created
April 18, 2016 12:14
-
-
Save tetya/6739f7b77d9705f858f840422677ae1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using NPOI.HSSF.UserModel; | |
using NPOI.SS.UserModel; | |
public class ForCategoryDB : MonoBehaviour { | |
static public void ReadBook(string exportPath, IWorkbook book){ | |
//.assetをloadしてみる | |
CategoryDB data = (CategoryDB)AssetDatabase.LoadAssetAtPath (exportPath, typeof(CategoryDB)); | |
//.assetがまだ無ければcreateする | |
if (data == null) { | |
data = ScriptableObject.CreateInstance<CategoryDB> (); | |
AssetDatabase.CreateAsset ((ScriptableObject)data, exportPath); | |
} | |
//古いリストを破棄 | |
data.list.Clear (); | |
//ScriptableObjectに記入 | |
WriteSO(book, data); | |
} | |
static private void WriteSO(IWorkbook book, CategoryDB data){ | |
//シートの指定 | |
ISheet sheet = book.GetSheetAt (0); | |
Debug.Log (sheet.LastRowNum); | |
//各列を探索 | |
for(int i=1; i<= sheet.LastRowNum; i++){ | |
CategoryDB.CategoryData cDB = new CategoryDB.CategoryData (); | |
IRow row = sheet.GetRow (i); | |
if (row == null) { | |
Debug.Log (i + 1 + "行目のデータは存在しませんでした。作成を完了しました。(ForCategoryDB.cs)"); | |
break; | |
} else { | |
cDB.id = (int)row.GetCell(0).NumericCellValue; | |
cDB.name = (string)row.GetCell(1).StringCellValue; | |
data.list.Add (cDB); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment