728x90
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tool_TableParser : MonoBehaviour
{
public delegate void Parser(string[] s);
public void Read_Resources_Bytes(string Name, Parser parser)
{
TextAsset asset = Resources.Load(Name) as TextAsset;
if (asset == null)
{
Debug.Log("asset == null");
return;
}
StringReader reader = new StringReader(asset.text);
if (reader == null)
{
Debug.Log("asset.txt not found or not readable");
return;
}
int lineCount = 0;
string tmp = reader.ReadLine();
while (tmp != null)
{
string[] stringList = tmp.Split(',');
if (stringList.Length == 0)
continue;
parser(stringList);
tmp = reader.ReadLine();
lineCount++;
}
}
public void Read_Resources_Csv(string Name, Parser parser)
{
string Path = string.Format("{0}/Resources/{1}.csv", Application.dataPath, Name);
if (File.Exists(Path))
{
StringReader reader = new StringReader(System.Text.Encoding.UTF8.GetString(File.ReadAllBytes(Path)));
if (reader == null)
{
Debug.Log("reader.txt not found or not readable");
return;
}
int lineCount = 0;
string tmp = reader.ReadLine();
while (tmp != null)
{
string[] stringList = tmp.Split(',');
if (stringList.Length == 0)
continue;
parser(stringList);
tmp = reader.ReadLine();
lineCount++;
}
}
}
}
728x90
'프로그래밍 > Unity' 카테고리의 다른 글
원형 그래프 (Kerisdiagramm) (0) | 2020.09.18 |
---|---|
csv 파일 쓰기 (0) | 2020.09.08 |
목록에 없는 API 레벨로 빌드하기 (0) | 2020.08.26 |
Texture 다운로드 (0) | 2020.08.25 |
Unity 각종 앱 에뮬레이터와의 호환성 (0) | 2020.01.25 |
댓글