Beispiel #1
0
    protected void WriteAllComponents(ES2AutoSave autoSave, ES2Writer writer)
    {
        Component[] components = autoSave.GetComponents <Component>();

        foreach (Component c in components)
        {
            if (c == null)
            {
                continue;
            }

            ES2Type type;
            ES2AutoSaveComponentInfo info = autoSave.GetComponentInfo(c);

            type = ES2TypeManager.GetES2Type(c.GetType());
            if (type == null)
            {
                continue;
            }

            if (info == null)
            {
                info = new ES2AutoSaveComponentInfo(c, autoSave);
            }
            WriteVariableRecursive(autoSave, info, writer, c);
        }
    }
Beispiel #2
0
    private void ReadComponent(ES2AutoSave autoSave, ES2Reader reader)
    {
        string componentID = reader.reader.ReadString();
        int    endPosition = (int)reader.stream.Position;
        int    length      = reader.reader.ReadInt32();

        endPosition += length;

        // Read collection type byte which is not relevant to Components.
        reader.reader.ReadByte();

        int     typeHash = reader.reader.ReadInt32();
        ES2Type type     = ES2TypeManager.GetES2Type(typeHash);

        // If there's no ES2Type for this type of Component, skip it.
        if (type == null)
        {
            reader.stream.Position = endPosition;
            return;
        }

        // Get or create the Component.
        Component c;
        ES2AutoSaveComponentInfo componentInfo = autoSave.GetComponentInfo(componentID);

        if (componentInfo == null || componentInfo.component == null)
        {
            // If no Component info, look for the Component, or otherwise, add one.
            if (!(c = autoSave.gameObject.GetComponent(type.type)))
            {
                c = autoSave.gameObject.AddComponent(type.type);
            }
        }
        else
        {
            c = componentInfo.component;
        }

        string dataType = reader.reader.ReadString();

        if (dataType == "data")
        {
            reader.Read <System.Object>(type, c);
            return;
        }
        else if (dataType == "vars")        // Else we're reading a series of variables denoted by "vars".
        {
            while (reader.stream.Position != endPosition)
            {
                ReadVariableRecursive(autoSave, componentInfo, reader, c);
            }
        }
        else
        {
            reader.stream.Position = endPosition;
            return;
        }
    }
Beispiel #3
0
    public static void UpdateAutoSave(ES2AutoSave autoSave)
    {
        // Delete any null values from Components array.
        for (int i = 0; i < autoSave.components.Count; i++)
        {
            if (autoSave.components[i] == null || autoSave.components[i].component == null)
            {
                autoSave.components.RemoveAt(i);
                i--;
            }
        }

        Component[] components = autoSave.gameObject.GetComponents(typeof(Component));

        for (int i = 0; i < components.Length; i++)
        {
            Component c = components[i];

            if (c == null)
            {
                continue;
            }

            // Exclude Easy Save components.
            Type type = c.GetType();
            if (typeof(ES2AutoSave).IsAssignableFrom(type) ||
                typeof(ES2AutoSaveManager) == type)
            {
                continue;
            }

            ES2AutoSaveComponentInfo componentInfo = autoSave.GetComponentInfo(c);
            // If the Component Info for this Component hasn't been added to the Auto Save, add it.
            if (componentInfo == null)
            {
                componentInfo = autoSave.AddComponentInfo(new ES2AutoSaveComponentInfo(c, autoSave));
            }

            // Get variables column if this Component is selected.
            if (componentInfo.selected)
            {
                UpdateVariablesForVariable(componentInfo);
            }
        }
    }