Exemplo n.º 1
0
        public override object  Fetch(object instance, Type type, string path)
        {
            int count = NGEditorPrefs.GetInt(path, -1);

            if (count == -1)
            {
                return(instance);
            }

            Type subType = Utility.GetArraySubType(type);

            if (count > 0 && ((subType.IsValueType == true && subType.IsStruct() == false) || subType == typeof(string) || subType.IsInterface == true || subType.IsAbstract == true))
            {
                string v = NGEditorPrefs.GetString(path + ".serialized", null);

                if (string.IsNullOrEmpty(v) == false)
                {
                    return(Utility.DeserializeField(Convert.FromBase64String(v)));
                }
                return(instance);
            }

            IList list = Activator.CreateInstance(type) as IList;

            try
            {
                for (int i = 0; i < count; i++)
                {
                    object element = null;

                    try
                    {
                        if (subType.IsValueType == true)
                        {
                            element = Activator.CreateInstance(subType);
                        }
                        else if (subType != typeof(string))
                        {
                            try
                            {
                                element = Activator.CreateInstance(subType);
                            }
                            catch (MissingMethodException)
                            {
                                element = FormatterServices.GetUninitializedObject(subType);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        InternalNGDebug.LogException(ex);
                        break;
                    }

                    element = Utility.LoadEditorPref(element, subType, path + '.' + i);

                    list.Add(element);
                }

                return(list);
            }
            catch (Exception ex)
            {
                InternalNGDebug.LogException("EditorPrefList failed fetching at \"" + path + "\".", ex);
            }

            return(instance);
        }
Exemplo n.º 2
0
        public override object  Fetch(object instance, Type type, string path)
        {
            int length = NGEditorPrefs.GetInt(path, -1);

            if (length == -1)
            {
                return(instance);
            }

            Type subType = type.GetElementType();

            if (length > 0 && (subType.IsValueType == true || subType == typeof(string) || subType.IsInterface == true || subType.IsAbstract == true))
            {
                string v = NGEditorPrefs.GetString(path + ".serialized", null);

                if (v != null)
                {
                    return(Utility.DeserializeField(Convert.FromBase64String(v)));
                }
                return(instance);
            }

            Array array = Array.CreateInstance(subType, length);

            try
            {
                for (int i = 0; i < array.Length; i++)
                {
                    object element = null;

                    try
                    {
                        if (subType.IsValueType == true)
                        {
                            element = Activator.CreateInstance(subType);
                        }
                        else if (subType != typeof(string))
                        {
                            try
                            {
                                element = Activator.CreateInstance(subType);
                            }
                            catch (MissingMethodException)
                            {
                                element = FormatterServices.GetUninitializedObject(subType);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        InternalNGDebug.LogException(ex);
                        break;
                    }

                    element = Utility.LoadEditorPref(element, subType, path + '.' + i);

                    array.SetValue(element, i);
                }

                return(array);
            }
            catch (Exception ex)
            {
                InternalNGDebug.LogException("EditorPrefArray failed fetching at \"" + path + "\".", ex);
            }

            return(instance);
        }
Exemplo n.º 3
0
 public override object  Fetch(object instance, Type type, string path)
 {
     return(NGEditorPrefs.GetInt(path, (Int32)instance));
 }