Unity Deserialization停止工作

时间:2015-11-16 19:49:11

标签: c# serialization unity3d

这是相关课程: 序列化工作正常,反序列化确实有效,但是当我更新我使用的网络插件时,现在已经停止了。

帮助或指针真的很棒 给定的错误是

SerializationException: Could not find type ' System.Collections.generic.Dictionary'2

当我尝试反序列化已经序列化并通过网络发送的SmartObject时失败

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using BeardedManStudios.Network;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;


public class EasySerialization {

    public static BMSByte EasySerialize(object arg1)
    {
        BMSByte bms = new BMSByte ();

        IFormatter formatter = new BinaryFormatter ();
        using (var stream = new MemoryStream())
        {
            formatter.Serialize(stream, (object) arg1);
            return ObjectMapper.MapBytes(bms, stream.ToArray());
        }
    }

    public static T EasyDeserialize<T>(ref NetworkingStream arg1)
    {
        byte[] bytes = (byte[]) ObjectMapper.MapByteArray(arg1);

        IFormatter formatter = new BinaryFormatter();
        using (var ms = new MemoryStream(bytes))
        {
            T o = (T)formatter.Deserialize(ms);
            return o;
        }
    }

    public static T EasyDeserialize<T>(NetworkingStream arg1)
    {
        byte[] bytes = (byte[]) ObjectMapper.MapByteArray(arg1);

        IFormatter formatter = new BinaryFormatter();
        using (var ms = new MemoryStream(bytes))
        {
            T o = (T)formatter.Deserialize(ms);
            return o;
        }
    }

//    public static object EasyDeserializeObject(NetworkingStream arg1)
//    {
//        byte[] bytes = (byte[]) ObjectMapper.MapByteArray(arg1);
//      
//        IFormatter formatter = new BinaryFormatter();
//        using (var ms = new MemoryStream(bytes))
//        {
//            object o = formatter.Deserialize(ms);
//            return o;
//        }
//    }
}

[System.Serializable]
public class SmartObject{
     Dictionary<string, object> objects = new Dictionary<string, object>();
    public object GetObject(string key){
        object response;
        if (objects.TryGetValue (key, out response)) {
            return response;
        } else {
            return null;
        }
    }
    public void AddObject (string key, object input){
        objects.Add (key, input);
    }

     Dictionary<string, SmartObject> smart_objects = new Dictionary<string, SmartObject>();
    public SmartObject GetSmartObject(string key){
        SmartObject response;
        if (smart_objects.TryGetValue (key, out response)) {
            return response;
        } else {
            return null;
        }
    }
    public void AddSmartObject (string key, SmartObject input){
        smart_objects.Add (key, input);
    }

     Dictionary<string, byte[]> byte_arrays = new Dictionary<string, byte[]>();
    public byte[] GetByteArray(string key){
        byte[] response;
        if (byte_arrays.TryGetValue (key, out response)) {
            return response;
        } else {
            return null;
        }
    }
    public void AddByteArray (string key, byte[] input){
        byte_arrays.Add (key, input);
    }

     Dictionary<string, string> strings = new Dictionary<string, string>();
    public string GetString(string key){
        string response;
        if (strings.TryGetValue (key, out response)) {
            return response;
        } else {
            return "";
        }
    }
    public void AddString (string key, string input){
        strings.Add (key, input);
    }

     Dictionary<string, int> ints = new Dictionary<string, int>();
    public int GetInt(string key){
        int response;
        if (ints.TryGetValue (key, out response)) {
            return response;
        } else {
            return 0;
        }
    }
    public void AddInt (string key, int input){
        ints.Add (key, input);
    }

     Dictionary<string, float> floats = new Dictionary<string, float>();
    public float GetFloat(string key){
        float response;
        if (floats.TryGetValue (key, out response)) {
            return response;
        } else {
            return 0;
        }
    }
    public void AddFloat (string key, float input){
        floats.Add (key, input);
    }

     Dictionary<string, Vector3_Serial> vec3s = new Dictionary<string, Vector3_Serial>();
    public Vector3 GetVec3(string key){
        Vector3_Serial response;
        if (vec3s.TryGetValue (key, out response)) {
            return response.ToVec3();
        } else {
            return Vector3.zero;
        }
    }
    public void AddVec3 (string key, Vector3 input){
        vec3s.Add (key, new Vector3_Serial(input));
    }

     Dictionary<string, Entity_Model> entities = new Dictionary<string, Entity_Model>();
    public Entity_Model GetEntity(string key){
        Entity_Model response;
        if (entities.TryGetValue (key, out response)) {
            return response;
        } else {
            return null;
        }
    }
    public void AddEntity (string key, Entity_Model input){
        entities.Add (key, input);
    }
}

0 个答案:

没有答案