예제 #1
0
    // Use this for initialization
    void Awake()
    {
        // event ---
        //fileLoader.eventWWWFileLoadComplete += (WWW www) => {
        //	string txt = www.text;

        //	Encoding encoder = Encoding.GetEncoding("Shift_JIS");
        //	string str = encoder.GetString(www.bytes);

        //	CsvItem[] list = CsvUtility.FromCsv<CsvItem>(str);
        //	Debug.Log (">>> "+list.Length);
        //	items = list;
        //};
        //fileLoader.LoadWWW (Application.streamingAssetsPath, "excelTest.csv");

        // callback ---
        fileLoader.LoadWWW(Application.streamingAssetsPath, "excelTest.csv", (WWW www) =>
        {
            // callback
            string txt = www.text;

            Encoding encoder = Encoding.GetEncoding("Shift_JIS");
            string str       = encoder.GetString(www.bytes);

            CsvItem[] list = CsvUtility.FromCsv <CsvItem>(str);
            items          = list;
        });

        // stream ---
        //Encoding encoder = Encoding.GetEncoding("Shift_JIS");
        //string loadStr = fileLoader.LoadStream(Application.streamingAssetsPath, "excelTest.csv", encoder);
        //CsvItem[] list = CsvUtility.FromCsv<CsvItem>(loadStr);
    }
예제 #2
0
 void OnGUI()
 {
     if (GUILayout.Button("Save/Load Test"))
     {
         var dataArray = GenerateData();
         var csv       = CsvUtility.ToCsv(dataArray);
         System.IO.File.WriteAllText("CsvOutput/serialized.csv", csv);
         var deserialized = CsvUtility.FromCsv <Data>(csv);
         var csv2         = CsvUtility.ToCsv(deserialized);
         System.IO.File.WriteAllText("CsvOutput/serialized2.csv", csv2);
         Debug.Assert(csv == csv2);
     }
     if (GUILayout.Button("Ordered Save Test"))
     {
         var dataArray = GenerateData();
         // 順序指定
         string[] order =
         {
             "id",
             "boolValue",
             "charValue",
             "sbyteValue",
             "byteValue",
             "shortValue",
             "ushortValue",
             "NonExistance",
             "intValue",
             "uintValue",
             "longValue",
             "ulongValue",
             "floatValue",
             "doubleValue",
             "stringValue",
             "nonSerializedTypeValue",
             "serializedTypeValue",
             "arrayValue",
             "listValue",
             "nonSerializedPrivateField",
             "nonSerializedPublicField"
         };
         var csv = CsvUtility.ToCsv(dataArray, order);
         System.IO.File.WriteAllText("CsvOutput/serializedOrdered.csv", csv);
         var deserialized = CsvUtility.FromCsv <Data>(csv);
         var csv2         = CsvUtility.ToCsv(deserialized, order);
         System.IO.File.WriteAllText("CsvOutput/serializedOrdered2.csv", csv2);
         Debug.Assert(csv == csv2);
     }
     GUILayout.Label(log);
 }
        public void FromCsv()
        {
            string    csv   = Resources.Load <TextAsset>("table1").text;
            DataTable table = CsvUtility.FromCsv(csv);

            Assert.AreEqual(4, table.Columns.Count);
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual("0", table.Rows[0][0]);
            Assert.AreEqual("1", table.Rows[0][1]);
            Assert.AreEqual(" 2", table.Rows[0][2]);
            Assert.AreEqual("\"3\"", table.Rows[0][3]);
            Assert.AreEqual("0", table.Rows[1][0]);
            Assert.AreEqual("1", table.Rows[1][1]);
            Assert.AreEqual(" 2", table.Rows[1][2]);
            Assert.AreEqual("\"3\"", table.Rows[1][3]);
        }