注意点
- Listを使うので名前空間にはSystem.Collections.Genericが必要
- 継承クラスはScriptableObject
This file contains hidden or 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 System.Collections; | |
using System.Collections.Generic; | |
[CreateAssetMenu()] | |
public class QuestionDB : ScriptableObject { | |
public List<QuestionData> list = new List<QuestionData> (); | |
[System.SerializableAttribute] | |
public class QuestionData{ | |
public int id; | |
public int typeID; | |
public int groupID; | |
public string question; | |
public string answer; | |
} | |
} |
[CreateAssetMenu()]を付けたので、これによりCreateから作成可能になる。
Listに使用している内部クラスには[System.SerializableAttribute]を付けた。これにより、クラスのpublicなインスタンスをInspectorで操作可能になる(参考)。
InspectorでSizeを入力すればListの要素数を変更できる。よって、この時点でその気になれば.Assetファイルによるデータベースの作成が可能。
Inspector上ではなくExcelからデータを流し込みたければ、更に色々工夫する必要がある。
なお、Inspector上に表示されるelementに名前を付けたくなるが、そのためには色々と手間をかける必要がある(参考)。Unityでの管理のためだけにスクリプトを複雑にするのも変な話なので、あきらめた方が無難。
>>次へ(NPOIを用いてExcelファイルのデータをScriptableObjectに書き込む)
0 件のコメント:
コメントを投稿