Ejemplo n.º 1
0
 public bool Deserialize()
 {
     if (_serializer.CanDeserialize(BbdPath))
     {
         _serializer.Deserialize(BbdPath, out _data);
         TryToUpgrade();
         return(true);
     }
     else
     {
         throw new System.NotSupportedException($"Version is not supported");
     }
 }
        public IInfo Load(Type objectType)
        {
            if (UnityObjectTokens == null)
            {
                UnityObjectTokens = new UnityObjectToken[0];
            }
            Tokens = UnityObjectTokens.ToDictionary(token => token.Token, token => token.Item);
            if (string.IsNullOrEmpty(SerializedData) || SerializedData == "null")
            {
                return((IInfo)Activator.CreateInstance(objectType));
            }
            try
            {
                using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(SerializedData)))
                {
                    Serializer.Serializer serializer = new Serializer.Serializer();
                    object deserialize = serializer.Deserialize(stream, new UnityObjectSerializerToken(this));
                    if (deserialize == null)
                    {
                        return(null);
                    }
                    if (!objectType.IsInstanceOfType(deserialize))
                    {
                        throw new Exception("Invalid Item on loading in FortScriptableObject");
                    }
                    return((IInfo)deserialize);
                }

/*                return
 *                      JsonConvert.DeserializeObject(SerializedData,
 *                          new JsonSerializerSettings { Converters = { new UnityObjectConverter(this) }, /*Converters = { new ArrayReferencePreservngConverter() },#1# TypeNameHandling = TypeNameHandling.All/*, PreserveReferencesHandling = PreserveReferencesHandling.All#1# });*/
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return((IInfo)Activator.CreateInstance(objectType));
            }
        }