using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Xml.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections.Generic;
public class demo : MonoBehaviour {
void Start () {
/*
//序列化字典1
Dictionary<string, int> dic = new Dictionary<string, int> ();
dic.Add ("zhaoguanghui", 12);
MySerialize<Dictionary<string, int>> (dic);
//序列化字符串2
string s = "zhao";
MySerialize<string> (s);
//序列化数组
int[] a = new int[]{1, 2};
MySerialize<int []> (a);
//序列化数据Int
int a1 = 2;
MySerialize<int> (a1);
*/
//序列化类
A a2 = new A ();
MySerialize<A> (a2);
}
void MySerialize<T>(T s)
{
FileStream fileStream = new FileStream (Application.dataPath + "/Res/test.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter ();
formatter.S
C# 序列化数据保存在本地
最新推荐文章于 2024-12-17 11:44:10 发布