Пример #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);
        }
    }
Пример #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;
        }
    }
Пример #3
0
 public ES2AutoSaveComponentInfo GetComponentInfo(string id)
 {
     for (int i = 0; i < components.Count; i++)
     {
         ES2AutoSaveComponentInfo info = components[i];
         if (info.component != null && info != null && info.id == id)
         {
             return(info);
         }
     }
     return(null);
 }
Пример #4
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);
            }
        }
    }
Пример #5
0
 public ES2AutoSaveComponentInfo AddComponentInfo(ES2AutoSaveComponentInfo info)
 {
     components.Add(info);
     return(info);
 }
Пример #6
0
    protected void GetComponentsColumnForAutoSave(ES2AutoSave autoSave, ES2EditorColumn previousColumn, ES2EditorRow previousRow)
    {
        ES2EditorColumn column = GetColumn(1);

        ES2EditorRow firstRow = null;

        // GameObject instance variables. These have to be handled seperately.
        ES2AutoSaveVariableInfo[] instanceVariables = new ES2AutoSaveVariableInfo[] { autoSave.activeSelfVariable, autoSave.parentVariable, autoSave.nameVariable, autoSave.tagVariable, autoSave.layerVariable };
        for (int i = 0; i < instanceVariables.Length; i++)
        {
            ES2AutoSaveVariableInfo variable = instanceVariables[i];

            ES2EditorRow newRow = column.AddRow(variable.name, variable, ES2EditorWindow.instance.style.saveButtonStyle, ES2EditorWindow.instance.style.saveButtonSelectedStyle, 0);
            if (firstRow == null)
            {
                firstRow = newRow;
            }

            SetTooltips(variable, newRow);

            // If this component was selected, also select it's Auto Save.
            if (variable.buttonSelectionChanged && variable.buttonSelected)
            {
                autoSave.buttonSelected = true;
            }

            // If the button for the Auto Save of this Component was deselected, deselect this one too.
            if (autoSave.buttonSelectionChanged && !autoSave.buttonSelected)
            {
                newRow.obj.buttonSelected = false;
            }

            // Get variables column if this Component is selected.
            if (variable.selected)
            {
                // Update this component if we've only just selected this Component.
                if (variable.selectionChanged)
                {
                    ES2EditorAutoSaveUtility.UpdateVariablesForVariable(variable);
                }

                GetVariablesColumnForVariable(variable, column, newRow, 2);
            }
        }

        // Create rows for Component's attached to this GameObject.
        for (int i = 0; i < autoSave.components.Count; i++)
        {
            ES2AutoSaveComponentInfo componentInfo = autoSave.components[i];
            ES2EditorRow             newRow        = column.AddRow(componentInfo.name, componentInfo, ES2EditorWindow.instance.style.saveButtonStyle, ES2EditorWindow.instance.style.saveButtonSelectedStyle, 0);
            if (firstRow == null)
            {
                firstRow = newRow;
            }

            SetTooltips(componentInfo, newRow);

            // If this component was selected ...
            if (componentInfo.buttonSelectionChanged && componentInfo.buttonSelected)
            {
                // ... also select it's Auto Save.
                autoSave.buttonSelected = true;
                // If this Component isn't currently supported, add support for it.
                if (!ES2EditorTypeUtility.TypeIsSupported(componentInfo.type))
                {
                    ES2EditorTypeUtility.AddType(componentInfo.type);
                }
            }

            // If the button for the Auto Save of this Component was deselected, deselect this one too.
            if (autoSave.buttonSelectionChanged && !autoSave.buttonSelected)
            {
                newRow.obj.buttonSelected = false;
            }

            // Get variables column if this Component is selected.
            if (componentInfo.selected)
            {
                // Update this component if we've only just selected this Component.
                if (componentInfo.selectionChanged)
                {
                    ES2EditorAutoSaveUtility.UpdateVariablesForVariable(componentInfo);
                }

                GetVariablesColumnForVariable(componentInfo, column, newRow, 2);
            }
        }

        if (autoSave.components.Count == 0)
        {
            firstRow = column.AddRow("No supportable Components", null, null, null, 0);
        }

        // Add seperator row.
        column.AddRow("", null, null, null);
        // Add curve line between columns.
        ArrayUtility.Add(ref curves, new ES2EditorRowCurve(previousColumn, previousRow, column, firstRow, autoSave.color));
    }