LoginSignup
0
0

More than 5 years have passed since last update.

Inventory / unity > csvファイルをResourcesから読込む > Resources.Load()

Last updated at Posted at 2016-08-22
動作環境
Unity 5.3.5-f1 on MacOS X El Capitan

関連 http://qiita.com/7of9/items/076cf5aaff7095bb876d

Inventoryの情報をどこから読むか。
起動時にResoucesのcsvファイルから読む実装をしてみた。

手順

参考 http://hwks.hatenadiary.jp/entry/2014/08/03/023235

  1. Assets以下にResoucesフォルダ作成
  2. Resoucesフォルダにinventory.csvを作成 (中身は後述)
  3. コードにusing System.IO;を追加。StringReader使用のため
  4. Resouces.Load()を実施するコード追加
inventory.csv
name,caseNo,row,column,url,about
InventoryCS.cs
using System.IO;
...中略...
public void debugReadCsv() {
    TextAsset csv = Resources.Load ("inventory") as TextAsset;
    StringReader reader = new StringReader (csv.text);
    while (reader.Peek () > -1) {
        string line = reader.ReadLine ();
        T_about.text = line;
    }
}

qiita.png

補足

StringReader > Peek

読み取り対象の次の文字を表す整数。使用できる文字がないか、ストリームがシークをサポートしていない場合は -1。

>-1でなく!= -1の方がいいのかもしれない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0