CSV 파서

Unity/자료 2016. 4. 14. 10:46

속도가 나름 괜찮은 csv 파서를 작성해 봤어요.
맘껐 가져다 쓰세요.
(출처는 표시해 주세요)

CSVParser.cs

//s 20160412-deed, csv 파서
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class CSVParser
{
	public CSVParser()
	{
	}
	~CSVParser()
	{
	}

    List stringList = new List();
    protected int _lineCount = 0;
    public int LineCount
    {
        get
        {
            return _lineCount;
        }
    }

	// Default Functions
	public void LoadFile( string filePath )
	{
		string fileFullPath = Application.dataPath + "/Resources/" + filePath;
		Debug.Log( fileFullPath );

        _lineCount = 0;

		TextAsset tmpText = (TextAsset)Resources.Load( "csv/weapon" );
		string fileAsset = tmpText.text;

		string[] delimeter = { "\r\n" };
		string[] fileDate = fileAsset.Split( delimeter, 
           StringSplitOptions.RemoveEmptyEntries );

		foreach (string rowData in fileDate)
        {
            string[] temp = rowData.Split(',');
            stringList.Add(new string[temp.Length]);
            for (int i = 0; i < temp.Length; ++i)
            {
                stringList[_lineCount][i] = temp[i];
            }

            _lineCount++;
        }

        _lineCount = fileDate.Length;
    }

    public int GetInt(int nRow, int nColumn)
    {
        if (stringList[nRow][nColumn] == null || stringList[nRow][nColumn].Length == 0)
            return 0;

        return System.Convert.ToInt32(stringList[nRow][nColumn]);
    }

    public float GetFloat(int nRow, int nColumn)
    {
        if (stringList[nRow][nColumn] == null || stringList[nRow][nColumn].Length == 0)
            return 0;

        return System.Convert.ToSingle(stringList[nRow][nColumn]);
    }
    public string GetString(int nRow, int nColumn)
    {
        if (stringList[nRow][nColumn] == null || stringList[nRow][nColumn].Length == 0)
            return "";

        return stringList[nRow][nColumn];
    }
}
//e 20160412-deed, csv 파서


블로그 이미지

아몬드콩

,

다른 게임오브젝트(GameObject)에 포함된 스크립트 호출하기
http://blog.danggun.net/2247

'Unity > 익히기' 카테고리의 다른 글

오브젝트에 적용 된 스크립트 찾기  (0) 2016.03.21
1 일차 - 설치하고 시작하기  (0) 2016.02.04
블로그 이미지

아몬드콩

,

How to find out to which GameObjects a certain Script is applied?

1. 이건 컴퍼넌트 이름이 아니라 컴퍼넌트 자체를 찾는 것.
One thing you can do is use the search field in the Hierarchy view. If you enter the full name of the script/component, only objects containing it will be listed in the view.

2. 디버깅 하면서 찾기.
Answer by dwitee · Sep 30, 2014 at 07:27 AM
you can put break point in the script's awake or start function and then in the watch window see the value of " this. gameObject"

3. 이것 최고. ^^;
In Unity 5 just right click on a script and click "Find References In Scene".
It will add the search term to the search bar in the Hierarchy view.
Just clear this string to see all the scenes game objects again.

블로그 이미지

아몬드콩

,