/// <inheritdoc/>
            protected internal override void CloneElement(int index)
            {
                SerializableArray array = property.GetArray();

                int   size     = array.GetLength() + 1;
                Array newArray = property.CreateArrayInstance(new int[] { size });

                object clonedEntry = null;

                for (int i = 0; i < array.GetLength(); i++)
                {
                    object value = array.GetProperty(i).GetValue <object>();

                    newArray.SetValue(value, i);

                    if (i == index)
                    {
                        clonedEntry = SerializableUtility.Clone(array.GetProperty(i).GetValue <object>());
                    }
                }

                newArray.SetValue(clonedEntry, size - 1);

                property.SetValue(newArray);
                this.array  = newArray;
                numElements = newArray.Length;
            }
Beispiel #2
0
        /// <summary>
        /// Helper method used for finding child properties of the specified property, using a property path.
        /// <see cref="SerializableObject.FindProperty(string)"/>.
        /// </summary>
        /// <param name="pathElements">Path elements representing field names and keys to look for.</param>
        /// <param name="elementIdx">Index in the <paramref name="pathElements"/> array to start the search at.</param>
        /// <returns>Property representing the final path element, or null if not found (array index is out of range, or
        ///          property with that path doesn't exist).</returns>
        internal SerializableProperty FindProperty(PropertyPathElement[] pathElements, int elementIdx)
        {
            switch (type)
            {
            case FieldType.Object:
            {
                SerializableObject childObject = GetObject();

                return(childObject.FindProperty(pathElements, elementIdx));
            }

            case FieldType.Array:
            {
                SerializableArray childArray = GetArray();

                return(childArray.FindProperty(pathElements, elementIdx));
            }

            case FieldType.List:
            {
                SerializableList childList = GetList();

                return(childList.FindProperty(pathElements, elementIdx));
            }

            case FieldType.Dictionary:
            {
                SerializableDictionary childDictionary = GetDictionary();

                return(childDictionary.FindProperty(pathElements, elementIdx));
            }
            }

            return(null);
        }
Beispiel #3
0
    public static void Serialize(SerializableArray t)
    {
        Stream          stream     = File.Open("Test.osl", FileMode.Create);
        BinaryFormatter bformatter = new BinaryFormatter();

        bformatter.Serialize(stream, t);
        stream.Close();
    }
Beispiel #4
0
    public static SerializableArray Deserialize()
    {
        Stream            stream     = File.Open("Test.osl", FileMode.Open);
        BinaryFormatter   bformatter = new BinaryFormatter();
        SerializableArray toReturn   = (SerializableArray)bformatter.Deserialize(stream);

        stream.Close();
        return(toReturn);
    }
