Beispiel #1
0
    public MyObject _LoadFromAssets()
    {
        MyObject obj = new MyObject();

        CsvUtil.LoadObject <MyObject>("Assets/Resources/CsvForSaveData.csv", ref obj);
        return(obj);
    }
Beispiel #2
0
    public void TestLoadStruct()
    {
        string csvData = @"s, Hello World  ,This is an ignored description,also ignored
			f,1234.5,Comment here"            ;

        TestStruct t = new TestStruct();

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvData)))
        {
            using (var sr = new StreamReader(ms))
            {
                CsvUtil.LoadObject(sr, ref t);
            }
        }
    }
Beispiel #3
0
    public void TestLoadSingleWithHeader()
    {
        // Test that we can include a header line if we want
        string csvData = @"#Field,#Value,#Description
			StringField, Hello World  ,This is an ignored description,also ignored
			EnumField,Blue,Something Something
			IntField,1234,Comment here
			FloatField,1.5,More commenting"            ;

        TestObject t = new TestObject();

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvData)))
        {
            using (var sr = new StreamReader(ms))
            {
                CsvUtil.LoadObject(sr, ref t);
            }
        }
    }
Beispiel #4
0
    public void TestLoadPropertiesAndFieldsSameName()
    {
        // It's ok to have newline with padding at start, should trim field names (not values)
        // Include spaces in string field value to prove all content preserved
        string csvData = @"StringMember, Hello World  ,This is an ignored description,also ignored
			EnumMember,Blue,Something Something
			IntMember,1234,Comment here
			FloatMember,1.5,More commenting"            ;

        TestPropertiesAndFieldsObject t = new TestPropertiesAndFieldsObject();

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvData)))
        {
            using (var sr = new StreamReader(ms))
            {
                CsvUtil.LoadObject(sr, ref t);
            }
        }
    }
Beispiel #5
0
    public void TestLoadSingle()
    {
        // It's ok to have newline with padding at start, should trim field names (not values)
        // Include spaces in string field value to prove all content preserved
        // Also put fields out of order
        string csvData = @"String Field, FloatField ,#Description, Int  Field ,   EnumField
""This,has,commas,in it"",2.34,Something ignored,35,Red
Hello World,256.25,""Notes here"",10003,Purple
Zaphod Beeblebrox,3.1,""Amazingly amazing"",000359,Green";

        TestObject t = new TestObject();

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvData)))
        {
            using (var sr = new StreamReader(ms))
            {
                CsvUtil.LoadObject(sr, ref t);
            }
        }
    }
Beispiel #6
0
    public void TestLoadSingleEmbeddedCommas()
    {
        // It's ok to have newline with padding at start, should trim field names (not values)
        // Include spaces in string field value to prove all content preserved
        // Also put fields out of order
        string csvData = @"StringField,""Commas, commas everywhere,abcd"",Ignored,ignored
			EnumField,Purple,Something Something
			IntField,-5002,Comment here
			FloatField,-3.142,Pi Pi Baby"            ;

        TestObject t = new TestObject();

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvData)))
        {
            using (var sr = new StreamReader(ms))
            {
                CsvUtil.LoadObject(sr, ref t);
            }
        }
    }
Beispiel #7
0
 public static void Reload()
 {
     m_Instance = new CustomStarUsage();
     if (File.Exists(m_Instance.m_ArchiveFilePath))
     {
         CsvUtil.LoadObject(m_Instance.m_ArchiveFilePath, ref m_Instance);
     }
     for (int i = 0; i < m_Instance.m_StarUsageCount; i++)
     {
         string   strUsage = m_Instance.GetUsage(i);
         string[] strs     = strUsage.Split('.');
         if (strs.Length != 2)
         {
             Debug.LogError("Invalid star usage format: " + strUsage);
             break;
         }
         m_Instance.ResetUsage(i, strs[0]);
         if (!byte.TryParse(strs[1], out m_Instance.m_StarsMaxCount[i]))
         {
             Debug.LogError("Invalid star usage format: " + strUsage);
             break;
         }
     }
 }