Exemple #1
0
        public static bool TypeIsSerializable(Type type)
        {
            if (type == null)
            {
                return(false);
            }

            if (IsPrimitive(type) || IsValueType(type) || IsAssignableFrom(typeof(UnityEngine.Component), type) || IsAssignableFrom(typeof(UnityEngine.ScriptableObject), type))
            {
                return(true);
            }

            var es3Type = ES3TypeMgr.GetOrCreateES3Type(type, false);

            if (es3Type != null && !es3Type.isUnsupported)
            {
                return(true);
            }

            if (TypeIsArray(type))
            {
                if (TypeIsSerializable(type.GetElementType()))
                {
                    return(true);
                }
                return(false);
            }

            var genericArgs = type.GetGenericArguments();

            for (int i = 0; i < genericArgs.Length; i++)
            {
                if (!TypeIsSerializable(genericArgs[i]))
                {
                    return(false);
                }
            }

            if (HasParameterlessConstructor(type))
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public override void Write(Type type, string key, object value)
        {
            StartWriteProperty(key);

            using (var ms = new MemoryStream())
            {
                using (var writer = ES3Writer.Create(ms, new ES3Settings(ES3.EncryptionType.None, ES3.CompressionType.None, ES3.Format.Binary_Alpha), false, false))
                {
                    writer.StartWriteObject(key);
                    writer.WriteType(type);
                    writer.WriteProperty("value", value, ES3TypeMgr.GetOrCreateES3Type(type), settings.referenceMode);
                    writer.EndWriteObject(key);
                }
                var bytes = ms.ToArray();
                Write7BitEncodedInt(bytes.Length);
                baseWriter.Write(bytes);
            }
            EndWriteProperty(key);
            MarkKeyForDeletion(key);
        }
Exemple #3
0
 public ES3Data(Type type, byte[] bytes)
 {
     this.type  = type == null ? null : ES3TypeMgr.GetOrCreateES3Type(type);
     this.bytes = bytes;
 }