Esempio n. 1
0
 public ES2AutoSaveVariableInfo GetVariableInfo(string name)
 {
     for (int i = 0; i < variableIDs.Count; i++)
     {
         ES2AutoSaveVariableInfo v = autoSave.GetCachedVariableInfo(variableIDs[i]);
         if (v != null && v.name == name)
         {
             return(v);
         }
     }
     return(null);
 }
Esempio n. 2
0
    public ES2AutoSaveVariableInfo AddVariableInfo(string name, Type type, bool isProperty, ES2AutoSave autoSave = null, ES2AutoSaveVariableInfo previous = null)
    {
        if (previous == null)
        {
            previous = this;
        }
        if (autoSave == null)
        {
            autoSave = previous.autoSave;
        }

        ES2AutoSaveVariableInfo info = new ES2AutoSaveVariableInfo(name, type, isProperty, autoSave, previous);

        autoSave.CacheVariableInfo(info);
        variableIDs.Add(info.id);
        return(info);
    }
Esempio n. 3
0
 private void SelectParentButtons(ES2AutoSaveVariableInfo info)
 {
     if (!string.IsNullOrEmpty(info.previousID))
     {
         ES2AutoSaveVariableInfo previous = info.autoSave.GetCachedVariableInfo(info.previousID);
         if (previous == null)
         {
             previous = info.autoSave.GetComponentInfo(info.previousID);
         }
         previous.buttonSelected = true;
         SelectParentButtons(previous);
     }
     else if (info.isComponent)
     {
         info.autoSave.buttonSelected = true;
     }
 }
Esempio n. 4
0
    public void RemoveCachedVariableInfo(string id)
    {
        ES2AutoSaveVariableInfo info = GetCachedVariableInfo(id);

        if (info == null)
        {
            return;
        }

        // Recursively delete all child variables.
        foreach (string childId in info.variableIDs)
        {
            RemoveCachedVariableInfo(childId);
        }

        // Remove this variable.
        variableCache.Remove(info);
    }
Esempio n. 5
0
    /*
     *  Gets the chain of variables leading up to a given variable, in reverse order.
     *  i.e. end of chain ('variable' parameter) is first item in List.
     */
    private static List <ES2AutoSaveVariableInfo> GetVariableChain(ES2AutoSaveVariableInfo variable)
    {
        List <ES2AutoSaveVariableInfo> chain = new List <ES2AutoSaveVariableInfo>();

        chain.Add(variable);

        if (string.IsNullOrEmpty(variable.previousID))
        {
            return(chain);
        }

        ES2AutoSaveVariableInfo previous = variable.autoSave.GetCachedVariableInfo(variable.previousID);

        if (previous == null)
        {
            previous = variable.autoSave.GetComponentInfo(variable.previousID);
        }

        chain.AddRange(GetVariableChain(previous));

        return(chain);
    }
Esempio n. 6
0
 public ES2AutoSaveVariableInfo(string name, Type type, bool isProperty, ES2AutoSave autoSave, ES2AutoSaveVariableInfo previous)
 {
     this.name       = name;
     this.id         = ES2AutoSave.GenerateID();
     this.type       = type;
     this.autoSave   = autoSave;
     this.isProperty = isProperty;
     if (previous != null)
     {
         this.previousID = previous.id;
     }
 }
Esempio n. 7
0
 public ES2AutoSaveVariableInfo CacheVariableInfo(ES2AutoSaveVariableInfo variable)
 {
     variableCache.Add(variable);
     return(variable);
 }
Esempio n. 8
0
    public static void UpdateVariablesForVariable(ES2AutoSaveVariableInfo variable)
    {
        // Don't display variables of strings, enums, collections or value types.
        if (variable.type == typeof(string) || variable.type.IsEnum || variable.type.IsValueType || ES2EditorTypeUtility.IsCollectionType(variable.type))
        {
            return;
        }

        Type type = variable.type;

        FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);

        // Add all of the variables to a List so we can see if any need deleting.
        List <ES2AutoSaveVariableInfo> variables = new List <ES2AutoSaveVariableInfo>();

        foreach (FieldInfo field in fields)
        {
            if (!ES2EditorTypeUtility.FieldIsSupportable(field) || typeof(Component).IsAssignableFrom(field.FieldType))
            {
                continue;
            }

            ES2AutoSaveVariableInfo newInfo = variable.GetVariableInfo(field.Name);
            if (newInfo == null)
            {
                newInfo = variable.AddVariableInfo(field.Name, field.FieldType, false);
            }
            variables.Add(newInfo);

            // Update type incase type has changed.
            newInfo.type = field.FieldType;

            if (newInfo.selected)
            {
                UpdateVariablesForVariable(newInfo);
            }
        }

        PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

        foreach (PropertyInfo property in properties)
        {
            if (!ES2EditorTypeUtility.PropertyIsSupportable(property) || typeof(Component).IsAssignableFrom(property.PropertyType))
            {
                continue;
            }

            ES2AutoSaveVariableInfo newInfo = variable.GetVariableInfo(property.Name);
            if (newInfo == null)
            {
                newInfo = variable.AddVariableInfo(property.Name, property.PropertyType, true);
            }
            variables.Add(newInfo);

            // Update type incase type has changed.
            newInfo.type = property.PropertyType;

            if (newInfo.selected)
            {
                UpdateVariablesForVariable(newInfo);
            }
        }

        // Check if any variables need deleting.
        if (variable.variableIDs.Count != variables.Count)
        {
            List <string> variableIDsToDelete = new List <string>();
            for (int i = 0; i < variable.variableIDs.Count; i++)
            {
                string variableID     = variable.variableIDs[i];
                bool   deleteVariable = true;
                for (int j = 0; j < variables.Count; j++)
                {
                    if (variables[j].id == variableID)
                    {
                        deleteVariable = false;
                        break;
                    }
                }
                if (deleteVariable)
                {
                    variableIDsToDelete.Add(variableID);
                }
            }

            // Now remove the variable IDs we want to delete.
            foreach (string variableIDToDelete in variableIDsToDelete)
            {
                variable.DeleteVariableInfo(variableIDToDelete);
            }
        }
    }
