1. Excel Write

2. Save another

3. Save&Setting File form And File name

4. Open to txt


5. Save another

6. Set Str EnCoding - UTF-8

7. Inport to unity


8. Setting Unity And Show

class TestCSV
| 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 | 
using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
public class TestCSV : MonoBehaviour 
{ 
    public string m_strCSVFileName = string.Empty; 
    class TempData 
    { 
        public int index; 
        public string testString; 
        public int testInt; 
        public float testFloat; 
    } 
    List<TempData> m_tempData = new List<TempData>(); 
    // Start is called before the first frame update 
    void Start() 
    { 
        List<Dictionary<string, object>> m_dictionaryData = CSVReader.Read(m_strCSVFileName); 
        for (int i = 0; i < m_dictionaryData.Count; i++) 
        { 
            m_tempData.Add(new TempData()); 
            m_tempData[i].index = int.Parse((m_dictionaryData[i]["Index"].ToString())); 
            m_tempData[i].testString = m_dictionaryData[i]["TestString"].ToString(); 
            m_tempData[i].testInt = int.Parse(m_dictionaryData[i]["TestInt"].ToString()); 
            m_tempData[i].testFloat = float.Parse(m_dictionaryData[i]["TestFloat"].ToString()); 
        } 
        for(int i =0; i< m_tempData.Count; i++) 
        { 
            Debug.Log("Index : "+m_tempData[i].index + ", TestString : " + m_tempData[i].testString + ", TestInt : " + m_tempData[i].testInt + ", TestFloat : " + m_tempData[i].testFloat); 
        } 
    } 
} | cs | 
class CSVReader
| 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 | 
using UnityEngine; 
using System.Collections.Generic; 
using System.Text.RegularExpressions; 
public class CSVReader 
{ 
    public static string SPLIT_RE = @",(?=(?:[^""]*""[^""]*"")*(?![^""]*""))"; 
    public static string LINE_SPLIT_RE = @"\r\n|\n\r|\n|\r"; 
    public static char[] TRIM_CHARS = { '\"' }; 
    public static List<Dictionary<string, object>> Read(string file) 
    { 
        var list = new List<Dictionary<string, object>>(); 
        TextAsset data = Resources.Load(file) as TextAsset; 
        var lines = Regex.Split(data.text, LINE_SPLIT_RE); 
        if (lines.Length <= 1) return list; 
        var header = Regex.Split(lines[0], SPLIT_RE); 
        for (var i = 1; i < lines.Length; i++) 
        { 
            var values = Regex.Split(lines[i], SPLIT_RE); 
            if (values.Length == 0 || values[0] == "") continue; 
            var entry = new Dictionary<string, object>(); 
            for (var j = 0; j < header.Length && j < values.Length; j++) 
            { 
                string value = values[j]; 
                value = value.TrimStart(TRIM_CHARS).TrimEnd(TRIM_CHARS).Replace("\\", ""); 
                object finalvalue = value; 
                int n; 
                float f; 
                if (int.TryParse(value, out n)) 
                { 
                    finalvalue = n; 
                } 
                else if (float.TryParse(value, out f)) 
                { 
                    finalvalue = f; 
                } 
                entry[header[j]] = finalvalue; 
            } 
            list.Add(entry); 
        } 
        return list; 
    } 
} | cs | 
혹시 코드가 맥 버전인가요?
답글삭제