Beispiel #5
0
        /// <summary>
        /// Expands or collapses the set of rows displaying all entries of a serializable array.
        /// </summary>
        /// <param name="parent">Parent row element whose children to expand/collapse.</param>
        /// <param name="obj">Object describing the array whose entries to display.</param>
        /// <param name="expand">True to expand, false to collapse.</param>
        private void ToggleArrayFoldout(Element parent, SerializableArray obj,
                                        bool expand)
        {
            parent.childLayout.Clear();
            parent.children = null;

            parent.indentLayout.Active = expand;

            if (expand)
            {
                AddArrayRows(parent, obj);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Registers a set of rows for all entries of the provided array.
        /// </summary>
        /// <param name="parent">Parent foldout row to which to append the new elements.</param>
        /// <param name="serializableArray">Array whose fields to display.</param>
        private void AddArrayRows(Element parent, SerializableArray serializableArray)
        {
            List <Element> elements = new List <Element>();

            int length = serializableArray.GetLength();

            for (int i = 0; i < length; i++)
            {
                string name         = "[" + i + "]";
                string propertyPath = parent.path + name;

                Element element;
                if (AddPropertyRow(parent, name, propertyPath, serializableArray.GetProperty(i), out element))
                {
                    elements.Add(element);
                }
            }

            parent.children = elements.ToArray();
        }
            /// <inheritdoc/>
            protected internal override object GetValue(int seqIndex)
            {
                SerializableArray serzArray = property.GetArray();

                // Create a property wrapper for native arrays so we get notified when the array values change
                if (style.StyleFlags.HasFlag(InspectableFieldStyleFlags.NativeWrapper))
                {
                    SerializableProperty.Getter getter = () =>
                    {
                        Array array = property.GetValue <Array>();

                        if (array != null)
                        {
                            return(array.GetValue(seqIndex));
                        }
                        else
                        {
                            return(null);
                        }
                    };

                    SerializableProperty.Setter setter = (object value) =>
                    {
                        Array array = property.GetValue <Array>();

                        if (array != null)
                        {
                            array.SetValue(value, seqIndex);
                            property.SetValue(array);
                        }
                    };

                    return(new SerializableProperty(serzArray.ElementPropertyType, serzArray.ElementType, getter, setter));
                }
                else
                {
                    return(serzArray.GetProperty(seqIndex));
                }
            }
    public void LoadRecord(string jsonRecordsData)
    {
        try
        {
            SerializableArray <RecordData> sr = JsonUtility.FromJson <SerializableArray <RecordData> >(jsonRecordsData);
            if (sr != null)
            {
                RecordData[] recordLevelSaves = sr.Array;

                recordsSaves = new List <RecordData>(recordLevelSaves);
            }
        }
        catch
        {
            recordsSaves = new List <RecordData>();
        }
        if (recordsSaves == null)
        {
            recordsSaves = new List <RecordData>();
        }
        // Debug.Log("RECORDS LOADING CALLLED"+recordsSaves +"sdf"+ new List<RecordLevelSave>());
    }
Beispiel #9
0
        /// <summary>
        /// Registers a new row in the layout for the provided property. The type of row is determined by the property type.
        /// </summary>
        /// <param name="parent">Parent foldout row to which to append the new elements.</param>
        /// <param name="name">Name of the field the property belongs to.</param>
        /// <param name="path">Slash separated path to the field from its parent object.</param>
        /// <param name="property">Property to create the row for.</param>
        /// <param name="element">Element containing data for the newly created row. Only valid if method returns true.
        ///                       </param>
        /// <returns>Returns true if the row was successfully added, false otherwise.</returns>
        private bool AddPropertyRow(Element parent, string name, string path, SerializableProperty property,
                                    out Element element)
        {
            switch (property.Type)
            {
            case SerializableProperty.FieldType.Bool:
            case SerializableProperty.FieldType.Float:
            case SerializableProperty.FieldType.Int:
            case SerializableProperty.FieldType.Color:
            case SerializableProperty.FieldType.Vector2:
            case SerializableProperty.FieldType.Vector3:
            case SerializableProperty.FieldType.Vector4:
                element = AddFieldRow(parent.childLayout, name, parent.so, parent.comp, path, property.Type);
                return(true);

            case SerializableProperty.FieldType.Object:
            {
                Action <Element, bool> toggleCallback =
                    (toggleParent, expand) =>
                {
                    SerializableObject childObject = new SerializableObject(property.InternalType, null);
                    ToggleObjectFoldout(toggleParent, childObject, expand);
                };

                element = AddFoldoutRow(parent.childLayout, null, name, parent.so, parent.comp, path, toggleCallback);
            }
                return(true);

            case SerializableProperty.FieldType.Array:
            {
                Action <Element, bool> toggleCallback =
                    (toggleParent, expand) =>
                {
                    SerializableArray childObject = property.GetArray();

                    if (childObject != null)
                    {
                        ToggleArrayFoldout(toggleParent, childObject, expand);
                    }
                };

                element = AddFoldoutRow(parent.childLayout, null, name, parent.so, parent.comp, path, toggleCallback);
            }
                return(true);

            case SerializableProperty.FieldType.List:
            {
                Action <Element, bool> toggleCallback =
                    (toggleParent, expand) =>
                {
                    SerializableList childObject = property.GetList();

                    if (childObject != null)
                    {
                        ToggleListFoldout(toggleParent, childObject, expand);
                    }
                };

                element = AddFoldoutRow(parent.childLayout, null, name, parent.so, parent.comp, path, toggleCallback);
            }
                return(true);
            }

            element = new Element();
            return(false);
        }
            /// <inheritdoc/>
            protected internal override object GetValue(int seqIndex)
            {
                SerializableArray array = property.GetArray();

                return(array.GetProperty(seqIndex));
            }