Exemple #1
0
        public object Deserialize(object component, UABField[] data, List <ISerializer> serializers)
        {
            if (UABSerializer.HasProperties(component) == true)
            {
                var fields = component.GetType().GetAllProperties()
                             .Where(x => x.GetCustomAttributes(true).Any(a => a is System.ObsoleteAttribute) == false && x.CanWrite == true && UABSerializer.FilterProperties(x) == true).ToArray();
                //var fields = component.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.Instance);
                //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log(component + " :: " + UABSerializer.HasProperties(component) + " :: " + fields.Length);
                for (int i = 0; i < data.Length; ++i)
                {
                    var fieldInfo = fields.FirstOrDefault(x => x.Name == data[i].name);
                    if (fieldInfo != null)
                    {
                        fieldInfo.SetValue(component, this.Unpack(component, fieldInfo.PropertyType, data[i], serializers), null);
                    }
                    else
                    {
                        if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                        {
                            UnityEngine.Debug.LogWarningFormat("Property with the name `{0}` was not found on property deserialization stage. Be sure you have no per-platform #ifdef directives in your scripts. Skipped.", data[i].name);
                        }
                    }
                }
            }
            else
            {
                var fields = component.GetType().GetAllFields();
                for (int i = 0; i < data.Length; ++i)
                {
                    var fieldInfo = fields.FirstOrDefault(x => x.Name == data[i].name);
                    if (fieldInfo != null)
                    {
                        fieldInfo.SetValue(component, this.Unpack(component, fieldInfo.FieldType, data[i], serializers));
                    }
                    else
                    {
                        if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                        {
                            UnityEngine.Debug.LogWarningFormat("Field with the name `{0}` was not found on field deserialization stage. Be sure you have no per-platform #ifdef directives in your scripts. Skipped.", data[i].name);
                        }
                    }
                }
            }

            return(component);
        }
        public UABField[] Serialize(object component, bool forced, List <ISerializer> serializers)
        {
            var list = ListPool <UABField> .Get();

            if (UABSerializer.HasProperties(component) == true)
            {
                var fields = component.GetType().GetAllProperties()
                             .Where(x => x.GetCustomAttributes(true).Any(a => a is System.ObsoleteAttribute) == false && x.CanWrite == true && UABSerializer.FilterProperties(x) == true).ToArray();
                for (int i = 0; i < fields.Length; ++i)
                {
                    var field = fields[i];

                    var ignoreAttr = field.GetCustomAttributes(typeof(BundleIgnoreAttribute), inherit: true);
                    if ((ignoreAttr != null && ignoreAttr.Length != 0))
                    {
                        continue;
                    }

                    if (this.IsSkipped(fields[i].PropertyType) == true)
                    {
                        continue;
                    }

                    list.Add(this.Pack(fields[i].Name, fields[i].PropertyType, fields[i].GetValue(component, null), serializers));
                }
            }
            else
            {
                var fields = component.GetType().GetAllFields();
                for (int i = 0; i < fields.Length; ++i)
                {
                    var field = fields[i];

                    if (forced == false)
                    {
                        var attr = field.GetCustomAttributes(typeof(SerializeField), inherit: true);
                        if ((attr == null || attr.Length == 0) && field.IsPublic == false)
                        {
                            continue;
                        }
                    }

                    var ignoreAttr = field.GetCustomAttributes(typeof(BundleIgnoreAttribute), inherit: true);
                    if ((ignoreAttr != null && ignoreAttr.Length != 0))
                    {
                        continue;
                    }

                    if (this.IsSkipped(fields[i].FieldType) == true)
                    {
                        continue;
                    }

                    list.Add(this.Pack(fields[i].Name, fields[i].FieldType, fields[i].GetValue(component), serializers));
                }
            }

            var uFields = list.ToArray();

            ListPool <UABField> .Release(list);

            return(uFields);
        }