zoukankan      html  css  js  c++  java
  • 序列化范例

    using UnityEngine;
    using System.Collections;
    using System;
    
    [Serializable]
    public class test
    {
        public int n1 = 0;
        public int n2 = 5;
        // [NonSerialized]
        public string str = null;
    }
    using UnityEngine;
    using System.Collections;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.IO;
    
    public class get : MonoBehaviour {
    
        // Use this for initialization
        void Start () {
            test obj = new test();
            obj.n1 = 1;
            obj.n2 = 2;
            obj.str = "简单的字符串";
            
            IFormatter formater = new BinaryFormatter();
            Stream stream = new FileStream("c:/SaveDtat.bin", FileMode.Create, FileAccess.Write, FileShare.None);
            formater.Serialize(stream, obj);
            stream.Close();
            
            
            IFormatter formatter = new BinaryFormatter();
            Stream reader_stream = new FileStream("c:/SaveDtat.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
            test readerObj = (test)formatter.Deserialize(reader_stream);
            reader_stream.Close();
            
            Debug.Log(readerObj.n1);
            Debug.Log(readerObj.n2);
            Debug.Log(readerObj.str);
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    }
  • 相关阅读:
    WordPress让文本小工具支持简码
    修改WordPress后台登录地址,提高安全性
    WordPress用键盘左右方向键来查看上一篇和下一篇文章
    Git 补丁操作
    Git 标签操作
    Git 修正错误
    Git 删除操作
    Git 重命名操作
    Git 移动操作
    Git 藏匿操作
  • 原文地址:https://www.cnblogs.com/softimagewht/p/3885579.html
Copyright © 2011-2022 走看看