Esempio n. 9
0
 private void SetTooltips(ES2AutoSaveVariableInfo info, ES2EditorRow row)
 {
     /*
      * Set the row's buttonTooltip and labelTooltip fields here to show a tooltip for each.
      */
 }
Esempio n. 10
0
    /*
     *  Displays all Properties for the given VariableInfo (which can also be a ComponentInfo.
     *  Finish GetVariablesColumn Method
     */
    private ES2EditorColumn GetVariablesColumnForVariable(ES2AutoSaveVariableInfo info, ES2EditorColumn previousColumn, ES2EditorRow previousRow, int columnIndex)
    {
        ES2EditorColumn column = GetColumn(columnIndex);

        ES2EditorRow firstRow = null;

        foreach (string variableID in info.variableIDs)
        {
            ES2AutoSaveVariableInfo variable = info.autoSave.GetCachedVariableInfo(variableID);
            ES2EditorRow            row      = column.AddRow(variable.name, variable, ES2EditorWindow.instance.style.saveButtonStyle, ES2EditorWindow.instance.style.saveButtonSelectedStyle);
            if (firstRow == null)
            {
                firstRow = row;
            }

            SetTooltips(variable, row);

            // If this variable was just selected ...
            if (variable.buttonSelectionChanged && variable.buttonSelected)
            {
                // ... select all of it's ancestors.
                SelectParentButtons(variable);

                // If this type isn't currently supported, add support for it.
                if (!ES2EditorTypeUtility.TypeIsSupported(variable.type))
                {
                    ES2EditorTypeUtility.AddType(variable.type);
                }
            }

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

            if (variable.selected)
            {
                // If we just selected this variable, update it.
                if (variable.selectionChanged && variable.selected)
                {
                    ES2EditorAutoSaveUtility.UpdateVariablesForVariable(variable);
                }

                GetVariablesColumnForVariable(variable, column, row, columnIndex + 1);
            }
        }

        if (info.variableIDs.Count == 0)
        {
            //firstRow = column.AddRow("No supportable types", null, null, null);
            return(null);
        }

        // Add seperator row.
        column.AddRow("", null, null, null);

        ArrayUtility.Add(ref curves, new ES2EditorRowCurve(previousColumn, previousRow, column, firstRow, info.autoSave.color));

        return(column);
    }
Esempio n. 11
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));
    }
Esempio n. 12
0
    private void ReadVariableRecursive(ES2AutoSave autoSave, ES2AutoSaveVariableInfo variable, ES2Reader reader, object obj)
    {
        string variableID  = reader.reader.ReadString();
        int    endPosition = (int)reader.stream.Position;
        int    length      = reader.reader.ReadInt32();

        endPosition += length;

        // Read Type data
        ES2Keys.Key collectionType = (ES2Keys.Key)reader.reader.ReadByte();
        int         typeHash       = reader.reader.ReadInt32();
        int         dictValueHash  = 0;

        if (collectionType == ES2Keys.Key._Dictionary)
        {
            dictValueHash = reader.reader.ReadInt32();
        }

        ES2AutoSaveVariableInfo info = autoSave.GetCachedVariableInfo(variableID);

        if (info == null)
        {
            reader.stream.Position = endPosition;
            return;
        }

        string dataType = reader.reader.ReadString();

        if (dataType == "data")
        {
            // Get ES2Types.
            ES2Type type          = ES2TypeManager.GetES2Type(typeHash);
            ES2Type dictValueType = null;
            if (collectionType == ES2Keys.Key._Dictionary)
            {
                dictValueType = ES2TypeManager.GetES2Type(dictValueHash);
            }

            // If the type of data we're loading isn't supported, skip it.
            if (type == null || (collectionType == ES2Keys.Key._Dictionary && dictValueType == null))
            {
                reader.stream.Position = endPosition;
                return;
            }

            bool valueWasSet = false;

            if (collectionType == ES2Keys.Key._Null)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.Read <System.Object>(type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._NativeArray)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadSystemArray(type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._List)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(List <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Queue)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(Queue <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Stack)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(Stack <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._HashSet)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(HashSet <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Dictionary)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadIDictionary(typeof(Dictionary <,>), type, dictValueType), info.isProperty);
            }

            if (!valueWasSet)
            {
                reader.stream.Position = endPosition;
                return;
            }
        }
        // Else, we have variables to load.
        else if (dataType == "vars")
        {
            object thisObj = ES2Reflection.GetValue(obj, info.name, info.isProperty);
            if (thisObj == null)
            {
                reader.stream.Position = endPosition;
            }
            ReadVariableRecursive(autoSave, info, reader, thisObj);
        }
        else
        {
            reader.stream.Position = endPosition;
            return;
        }
    }
Esempio n. 13
0
    private void WriteVariableRecursive(ES2AutoSave autoSave, ES2AutoSaveVariableInfo variable, ES2Writer writer, object obj)
    {
        // Get the Type data for this variable, or return if a type is not supported.
        ES2Type es2Type       = null;
        ES2Type dictValueType = null;

        ES2Keys.Key collectionType = ES2Keys.GetCollectionType(variable.type);

        // If it's not a collection type, just get the basic ES2Type.
        if (collectionType == ES2Keys.Key._Null)
        {
            es2Type = ES2TypeManager.GetES2Type(variable.type);
        }
        // Otherwise, get the collection element types.
        else
        {
            if (collectionType == ES2Keys.Key._NativeArray)            // Get Array Element Type.
            {
                es2Type = ES2TypeManager.GetES2Type(variable.type.GetElementType());
            }
            else
            {
                // Get ES2Types for generic type arguments.
                Type[] genericArgs = ES2Reflection.GetGenericArguments(variable.type);
                if (genericArgs.Length > 0)
                {
                    es2Type = ES2TypeManager.GetES2Type(genericArgs[0]);
                    if (genericArgs.Length > 1)
                    {
                        dictValueType = ES2TypeManager.GetES2Type(genericArgs[1]);
                        if (dictValueType == null)
                        {
                            return;
                        }
                    }
                }
            }
        }

        // Skip if unsupported. Enums are not supported unless they have an explicit ES2Type.
        if (es2Type == null || es2Type.GetType() == typeof(ES2_Enum))
        {
            return;
        }

        writer.writer.Write(variable.id);
        int startPosition = writer.WritePropertyPrefix();

        // Write the Type data for this variable.
        writer.writer.Write((byte)collectionType);
        writer.writer.Write(es2Type.hash);
        // If Dictionary, also write the Dictionary value type.
        if (dictValueType != null)
        {
            writer.writer.Write(dictValueType.hash);
        }

        int variableCount = 0;

        foreach (string variableID in variable.variableIDs)
        {
            ES2AutoSaveVariableInfo variableInfo = autoSave.GetCachedVariableInfo(variableID);
            if (variableInfo.buttonSelected)
            {
                variableCount++;
                if (variableCount == 1)
                {
                    writer.writer.Write("vars");
                }

                object variableObj = ES2Reflection.GetValue(obj, variableInfo.name, variableInfo.isProperty);

                WriteVariableRecursive(autoSave, variableInfo, writer, variableObj);
            }
        }

        // If no variables were written, we want to save this variable.
        if (variableCount == 0)
        {
            writer.writer.Write("data");
            if (collectionType == ES2Keys.Key._Null)
            {
                writer.Write(obj, es2Type);
            }
            else if (collectionType == ES2Keys.Key._NativeArray)
            {
                writer.WriteSystemArray((Array)obj, es2Type);
            }
            else if (collectionType == ES2Keys.Key._List)
            {
                writer.WriteICollection((ICollection)obj, es2Type);
            }
            else if (collectionType == ES2Keys.Key._Queue)
            {
                writer.WriteICollection((ICollection)obj, es2Type);
            }
            else if (collectionType == ES2Keys.Key._Stack)
            {
                writer.WriteICollection((ICollection)obj, es2Type);
            }
            else if (collectionType == ES2Keys.Key._HashSet)
            {
                writer.WriteICollection((ICollection)obj, es2Type);
            }
            else if (collectionType == ES2Keys.Key._Dictionary)
            {
                writer.WriteIDictionary((IDictionary)obj, es2Type, dictValueType);
            }
        }

        writer.WritePropertyLength(startPosition);
    }